Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ private JSONObject getRemotePlatformSdkMappings(String hash) throws IOException,
return result;
} catch (InterruptedException|ExecutionException exc) {
LOGGER.error(String.format("Mappings downloading %s was interrupted", hash), exc);
} finally {
mappingsDownloadOperationCache.remove(hash);
}
throw new ExtenderException(String.format("Cannot find platform sdks mappings for hash: %s", hash));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED;

public class DefoldSDKServiceTest {
private static DefoldSdkServiceConfiguration configuration;
Expand Down Expand Up @@ -108,6 +109,20 @@ public static void beforeAll() throws IOException {
.withBodyFile("test_sdk_invalid.sha256")
.withHeader("Content-Type", "text/plain")));

// first call should fail; second - should be successful
stubFor(get(urlEqualTo("/unstable_sdk_mapping.json"))
.inScenario("request_chain")
.whenScenarioStateIs(STARTED)
.willReturn(aResponse()
.withStatus(404))
.willSetStateTo("not_found"));
stubFor(get(urlEqualTo("/unstable_sdk_mapping.json"))
.inScenario("request_chain")
.whenScenarioStateIs("not_found")
.willReturn(aResponse()
.withStatus(200)
.withBody("{}")
));
}

@AfterAll
Expand Down Expand Up @@ -305,7 +320,7 @@ public void testChecksumVerification() throws IOException {
DefoldSdkServiceConfiguration conf = DefoldSdkServiceConfiguration.builder()
.location(Path.of("/tmp/defoldsdk"))
.cacheSize(1)
.sdkUrls(new String[] {"http://localhost:8090/%s.zip"})
.sdkUrls(new String[] {"http://localhost:" + String.valueOf(serverPort) + "/%s.zip"})
.enableSdkVerification(true)
.maxVerificationRetryCount(3)
.build();
Expand All @@ -318,7 +333,7 @@ public void testInvalidVerification() throws IOException {
DefoldSdkServiceConfiguration disabledVerificationConf = DefoldSdkServiceConfiguration.builder()
.location(Path.of("/tmp/defoldsdk"))
.cacheSize(0)
.sdkUrls(new String[] {"http://localhost:8090/%s.zip"})
.sdkUrls(new String[] {"http://localhost:" + String.valueOf(serverPort) + "/%s.zip"})
.enableSdkVerification(false)
.maxVerificationRetryCount(3)
.build();
Expand All @@ -328,7 +343,7 @@ public void testInvalidVerification() throws IOException {
DefoldSdkServiceConfiguration enabledVerificationConf = DefoldSdkServiceConfiguration.builder()
.location(Path.of("/tmp/defoldsdk"))
.cacheSize(0)
.sdkUrls(new String[] {"http://localhost:8090/%s.zip"})
.sdkUrls(new String[] {"http://localhost:" + String.valueOf(serverPort) + "/%s.zip"})
.enableSdkVerification(true)
.maxVerificationRetryCount(3)
.build();
Expand All @@ -341,4 +356,19 @@ public void testInvalidVerification() throws IOException {
ExtenderException exc = assertThrows(ExtenderException.class, () -> sdkService1.getSdk("test_sdk_invalid"));
assertTrue(exc.getMessage().contains("Sdk verification failed"));
}

@Test
public void testUnstableAccessSdkMappings() throws IOException {
DefoldSdkServiceConfiguration conf = DefoldSdkServiceConfiguration.builder()
.location(Path.of("/tmp/defoldsdk"))
.cacheSize(0)
.mappingsUrls(new String[] {"http://localhost:" + String.valueOf(serverPort) + "/%s.json"})
.enableSdkVerification(false)
.maxVerificationRetryCount(1)
.build();
DefoldSdkService sdkService = new DefoldSdkService(conf, new SimpleMeterRegistry());
assertThrows(ExtenderException.class, () -> sdkService.getPlatformSdkMappings("unstable_sdk_mapping"));

assertDoesNotThrow(() -> sdkService.getPlatformSdkMappings("unstable_sdk_mapping"));
}
}