Skip to content

Added cognito MigrateUser event struct #194

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

Merged
merged 4 commits into from
May 28, 2019
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
22 changes: 22 additions & 0 deletions events/cognito.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
26 changes: 25 additions & 1 deletion events/cognito_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions events/testdata/cognito-event-userpools-migrateuser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "1",
"triggerSource": "UserMigration_Authentication",
"region": "<region>",
"userPoolId": "<userPoolId>",
"userName": "<userName>",
"callerContext": {
"awsSdkVersion": "<calling aws sdk with version>",
"clientId": "<apps client id>"
},
"request": {
"password": "<password>"
},
"response": {
"userAttributes": {
"email": "<email>",
"phone_number": "<phone_number>"
},
"finalUserStatus": "<final_user_status>",
"messageAction": "<message-action>",
"desiredDeliveryMediums": [
"<desired-delivery-mediums-1>",
"<desired-delivery-mediums-2>"
],
"forceAliasCreation": true
}
}