Skip to content

Commit

Permalink
add test for groupsToOverride and iamRolesToOverride
Browse files Browse the repository at this point in the history
  • Loading branch information
torbjokv committed Dec 9, 2024
1 parent dc6e7f6 commit d983c39
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import com.amazonaws.services.lambda.runtime.events.CloudWatchLogsEvent;
import com.amazonaws.services.lambda.runtime.events.CloudWatchMetricAlarmEvent;
import com.amazonaws.services.lambda.runtime.events.CodeCommitEvent;
import com.amazonaws.services.lambda.runtime.events.CognitoUserPoolPreTokenGenerationEventV2.ClaimsAndScopeOverrideDetails;
import com.amazonaws.services.lambda.runtime.events.CognitoUserPoolPreTokenGenerationEventV2.Response;
import com.amazonaws.services.lambda.runtime.events.CognitoUserPoolPreTokenGenerationEventV2;
import com.amazonaws.services.lambda.runtime.events.CognitoUserPoolPreTokenGenerationEventV2.GroupOverrideDetails;
import com.amazonaws.services.lambda.runtime.events.ConfigEvent;
import com.amazonaws.services.lambda.runtime.events.ConnectEvent;
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
Expand Down Expand Up @@ -111,8 +114,8 @@ public void testLoadKafkaEvent() {

KafkaEvent.KafkaEventRecord record = event.getRecords().get("mytopic-01").get(0);
assertThat(record.getValue()).decodedAsBase64().asString().isEqualTo("Hello from Kafka !!");
String headerValue = new String(record.getHeaders().get(0).get("headerKey"));

String headerValue = new String(record.getHeaders().get(0).get("headerKey"));
assertThat(headerValue).isEqualTo("headerValue");
}

Expand Down Expand Up @@ -151,7 +154,7 @@ public void testLoadKinesisFirehoseEvent() {
@Test
public void testLoadMSKFirehoseEvent() {
MSKFirehoseEvent event = EventLoader.loadMSKFirehoseEvent("msk_firehose_event.json");

assertThat(event).isNotNull();
assertThat(event.getSourceMSKArn()).isEqualTo("arn:aws:kafka:EXAMPLE");
assertThat(event.getDeliveryStreamArn()).isEqualTo("arn:aws:firehose:EXAMPLE");
Expand Down Expand Up @@ -420,6 +423,29 @@ public void testLoadCognitoUserPoolPreTokenGenerationEventV2() {
assertThat("aws.cognito.signin.user.admin").isEqualTo(requestScopes[0]);
}

@Test
public void testGroupOverrideDetailsCognitoUserPoolPreTokenGenerationEventV2() {
CognitoUserPoolPreTokenGenerationEventV2 event = EventLoader.loadCognitoUserPoolPreTokenGenerationEventV2(
"cognito_user_pool_pre_token_generation_event_v2_with_response.json");

assertThat(event).isNotNull();
assertThat(event)
.extracting(CognitoUserPoolPreTokenGenerationEventV2::getResponse)
.extracting(Response::getClaimsAndScopeOverrideDetails)
.extracting(ClaimsAndScopeOverrideDetails::getGroupOverrideDetails)
.extracting(GroupOverrideDetails::getGroupsToOverride)
.asList()
.contains("my_group");

assertThat(event)
.extracting(CognitoUserPoolPreTokenGenerationEventV2::getResponse)
.extracting(Response::getClaimsAndScopeOverrideDetails)
.extracting(ClaimsAndScopeOverrideDetails::getGroupOverrideDetails)
.extracting(GroupOverrideDetails::getIamRolesToOverride)
.asList()
.contains("my_role");
}

@Test
public void testCloudWatchCompositeAlarmEvent() {
CloudWatchCompositeAlarmEvent event = EventLoader.loadCloudWatchCompositeAlarmEvent("cloudwatch_composite_alarm.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"version": "2",
"triggerSource": "TokenGeneration_Authentication",
"region": "us-east-1",
"userPoolId": "us-east-1_EXAMPLE",
"userName": "JaneDoe",
"callerContext": {
"awsSdkVersion": "aws-sdk-unknown-unknown",
"clientId": "1example23456789"
},
"request": {
"userAttributes": {
"string": "string"
},
"scopes": ["string", "string"],
"groupConfiguration": {
"groupsToOverride": ["string", "string"],
"iamRolesToOverride": ["string", "string"],
"preferredRole": "string"
},
"clientMetadata": {
"string": "string"
}
},
"response": {
"claimsAndScopeOverrideDetails": {
"idTokenGeneration": {
"claimsToAddOrOverride": {
"string": ["accepted datatype"]
},
"claimsToSuppress": ["string", "string"]
},
"accessTokenGeneration": {
"claimsToAddOrOverride": {
"string": ["accepted datatype"]
},
"claimsToSuppress": ["string", "string"],
"scopesToAdd": ["string", "string"],
"scopesToSuppress": ["string", "string"]
},
"groupOverrideDetails": {
"groupsToOverride": ["my_group", "string"],
"iamRolesToOverride": ["my_role", "string"],
"preferredRole": "string"
}
}
}
}

0 comments on commit d983c39

Please sign in to comment.