Skip to content

Commit

Permalink
Added cognito MigrateUser event struct (#194)
Browse files Browse the repository at this point in the history
* Added cognito MigrateUser event struct

* fix tabs broken by merge

* Update cognito_test.go
  • Loading branch information
mattrx authored and bmoffatt committed May 28, 2019
1 parent 9ab421a commit 6e3671a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
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
}
}

0 comments on commit 6e3671a

Please sign in to comment.