Skip to content

Commit 6e3671a

Browse files
mattrxbmoffatt
authored andcommitted
Added cognito MigrateUser event struct (#194)
* Added cognito MigrateUser event struct * fix tabs broken by merge * Update cognito_test.go
1 parent 9ab421a commit 6e3671a

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

events/cognito.go

+22
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ type CognitoEventUserPoolsPostAuthentication struct {
5252
Response CognitoEventUserPoolsPostAuthenticationResponse `json:"response"`
5353
}
5454

55+
// CognitoEventUserPoolsMigrateUser is sent by AWS Cognito User Pools when a user does not exist in the
56+
// user pool at the time of sign-in with a password, or in the forgot-password flow.
57+
type CognitoEventUserPoolsMigrateUser struct {
58+
CognitoEventUserPoolsHeader
59+
CognitoEventUserPoolsMigrateUserRequest `json:"request"`
60+
CognitoEventUserPoolsMigrateUserResponse `json:"response"`
61+
}
62+
5563
// CognitoEventUserPoolsCallerContext contains information about the caller
5664
type CognitoEventUserPoolsCallerContext struct {
5765
AWSSDKVersion string `json:"awsSdkVersion"`
@@ -111,6 +119,20 @@ type CognitoEventUserPoolsPostAuthenticationRequest struct {
111119
type CognitoEventUserPoolsPostAuthenticationResponse struct {
112120
}
113121

122+
// CognitoEventUserPoolsMigrateUserRequest contains the request portion of a MigrateUser event
123+
type CognitoEventUserPoolsMigrateUserRequest struct {
124+
Password string `json:"password"`
125+
}
126+
127+
// CognitoEventUserPoolsMigrateUserResponse contains the response portion of a MigrateUser event
128+
type CognitoEventUserPoolsMigrateUserResponse struct {
129+
UserAttributes map[string]string `json:"userAttributes"`
130+
FinalUserStatus string `json:"finalUserStatus"`
131+
MessageAction string `json:"messageAction"`
132+
DesiredDeliveryMediums []string `json:"desiredDeliveryMediums"`
133+
ForceAliasCreation bool `json:"forceAliasCreation"`
134+
}
135+
114136
// ClaimsOverrideDetails allows lambda to add, supress or override claims in the token
115137
type ClaimsOverrideDetails struct {
116138
GroupOverrideDetails GroupConfiguration `json:"groupOverrideDetails"`

events/cognito_test.go

+25-1
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,32 @@ func TestCognitoEventUserPoolsPostAuthenticationMarshaling(t *testing.T) {
136136
assert.JSONEq(t, string(inputJSON), string(outputJSON))
137137
}
138138

139-
func TestCognitoEventUserPoolsCustomMessageMarshaling(t *testing.T) {
139+
func TestCognitoEventUserPoolsMigrateUserMarshalingMalformedJson(t *testing.T) {
140+
test.TestMalformedJson(t, CognitoEventUserPoolsMigrateUser{})
141+
}
140142

143+
func TestCognitoEventUserPoolsMigrateUserMarshaling(t *testing.T) {
144+
// read json from file
145+
inputJSON, err := ioutil.ReadFile("./testdata/cognito-event-userpools-migrateuser.json")
146+
if err != nil {
147+
t.Errorf("could not open test file. details: %v", err)
148+
}
149+
150+
// de-serialize into CognitoEvent
151+
var inputEvent CognitoEventUserPoolsMigrateUser
152+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
153+
t.Errorf("could not unmarshal event. details: %v", err)
154+
}
155+
156+
// serialize to json
157+
outputJSON, err := json.Marshal(inputEvent)
158+
if err != nil {
159+
t.Errorf("could not marshal event. details: %v", err)
160+
}
161+
test.AssertJsonsEqual(t, inputJSON, outputJSON)
162+
}
163+
164+
func TestCognitoEventUserPoolsCustomMessageMarshaling(t *testing.T) {
141165
// read json from file
142166
inputJSON, err := ioutil.ReadFile("./testdata/cognito-event-userpools-custommessage.json")
143167
if err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "1",
3+
"triggerSource": "UserMigration_Authentication",
4+
"region": "<region>",
5+
"userPoolId": "<userPoolId>",
6+
"userName": "<userName>",
7+
"callerContext": {
8+
"awsSdkVersion": "<calling aws sdk with version>",
9+
"clientId": "<apps client id>"
10+
},
11+
"request": {
12+
"password": "<password>"
13+
},
14+
"response": {
15+
"userAttributes": {
16+
"email": "<email>",
17+
"phone_number": "<phone_number>"
18+
},
19+
"finalUserStatus": "<final_user_status>",
20+
"messageAction": "<message-action>",
21+
"desiredDeliveryMediums": [
22+
"<desired-delivery-mediums-1>",
23+
"<desired-delivery-mediums-2>"
24+
],
25+
"forceAliasCreation": true
26+
}
27+
}

0 commit comments

Comments
 (0)