Navigation Menu

Skip to content

Commit

Permalink
Revert "Add a storage client method for checking wheter a user has a …
Browse files Browse the repository at this point in the history
…stored manifest."

This reverts commit 8b6012f.
  • Loading branch information
jon-signal committed Mar 22, 2021
1 parent a7bad20 commit a816aa0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
Expand Up @@ -30,19 +30,14 @@ public class SecureStorageClient {

private final ExternalServiceCredentialGenerator storageServiceCredentialGenerator;
private final URI deleteUri;
private final URI getManifestUri;
private final FaultTolerantHttpClient httpClient;

@VisibleForTesting
static final String DELETE_PATH = "/v1/storage";

@VisibleForTesting
static final String GET_MANIFEST_PATH = "/v1/storage/manifest";

public SecureStorageClient(final ExternalServiceCredentialGenerator storageServiceCredentialGenerator, final Executor executor, final SecureStorageServiceConfiguration configuration) throws CertificateException {
this.storageServiceCredentialGenerator = storageServiceCredentialGenerator;
this.deleteUri = URI.create(configuration.getUri()).resolve(DELETE_PATH);
this.getManifestUri = URI.create(configuration.getUri()).resolve(GET_MANIFEST_PATH);
this.httpClient = FaultTolerantHttpClient.newBuilder()
.withCircuitBreaker(configuration.getCircuitBreakerConfiguration())
.withRetry(configuration.getRetryConfiguration())
Expand Down Expand Up @@ -73,24 +68,4 @@ public CompletableFuture<Void> deleteStoredData(final UUID accountUuid) {
throw new RuntimeException("Failed to delete storage service data: " + response.statusCode());
});
}

public CompletableFuture<Boolean> hasStoredData(final UUID accountUuid) {
final ExternalServiceCredentials credentials = storageServiceCredentialGenerator.generateFor(accountUuid.toString());

final HttpRequest request = HttpRequest.newBuilder()
.uri(getManifestUri)
.GET()
.header("Authorization", "Basic " + Base64.encodeBytes((credentials.getUsername() + ":" + credentials.getPassword()).getBytes(StandardCharsets.UTF_8)))
.build();

return httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApply(response -> {
if (response.statusCode() >= 200 && response.statusCode() < 300) {
return true;
} else if (response.statusCode() == 404) {
return false;
}

throw new RuntimeException("Failed to check for presence of manifest: " + response.statusCode());
});
}
}
Expand Up @@ -27,12 +27,9 @@

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -121,46 +118,4 @@ public void deleteStoredDataFailure() {

assertThrows(RuntimeException.class, () -> secureStorageClient.deleteStoredData(accountUuid).join());
}

@Test
public void hasManifest() {
final String username = RandomStringUtils.randomAlphabetic(16);
final String password = RandomStringUtils.randomAlphanumeric(32);

when(credentialGenerator.generateFor(accountUuid.toString())).thenReturn(new ExternalServiceCredentials(username, password));

wireMockRule.stubFor(get(urlEqualTo(SecureStorageClient.GET_MANIFEST_PATH))
.withBasicAuth(username, password)
.willReturn(aResponse().withStatus(200)));

assertTrue(secureStorageClient.hasStoredData(accountUuid).join());
}

@Test
public void hasManifesNotFound() {
final String username = RandomStringUtils.randomAlphabetic(16);
final String password = RandomStringUtils.randomAlphanumeric(32);

when(credentialGenerator.generateFor(accountUuid.toString())).thenReturn(new ExternalServiceCredentials(username, password));

wireMockRule.stubFor(get(urlEqualTo(SecureStorageClient.GET_MANIFEST_PATH))
.withBasicAuth(username, password)
.willReturn(aResponse().withStatus(404)));

assertFalse(secureStorageClient.hasStoredData(accountUuid).join());
}

@Test
public void hasManifestFailure() {
final String username = RandomStringUtils.randomAlphabetic(16);
final String password = RandomStringUtils.randomAlphanumeric(32);

when(credentialGenerator.generateFor(accountUuid.toString())).thenReturn(new ExternalServiceCredentials(username, password));

wireMockRule.stubFor(get(urlEqualTo(SecureStorageClient.GET_MANIFEST_PATH))
.withBasicAuth(username, password)
.willReturn(aResponse().withStatus(400)));

assertThrows(RuntimeException.class, () -> secureStorageClient.hasStoredData(accountUuid).join());
}
}

0 comments on commit a816aa0

Please sign in to comment.