From 6e3671ae53de51752c684359a3ab3152a2b35283 Mon Sep 17 00:00:00 2001 From: Matthias Rumpf Date: Tue, 28 May 2019 20:07:29 +0200 Subject: [PATCH] Added cognito MigrateUser event struct (#194) * Added cognito MigrateUser event struct * fix tabs broken by merge * Update cognito_test.go --- events/cognito.go | 22 +++++++++++++++ events/cognito_test.go | 26 +++++++++++++++++- .../cognito-event-userpools-migrateuser.json | 27 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 events/testdata/cognito-event-userpools-migrateuser.json diff --git a/events/cognito.go b/events/cognito.go index a9a9326c..5124f0dc 100644 --- a/events/cognito.go +++ b/events/cognito.go @@ -52,6 +52,14 @@ type CognitoEventUserPoolsPostAuthentication struct { Response CognitoEventUserPoolsPostAuthenticationResponse `json:"response"` } +// CognitoEventUserPoolsMigrateUser is sent by AWS Cognito User Pools when a user does not exist in the +// user pool at the time of sign-in with a password, or in the forgot-password flow. +type CognitoEventUserPoolsMigrateUser struct { + CognitoEventUserPoolsHeader + CognitoEventUserPoolsMigrateUserRequest `json:"request"` + CognitoEventUserPoolsMigrateUserResponse `json:"response"` +} + // CognitoEventUserPoolsCallerContext contains information about the caller type CognitoEventUserPoolsCallerContext struct { AWSSDKVersion string `json:"awsSdkVersion"` @@ -111,6 +119,20 @@ type CognitoEventUserPoolsPostAuthenticationRequest struct { type CognitoEventUserPoolsPostAuthenticationResponse struct { } +// CognitoEventUserPoolsMigrateUserRequest contains the request portion of a MigrateUser event +type CognitoEventUserPoolsMigrateUserRequest struct { + Password string `json:"password"` +} + +// CognitoEventUserPoolsMigrateUserResponse contains the response portion of a MigrateUser event +type CognitoEventUserPoolsMigrateUserResponse struct { + UserAttributes map[string]string `json:"userAttributes"` + FinalUserStatus string `json:"finalUserStatus"` + MessageAction string `json:"messageAction"` + DesiredDeliveryMediums []string `json:"desiredDeliveryMediums"` + ForceAliasCreation bool `json:"forceAliasCreation"` +} + // ClaimsOverrideDetails allows lambda to add, supress or override claims in the token type ClaimsOverrideDetails struct { GroupOverrideDetails GroupConfiguration `json:"groupOverrideDetails"` diff --git a/events/cognito_test.go b/events/cognito_test.go index 190b602d..47ca06b5 100644 --- a/events/cognito_test.go +++ b/events/cognito_test.go @@ -136,8 +136,32 @@ func TestCognitoEventUserPoolsPostAuthenticationMarshaling(t *testing.T) { assert.JSONEq(t, string(inputJSON), string(outputJSON)) } -func TestCognitoEventUserPoolsCustomMessageMarshaling(t *testing.T) { +func TestCognitoEventUserPoolsMigrateUserMarshalingMalformedJson(t *testing.T) { + test.TestMalformedJson(t, CognitoEventUserPoolsMigrateUser{}) +} +func TestCognitoEventUserPoolsMigrateUserMarshaling(t *testing.T) { + // read json from file + inputJSON, err := ioutil.ReadFile("./testdata/cognito-event-userpools-migrateuser.json") + if err != nil { + t.Errorf("could not open test file. details: %v", err) + } + + // de-serialize into CognitoEvent + var inputEvent CognitoEventUserPoolsMigrateUser + if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { + t.Errorf("could not unmarshal event. details: %v", err) + } + + // serialize to json + outputJSON, err := json.Marshal(inputEvent) + if err != nil { + t.Errorf("could not marshal event. details: %v", err) + } + test.AssertJsonsEqual(t, inputJSON, outputJSON) +} + +func TestCognitoEventUserPoolsCustomMessageMarshaling(t *testing.T) { // read json from file inputJSON, err := ioutil.ReadFile("./testdata/cognito-event-userpools-custommessage.json") if err != nil { diff --git a/events/testdata/cognito-event-userpools-migrateuser.json b/events/testdata/cognito-event-userpools-migrateuser.json new file mode 100644 index 00000000..4991195d --- /dev/null +++ b/events/testdata/cognito-event-userpools-migrateuser.json @@ -0,0 +1,27 @@ +{ + "version": "1", + "triggerSource": "UserMigration_Authentication", + "region": "", + "userPoolId": "", + "userName": "", + "callerContext": { + "awsSdkVersion": "", + "clientId": "" + }, + "request": { + "password": "" + }, + "response": { + "userAttributes": { + "email": "", + "phone_number": "" + }, + "finalUserStatus": "", + "messageAction": "", + "desiredDeliveryMediums": [ + "", + "" + ], + "forceAliasCreation": true + } +} \ No newline at end of file