Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing expectations for non-set properties #4911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,32 @@ class S3SignerPropertiesPluginsTest {

@ParameterizedTest
@MethodSource("testCases")
public void validateTestCase(TestCase testCase) {
void validateTestCase(TestCase testCase) {
CapturingInterceptor capturingInterceptor = new CapturingInterceptor();
S3ClientBuilder clientBuilder = getS3ClientBuilder(capturingInterceptor);
testCase.configureClient().accept(clientBuilder);
S3Client client = clientBuilder.build();

assertThatThrownBy(() -> testCase.useClient().accept(client))
.hasMessageContaining("boom")
.as(testCase.name());
.as(testCase.name() + " - Expected exception");

AuthSchemeOption expectedValues = testCase.expectedSignerProperties();
Map<SignerProperty<?>, Object> expectedProperties = signerProperties(expectedValues);

assertThat(selectSignerProperties(signerProperties(capturingInterceptor.authSchemeOption()), expectedProperties.keySet()))
assertThat(
selectSignerProperties(
signerProperties(capturingInterceptor.authSchemeOption()),
expectedProperties.keySet()))
.isEqualTo(expectedProperties)
.as(testCase.name());
assertThat(selectSignerProperties(signerProperties(capturingInterceptor.authSchemeOption()), testCase.unsetProperties()))
.as(testCase.name() + " - Expected Properties");

assertThat(
selectSignerProperties(
signerProperties(capturingInterceptor.authSchemeOption()),
testCase.unsetProperties()))
.isEqualTo(Collections.emptyMap())
.as(testCase.name());
.as(testCase.name() + " - Expected Unset Properties");
}

static Map<SignerProperty<?>, Object> signerProperties(AuthSchemeOption option) {
Expand Down Expand Up @@ -112,22 +120,22 @@ public static Collection<TestCase> testCases() {
testUploadPartEnablesPayloadSigningUsingPlugin(),
// S3OverrideAuthSchemePropertiesPlugin.disableChunkEncoding()
testUploadPartDisablesChunkEncodingUsingPlugin(),
testPutObjectDisablesChunkEncodingUsingPlugin() ,
testPutObjectDisablesChunkEncodingUsingPlugin(),
testGetObjectDoesNotDisablesChunkEncodingUsingPlugin()
);
}

// S3OverrideAuthSchemePropertiesPlugin.enablePayloadSigningPlugin()
private static TestCase testUploadPartDisablesPayloadSigningByDefault() {
return forUploadPart("UploadPartDisablesPayloadSigningByDefault")
return forUploadPart("Disables PayloadSigning By Default")
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder()
.putSignerProperty(AwsV4FamilyHttpSigner.PAYLOAD_SIGNING_ENABLED, false)
.build())
.build();
}

private static TestCase testUploadPartEnablesPayloadSigningUsingPlugin() {
return forUploadPart("UploadPartEnablesPayloadSigningUsingPlugin")
return forUploadPart("Enables PayloadSigning Using Plugin")
.configureClient(c -> c.addPlugin(S3OverrideAuthSchemePropertiesPlugin.enablePayloadSigningPlugin()))
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder()
.putSignerProperty(AwsV4FamilyHttpSigner.PAYLOAD_SIGNING_ENABLED, true)
Expand All @@ -136,10 +144,9 @@ private static TestCase testUploadPartEnablesPayloadSigningUsingPlugin() {

}


// S3OverrideAuthSchemePropertiesPlugin.disableChunkEncoding()
private static TestCase testUploadPartDisablesChunkEncodingUsingPlugin() {
return forUploadPart("UploadPartDisablesChunkEncodingUsingPlugin")
return forUploadPart("Disables ChunkEncoding Using Plugin")
.configureClient(c -> c.addPlugin(S3OverrideAuthSchemePropertiesPlugin.disableChunkEncodingPlugin()))
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder()
.putSignerProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED, false)
Expand All @@ -149,7 +156,7 @@ private static TestCase testUploadPartDisablesChunkEncodingUsingPlugin() {
}

static TestCase testPutObjectDisablesChunkEncodingUsingPlugin() {
return forPutObject("PutObjectDisablesChunkEncodingUsingPlugin")
return forPutObject("Disables ChunkEncoding Using Plugin")
.configureClient(c -> c.addPlugin(S3OverrideAuthSchemePropertiesPlugin.disableChunkEncodingPlugin()))
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder()
.putSignerProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED, false)
Expand All @@ -158,45 +165,44 @@ static TestCase testPutObjectDisablesChunkEncodingUsingPlugin() {
}

static TestCase testGetObjectDoesNotDisablesChunkEncodingUsingPlugin() {
return forGetObject("GetObjectDoesNotDisablesChunkEncodingUsingPlugin")
return forGetObject("Does Not Disable ChunkEncoding Using Plugin")
.configureClient(c -> c.addPlugin(S3OverrideAuthSchemePropertiesPlugin.disableChunkEncodingPlugin()))
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder()
.build())
.addUnsetProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED)
.addExpectedUnsetProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED)
.build();
}

