Skip to content

Commit c84016c

Browse files
JerzyLabmoffatt
authored andcommitted
Added event for Cognito custom message (#185)
* Added custom messgage event * Added new line * update testdata json * review comments resolved
1 parent 7c08e63 commit c84016c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

events/cognito.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,24 @@ type GroupConfiguration struct {
124124
IAMRolesToOverride []string `json:"iamRolesToOverride"`
125125
PreferredRole *string `json:"preferredRole"`
126126
}
127+
128+
// CognitoEventUserPoolsCustomMessage is sent by AWS Cognito User Pools before a verification or MFA message is sent,
129+
// allowing a user to customize the message dynamically.
130+
type CognitoEventUserPoolsCustomMessage struct {
131+
CognitoEventUserPoolsHeader
132+
Request CognitoEventUserPoolsCustomMessageRequest `json:"request"`
133+
Response CognitoEventUserPoolsCustomMessageResponse `json:"response"`
134+
}
135+
136+
// CognitoEventUserPoolsCustomMessageRequest contains the request portion of a CustomMessage event
137+
type CognitoEventUserPoolsCustomMessageRequest struct {
138+
UserAttributes map[string]interface{} `json:"userAttributes"`
139+
CodeParameter string `json:"codeParameter"`
140+
}
141+
142+
// CognitoEventUserPoolsCustomMessageResponse contains the response portion of a CustomMessage event
143+
type CognitoEventUserPoolsCustomMessageResponse struct {
144+
SMSMessage string `json:"smsMessage"`
145+
EmailMessage string `json:"emailMessage"`
146+
EmailSubject string `json:"emailSubject"`
147+
}

events/cognito_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,30 @@ func TestCognitoEventUserPoolsPostAuthenticationMarshaling(t *testing.T) {
135135

136136
assert.JSONEq(t, string(inputJSON), string(outputJSON))
137137
}
138+
139+
func TestCognitoEventUserPoolsCustomMessageMarshaling(t *testing.T) {
140+
141+
// read json from file
142+
inputJSON, err := ioutil.ReadFile("./testdata/cognito-event-userpools-custommessage.json")
143+
if err != nil {
144+
t.Errorf("could not open test file. details: %v", err)
145+
}
146+
147+
// de-serialize into CognitoEvent
148+
var inputEvent CognitoEventUserPoolsCustomMessage
149+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
150+
t.Errorf("could not unmarshal event. details: %v", err)
151+
}
152+
153+
// serialize to json
154+
outputJSON, err := json.Marshal(inputEvent)
155+
if err != nil {
156+
t.Errorf("could not marshal event. details: %v", err)
157+
}
158+
159+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
160+
}
161+
162+
func TestCognitoUserPoolsCustomMessageMarshalingMalformedJson(t *testing.T) {
163+
test.TestMalformedJson(t, CognitoEventUserPoolsCustomMessage{})
164+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": "1",
3+
"triggerSource": "CustomMessage_SignUp/CustomMessage_ResendCode/CustomMessage_ForgotPassword/CustomMessage_VerifyUserAttribute",
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+
"userAttributes": {
13+
"phone_number_verified": true,
14+
"email_verified": false
15+
},
16+
"codeParameter": "####"
17+
},
18+
"response": {
19+
"smsMessage": "<custom message to be sent in the message with code parameter>",
20+
"emailMessage": "<custom message to be sent in the message with code parameter>",
21+
"emailSubject": "<custom email subject>"
22+
}
23+
}

0 commit comments

Comments
 (0)