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

Update codegen-generated-classes-test for SRA #4548

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 @@ -42,6 +42,8 @@
import software.amazon.awssdk.http.SdkHttpResponse;
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.identity.spi.AwsCredentialsIdentity;
import software.amazon.awssdk.identity.spi.ResolveIdentityRequest;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient;
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient;
Expand All @@ -65,7 +67,8 @@ public class NoneAuthTypeRequestTest {
@Before
public void setup() throws IOException {
credentialsProvider = mock(AwsCredentialsProvider.class);
when(credentialsProvider.resolveIdentity()).thenAnswer(
when(credentialsProvider.identityType()).thenReturn(AwsCredentialsIdentity.class);
when(credentialsProvider.resolveIdentity(any(ResolveIdentityRequest.class))).thenAnswer(
invocationOnMock -> CompletableFuture.completedFuture(AwsBasicCredentials.create("123", "12344")));

httpClient = mock(SdkHttpClient.class);
Expand Down Expand Up @@ -98,56 +101,56 @@ public void setup() throws IOException {
public void sync_json_authorization_is_absent_for_noneAuthType() {
jsonClient.operationWithNoneAuthType(o -> o.booleanMember(true));
assertThat(getSyncRequest().firstMatchingHeader("Authorization")).isNotPresent();
verify(credentialsProvider, times(0)).resolveIdentity();
verify(credentialsProvider, times(0)).resolveIdentity(any(ResolveIdentityRequest.class));
}

@Test
public void sync_json_authorization_is_present_for_defaultAuth() {
jsonClient.jsonValuesOperation();
assertThat(getSyncRequest().firstMatchingHeader("Authorization")).isPresent();
verify(credentialsProvider, times(1)).resolveIdentity();
verify(credentialsProvider, times(1)).resolveIdentity(any(ResolveIdentityRequest.class));
}

@Test
public void async_json_authorization_is_absent_for_noneAuthType() {
jsonAsyncClient.operationWithNoneAuthType(o -> o.booleanMember(true));
assertThat(getAsyncRequest().firstMatchingHeader("Authorization")).isNotPresent();
verify(credentialsProvider, times(0)).resolveIdentity();
verify(credentialsProvider, times(0)).resolveIdentity(any(ResolveIdentityRequest.class));
}

@Test
public void async_json_authorization_is_present_for_defaultAuth() {
jsonAsyncClient.jsonValuesOperation();
assertThat(getAsyncRequest().firstMatchingHeader("Authorization")).isPresent();
verify(credentialsProvider, times(1)).resolveIdentity();
verify(credentialsProvider, times(1)).resolveIdentity(any(ResolveIdentityRequest.class));
}

@Test
public void sync_xml_authorization_is_absent_for_noneAuthType() {
xmlClient.operationWithNoneAuthType(o -> o.booleanMember(true));
assertThat(getSyncRequest().firstMatchingHeader("Authorization")).isNotPresent();
verify(credentialsProvider, times(0)).resolveIdentity();
verify(credentialsProvider, times(0)).resolveIdentity(any(ResolveIdentityRequest.class));
}

@Test
public void sync_xml_authorization_is_present_for_defaultAuth() {
xmlClient.jsonValuesOperation(json -> json.jsonValueMember("one"));
assertThat(getSyncRequest().firstMatchingHeader("Authorization")).isPresent();
verify(credentialsProvider, times(1)).resolveIdentity();
verify(credentialsProvider, times(1)).resolveIdentity(any(ResolveIdentityRequest.class));
}

@Test
public void async_xml_authorization_is_absent_for_noneAuthType() {
xmlAsyncClient.operationWithNoneAuthType(o -> o.booleanMember(true));
assertThat(getAsyncRequest().firstMatchingHeader("Authorization")).isNotPresent();
verify(credentialsProvider, times(0)).resolveIdentity();
verify(credentialsProvider, times(0)).resolveIdentity(any(ResolveIdentityRequest.class));
}

@Test
public void async_xml_authorization_is_present_for_defaultAuth() {
xmlAsyncClient.jsonValuesOperation(json -> json.jsonValueMember("one"));
assertThat(getAsyncRequest().firstMatchingHeader("Authorization")).isPresent();
verify(credentialsProvider, times(1)).resolveIdentity();
verify(credentialsProvider, times(1)).resolveIdentity(any(ResolveIdentityRequest.class));
}

private SdkHttpRequest getSyncRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.auth.token.credentials.SdkTokenProvider;
import software.amazon.awssdk.auth.token.credentials.aws.DefaultAwsTokenProvider;
import software.amazon.awssdk.auth.token.signer.aws.BearerTokenSigner;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder;
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
Expand All @@ -34,6 +33,8 @@
import software.amazon.awssdk.identity.spi.TokenIdentity;
import software.amazon.awssdk.regions.Region;

// TODO(sra-identity-auth): assert client is configured with SRA types like AUTH_SCHEMES, AUTH_SCHEME_PROVIDER,
// IDENTITY_PROVIDERS.
public class ClientBuilderTest {
@Test
public void syncClient_includesDefaultProvider_includesDefaultSigner() {
Expand All @@ -42,8 +43,7 @@ public void syncClient_includesDefaultProvider_includesDefaultSigner() {

assertThat(config.option(AwsClientOption.TOKEN_IDENTITY_PROVIDER))
.isInstanceOf(DefaultAwsTokenProvider.class);
assertThat(config.option(SdkAdvancedClientOption.TOKEN_SIGNER))
.isInstanceOf(BearerTokenSigner.class);
assertThat(config.option(SdkAdvancedClientOption.TOKEN_SIGNER)).isNull();;
}

@Test
Expand Down Expand Up @@ -90,8 +90,7 @@ public void asyncClient_includesDefaultProvider_includesDefaultSigner() {

assertThat(config.option(AwsClientOption.TOKEN_IDENTITY_PROVIDER))
.isInstanceOf(DefaultAwsTokenProvider.class);
assertThat(config.option(SdkAdvancedClientOption.TOKEN_SIGNER))
.isInstanceOf(BearerTokenSigner.class);
assertThat(config.option(SdkAdvancedClientOption.TOKEN_SIGNER)).isNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.regions.Region;


// TODO(sra-identity-auth): assert client is configured with SRA types like AUTH_SCHEMES, AUTH_SCHEME_PROVIDER,
// IDENTITY_PROVIDERS. For mixed auth, assert AUTH_SCHEMES has all expected.
public class ClientBuilderTest {
@Test
public void syncClient_buildWithDefaults_validationsSucceed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.regions.Region;

// TODO(sra-identity-auth): assert client is configured with SRA types like AUTH_SCHEMES, AUTH_SCHEME_PROVIDER,
// IDENTITY_PROVIDERS.
public class ClientBuilderTest {
@Test
public void syncClient_buildWithDefaults_validationsSucceed() {
Expand Down
Loading