// S3DisableChunkEncodingIfConfiguredPlugin
static TestCase testUploadPartEnablesChunkEncodingByDefault() {
return forUploadPart("UploadPartEnablesChunkEncodingByDefault")
return forUploadPart("Enables ChunkEncoding By Default")
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder()
.putSignerProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED, true)
.build())
.build();
}

static TestCase testUploadPartDisablesChunkEncodingWhenConfigured() {
return forUploadPart("UploadPartDisablesChunkEncodingWhenConfigured")
return forUploadPart("Disables ChunkEncoding When Configured")
.configureClient(c -> c.serviceConfiguration(S3Configuration.builder()
.chunkedEncodingEnabled(false)
.build()))
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder()
.putSignerProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED, false)
.build())
.build();

}

static TestCase testPutObjectEnablesChunkEncodingByDefault() {
return forPutObject("PutObjectEnablesChunkEncodingByDefault")
return forPutObject("Enables ChunkEncoding By Default")
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder()
.putSignerProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED, true)
.build())
.build();
}

static TestCase testPutObjectDisablesChunkEncodingWhenConfigured() {
return forPutObject("PutObjectDisablesChunkEncodingWhenConfigured")
return forPutObject("Disables ChunkEncoding When Configured")
.configureClient(c -> c.serviceConfiguration(S3Configuration.builder()
.chunkedEncodingEnabled(false)
.build()))
Expand All @@ -207,32 +213,35 @@ static TestCase testPutObjectDisablesChunkEncodingWhenConfigured() {
}

static TestCase testGetObjectDoesNotSetChunkEncoding() {
return forGetObject("GetObjectDoesNotSetChunkEncoding")
return forGetObject("Does Not Set ChunkEncoding")
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder().build())
.addExpectedUnsetProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED)
.build();
}

static TestCase testGetObjectDoesNotSetChunkEncodingIfNotConfigured() {
return forGetObject("GetObjectDoesNotSetChunkEncodingIfNotConfigured")
return forGetObject("Does Not Set ChunkEncoding If Not Configured")
.configureClient(c -> c.serviceConfiguration(S3Configuration.builder()
.chunkedEncodingEnabled(true)
.build()))
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder().build())
.addExpectedUnsetProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED)
.build();
}

static TestCase testGetObjectDoesNotSetChunkEncodingIfConfigured() {
return forGetObject("GetObjectDoesNotSetChunkEncodingIfConfigured")
return forGetObject("Does Not Set ChunkEncoding If Configured")
.configureClient(c -> c.serviceConfiguration(S3Configuration.builder()
.chunkedEncodingEnabled(false)
.build()))
.expectedSignerProperties(defaultExpectedAuthSchemeOptionBuilder().build())
.addExpectedUnsetProperty(AwsV4FamilyHttpSigner.CHUNK_ENCODING_ENABLED)
.build();
}

// End of tests, utils next
static TestCaseBuilder forUploadPart(String name) {
return testCaseBuilder(name)
return testCaseBuilder("UploadPart " + name)
.useClient(c -> {
UploadPartRequest.Builder requestBuilder =
UploadPartRequest.builder().bucket(DEFAULT_BUCKET).key(DEFAULT_KEY).partNumber(0).uploadId("test");
Expand All @@ -241,7 +250,7 @@ static TestCaseBuilder forUploadPart(String name) {
}

static TestCaseBuilder forPutObject(String name) {
return testCaseBuilder(name)
return testCaseBuilder("PutObject " + name)
.useClient(c -> {
PutObjectRequest.Builder requestBuilder =
PutObjectRequest.builder().bucket(DEFAULT_BUCKET).key(DEFAULT_KEY);
Expand All @@ -250,7 +259,7 @@ static TestCaseBuilder forPutObject(String name) {
}

static TestCaseBuilder forGetObject(String name) {
return testCaseBuilder(name)
return testCaseBuilder("GetObject " + name)
.useClient(c -> {
GetObjectRequest.Builder requestBuilder =
GetObjectRequest.builder().bucket(DEFAULT_BUCKET).key(DEFAULT_KEY);
Expand Down Expand Up @@ -329,7 +338,7 @@ public TestCaseBuilder unsetProperties(Set<SignerProperty<?>> unsetProperties) {
return this;
}

public TestCaseBuilder addUnsetProperty(SignerProperty<?> unsetProperty) {
public TestCaseBuilder addExpectedUnsetProperty(SignerProperty<?> unsetProperty) {
this.unsetProperties.add(unsetProperty);
return this;
}
Expand Down Expand Up @@ -377,6 +386,11 @@ public AuthSchemeOption expectedSignerProperties() {
public Set<SignerProperty<?>> unsetProperties() {
return unsetProperties;
}

@Override
public String toString() {
return name;
}
}

static class SignerPropertiesBuilder {
Expand Down