Skip to content

Commit

Permalink
Add user_not_found to Create/Verify auth challenge events
Browse files Browse the repository at this point in the history
- Adds `user_not_found` field to:
    - `CognitoEventUserPoolsCreateAuthChallengeRequest`
    - `CognitoEventUserPoolsVerifyAuthChallengeRequest`
- Adds test cases where `user_not_found` becomes `true` for:
    - `CognitoEventUserPoolsDefineAuthChallengeRequest`
    - `CognitoEventUserPoolsCreateAuthChallengeRequest`
    - `CognitoEventUserPoolsVerifyAuthChallengeRequest`

issue #718
  • Loading branch information
kikuomax committed Nov 4, 2023
1 parent 3e195f6 commit 8e1b8a1
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 3 deletions.
45 changes: 45 additions & 0 deletions lambda-events/src/event/cognito/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ pub struct CognitoEventUserPoolsCreateAuthChallengeRequest {
#[serde(deserialize_with = "deserialize_lambda_map")]
#[serde(default)]
pub client_metadata: HashMap<String, String>,
#[serde(default)]
pub user_not_found: bool,
}

/// `CognitoEventUserPoolsCreateAuthChallengeResponse` defines create auth challenge response parameters
Expand Down Expand Up @@ -389,6 +391,8 @@ where
#[serde(deserialize_with = "deserialize_lambda_map")]
#[serde(default)]
pub client_metadata: HashMap<String, String>,
#[serde(default)]
pub user_not_found: bool,
}

/// `CognitoEventUserPoolsVerifyAuthChallengeResponse` defines verify auth challenge response parameters
Expand Down Expand Up @@ -482,6 +486,19 @@ mod test {
assert_eq!(parsed, reparsed);
}

#[test]
#[cfg(feature = "cognito")]
fn example_cognito_event_userpools_create_auth_challenge_user_not_found() {
let data = include_bytes!("../../fixtures/example-cognito-event-userpools-create-auth-challenge-user-not-found.json");
let parsed: CognitoEventUserPoolsCreateAuthChallenge = serde_json::from_slice(data).unwrap();

assert!(parsed.request.user_not_found);

let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: CognitoEventUserPoolsCreateAuthChallenge = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}

#[test]
#[cfg(feature = "cognito")]
fn example_cognito_event_userpools_custommessage() {
Expand Down Expand Up @@ -518,6 +535,21 @@ mod test {
assert_eq!(parsed, reparsed);
}

#[test]
#[cfg(feature = "cognito")]
fn example_cognito_event_userpools_define_auth_challenge_user_not_found() {
let data = include_bytes!(
"../../fixtures/example-cognito-event-userpools-define-auth-challenge-user-not-found.json"
);
let parsed: CognitoEventUserPoolsDefineAuthChallenge = serde_json::from_slice(data).unwrap();

assert!(parsed.request.user_not_found);

let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: CognitoEventUserPoolsDefineAuthChallenge = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}

#[test]
#[cfg(feature = "cognito")]
fn example_cognito_event_userpools_migrateuser() {
Expand Down Expand Up @@ -612,4 +644,17 @@ mod test {
let reparsed: CognitoEventUserPoolsVerifyAuthChallenge = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}

#[test]
#[cfg(feature = "cognito")]
fn example_cognito_event_userpools_verify_auth_challenge_user_not_found() {
let data = include_bytes!("../../fixtures/example-cognito-event-userpools-verify-auth-challenge-user-not-found.json");
let parsed: CognitoEventUserPoolsVerifyAuthChallenge = serde_json::from_slice(data).unwrap();

assert!(parsed.request.user_not_found);

let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: CognitoEventUserPoolsVerifyAuthChallenge = serde_json::from_slice(output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "1",
"region": "us-west-2",
"userPoolId": "<userPoolId>",
"userName": "<userName>",
"callerContext": {
"awsSdkVersion": "aws-sdk-unknown-unknown",
"clientId": "<clientId>"
},
"triggerSource": "CreateAuthChallenge_Authentication",
"request": {
"userAttributes": {
"sub": "<sub>",
"cognito:user_status": "CONFIRMED",
"phone_number_verified": "true",
"cognito:phone_number_alias": "+12223334455",
"phone_number": "+12223334455"
},
"challengeName": "CUSTOM_CHALLENGE",
"session": [
{
"challengeName": "PASSWORD_VERIFIER",
"challengeResult": true,
"challengeMetadata": "metadata"
}
],
"clientMetadata": {
"exampleMetadataKey": "example metadata value"
},
"userNotFound": true
},
"response": {
"publicChallengeParameters": {
"a": "b"
},
"privateChallengeParameters": {
"c": "d"
},
"challengeMetadata": "challengeMetadata"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
],
"clientMetadata": {
"exampleMetadataKey": "example metadata value"
}
},
"userNotFound": false
},
"response": {
"publicChallengeParameters": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": "1",
"region": "us-west-2",
"userPoolId": "<userPoolId>",
"userName": "<userName>",
"callerContext": {
"awsSdkVersion": "aws-sdk-unknown-unknown",
"clientId": "<clientId>"
},
"triggerSource": "DefineAuthChallenge_Authentication",
"request": {
"userAttributes": {
"sub": "<sub>",
"cognito:user_status": "CONFIRMED",
"phone_number_verified": "true",
"cognito:phone_number_alias": "+12223334455",
"phone_number": "+12223334455"
},
"session": [
{
"challengeName": "PASSWORD_VERIFIER",
"challengeResult": true,
"challengeMetadata": "metadata"
}
],
"clientMetadata": {
"exampleMetadataKey": "example metadata value"
},
"userNotFound": true
},
"response": {
"challengeName": "challengeName",
"issueTokens": true,
"failAuthentication": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"challengeAnswer": "123xxxx",
"clientMetadata": {
"exampleMetadataKey": "example metadata value"
}
},
"userNotFound": false
},
"response": {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": "1",
"region": "us-west-2",
"userPoolId": "<userPoolId>",
"userName": "<userName>",
"callerContext": {
"awsSdkVersion": "aws-sdk-unknown-unknown",
"clientId": "<clientId>"
},
"triggerSource": "VerifyAuthChallengeResponse_Authentication",
"request": {
"userAttributes": {
"sub": "<sub>",
"cognito:user_status": "CONFIRMED",
"phone_number_verified": "true",
"cognito:phone_number_alias": "+12223334455",
"phone_number": "+12223334455"
},
"privateChallengeParameters": {
"secret": "11122233"
},
"challengeAnswer": "123xxxx",
"clientMetadata": {
"exampleMetadataKey": "example metadata value"
},
"userNotFound": true
},
"response": {
"answerCorrect": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"challengeAnswer": "123xxxx",
"clientMetadata": {
"exampleMetadataKey": "example metadata value"
}
},
"userNotFound": false
},
"response": {
"answerCorrect": true
Expand Down

0 comments on commit 8e1b8a1

Please sign in to comment.