Repository: awslabs/aws-lambda-rust-runtime (language: rust)

Issue:
Missing `userNotFound` field in "create/verify auth challenge" Cognito user pool events
According to [AWS documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html), "create/verify auth challenge" Cognito user pool events should have `userNotFound` field, and they did as far as I tested on my AWS account. However, `user_not_found` fields are missing in:
- [`CognitoEventUserPoolsCreateAuthChallengeRequest`](https://github.com/awslabs/aws-lambda-rust-runtime/blob/3e195f6b0c734ae694cb1375fed57cf1b6dd01fd/lambda-events/src/event/cognito/mod.rs#L336-L346)
- [`CognitoEventUserPoolsVerifyAuthChallengeRequest`](https://github.com/awslabs/aws-lambda-rust-runtime/blob/3e195f6b0c734ae694cb1375fed57cf1b6dd01fd/lambda-events/src/event/cognito/mod.rs#L376-L392)

They should have `user_not_found` field similar to [`CognitoEventUserPoolsDefineAuthChallengeRequest`](https://github.com/awslabs/aws-lambda-rust-runtime/blob/3e195f6b0c734ae694cb1375fed57cf1b6dd01fd/lambda-events/src/event/cognito/mod.rs#L298-L308).

`userNotFound` information helps us when we have to generate dummy challenges for non-existing users so that users' presence is not disclosed.


Discussion / hints:

Fix patch:
diff --git a/lambda-events/src/event/cognito/mod.rs b/lambda-events/src/event/cognito/mod.rs
index 49f2eebd..c07c40a4 100644
--- a/lambda-events/src/event/cognito/mod.rs
+++ b/lambda-events/src/event/cognito/mod.rs
@@ -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
@@ -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
@@ -482,6 +486,20 @@ 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() {
@@ -518,6 +536,20 @@ 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() {
@@ -612,4 +644,18 @@ 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);
+    }
 }
diff --git a/lambda-events/src/fixtures/example-cognito-event-userpools-create-auth-challenge-user-not-found.json b/lambda-events/src/fixtures/example-cognito-event-userpools-create-auth-challenge-user-not-found.json
new file mode 100644
index 00000000..40ce2a2b
--- /dev/null
+++ b/lambda-events/src/fixtures/example-cognito-event-userpools-create-auth-challenge-user-not-found.json
@@ -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"
+  }
+}
diff --git a/lambda-events/src/fixtures/example-cognito-event-userpools-create-auth-challenge.json b/lambda-events/src/fixtures/example-cognito-event-userpools-create-auth-challenge.json
index 99acf0a2..2d0f2a83 100644
--- a/lambda-events/src/fixtures/example-cognito-event-userpools-create-auth-challenge.json
+++ b/lambda-events/src/fixtures/example-cognito-event-userpools-create-auth-challenge.json
@@ -26,7 +26,8 @@
     ],
     "clientMetadata": {
       "exampleMetadataKey": "example metadata value"
-    }
+    },
+    "userNotFound": false
   },
   "response": {
     "publicChallengeParameters": {
diff --git a/lambda-events/src/fixtures/example-cognito-event-userpools-define-auth-challenge-user-not-found.json b/lambda-events/src/fixtures/example-cognito-event-userpools-define-auth-challenge-user-not-found.json
new file mode 100644
index 00000000..1ad40e2a
--- /dev/null
+++ b/lambda-events/src/fixtures/example-cognito-event-userpools-define-auth-challenge-user-not-found.json
@@ -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
+  }
+}
diff --git a/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge-optional-answer-correct.json b/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge-optional-answer-correct.json
index 70a973f4..f6f7ca09 100644
--- a/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge-optional-answer-correct.json
+++ b/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge-optional-answer-correct.json
@@ -22,7 +22,8 @@
     "challengeAnswer": "123xxxx",
     "clientMetadata": {
       "exampleMetadataKey": "example metadata value"
-    }
+    },
+    "userNotFound": false
   },
   "response": {
   }
diff --git a/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge-user-not-found.json b/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge-user-not-found.json
new file mode 100644
index 00000000..a5068eaa
--- /dev/null
+++ b/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge-user-not-found.json
@@ -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
+  }
+}
diff --git a/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge.json b/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge.json
index b1d88fee..6bff9974 100644
--- a/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge.json
+++ b/lambda-events/src/fixtures/example-cognito-event-userpools-verify-auth-challenge.json
@@ -22,7 +22,8 @@
     "challengeAnswer": "123xxxx",
     "clientMetadata": {
       "exampleMetadataKey": "example metadata value"
-    }
+    },
+    "userNotFound": false
   },
   "response": {
     "answerCorrect": true


Test patch: