From 1c044b3e61fe53edce8a9264f76dd11a2309fda2 Mon Sep 17 00:00:00 2001 From: Jerzy Date: Tue, 30 Apr 2019 12:09:33 +0200 Subject: [PATCH 1/4] Added custom messgage event --- events/cognito.go | 21 +++++++++++++++ events/cognito_test.go | 27 +++++++++++++++++++ ...cognito-event-userpools-custommessage.json | 23 ++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 events/testdata/cognito-event-userpools-custommessage.json diff --git a/events/cognito.go b/events/cognito.go index a518abf8..93f9be46 100644 --- a/events/cognito.go +++ b/events/cognito.go @@ -106,3 +106,24 @@ type GroupConfiguration struct { IAMRolesToOverride []string `json:"iamRolesToOverride"` PreferredRole *string `json:"preferredRole"` } + +// CognitoEventUserPoolsCustomMessage is sent by AWS Cognito User Pools before a verification or MFA message is sent, +// allowing a user to customize the message dynamically. +type CognitoEventUserPoolsCustomMessage struct { + CognitoEventUserPoolsHeader + Request CognitoEventUserPoolsCustomMessageRequest `json:"request"` + Response CognitoEventUserPoolsCustomMessageResponse `json:"response"` +} + +// CognitoEventUserPoolsCustomMessageRequest contains the request portion of a CustomMessage event +type CognitoEventUserPoolsCustomMessageRequest struct { + UserAttributes map[string]bool `json:"userAttributes"` + CodeParameter string `json:"codeParameter"` +} + +// CognitoEventUserPoolsCustomMessageResponse contains the response portion of a CustomMessage event +type CognitoEventUserPoolsCustomMessageResponse struct { + SmsMessage string `json:"smsMessage"` + EmailMessage string `json:"emailMessage"` + EmailSubject string `json:"emailSubject"` +} diff --git a/events/cognito_test.go b/events/cognito_test.go index a619e47a..bf91f513 100644 --- a/events/cognito_test.go +++ b/events/cognito_test.go @@ -112,3 +112,30 @@ func TestCognitoEventUserPoolsPreTokenGenMarshaling(t *testing.T) { 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 { + t.Errorf("could not open test file. details: %v", err) + } + + // de-serialize into CognitoEvent + var inputEvent CognitoEventUserPoolsCustomMessage + 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) + } + + assert.JSONEq(t, string(inputJSON), string(outputJSON)) +} + +func TestCognitoUserPoolsCustomMessageMarshalingMalformedJson(t *testing.T) { + test.TestMalformedJson(t, CognitoEventUserPoolsCustomMessage{}) +} diff --git a/events/testdata/cognito-event-userpools-custommessage.json b/events/testdata/cognito-event-userpools-custommessage.json new file mode 100644 index 00000000..305aae15 --- /dev/null +++ b/events/testdata/cognito-event-userpools-custommessage.json @@ -0,0 +1,23 @@ +{ + "version": "1", + "triggerSource": "CustomMessage_SignUp", + "region": "", + "userPoolId": "", + "userName": "", + "callerContext": { + "awsSdkVersion": "", + "clientId": "" + }, + "request": { + "userAttributes": { + "phone_number_verified": true, + "email_verified": false + }, + "codeParameter": "####" + }, + "response": { + "smsMessage": "", + "emailMessage": "", + "emailSubject": "" + } +} \ No newline at end of file From 88744c3517772cace772c3a58dab4dd7932fd247 Mon Sep 17 00:00:00 2001 From: Jerzy Date: Tue, 30 Apr 2019 12:13:39 +0200 Subject: [PATCH 2/4] Added new line --- events/testdata/cognito-event-userpools-custommessage.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/events/testdata/cognito-event-userpools-custommessage.json b/events/testdata/cognito-event-userpools-custommessage.json index 305aae15..006642c2 100644 --- a/events/testdata/cognito-event-userpools-custommessage.json +++ b/events/testdata/cognito-event-userpools-custommessage.json @@ -20,4 +20,4 @@ "emailMessage": "", "emailSubject": "" } -} \ No newline at end of file +} From 52c0700a1d9801fa380f88876a5b26fc2733ecf2 Mon Sep 17 00:00:00 2001 From: Jerzy Date: Tue, 30 Apr 2019 12:14:34 +0200 Subject: [PATCH 3/4] update testdata json --- events/testdata/cognito-event-userpools-custommessage.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/events/testdata/cognito-event-userpools-custommessage.json b/events/testdata/cognito-event-userpools-custommessage.json index 006642c2..48c43f29 100644 --- a/events/testdata/cognito-event-userpools-custommessage.json +++ b/events/testdata/cognito-event-userpools-custommessage.json @@ -1,6 +1,6 @@ { "version": "1", - "triggerSource": "CustomMessage_SignUp", + "triggerSource": "CustomMessage_SignUp/CustomMessage_ResendCode/CustomMessage_ForgotPassword/CustomMessage_VerifyUserAttribute", "region": "", "userPoolId": "", "userName": "", From bab23385ce4773162d9b1136200575d5b52cb436 Mon Sep 17 00:00:00 2001 From: Jerzy Date: Sun, 19 May 2019 21:30:54 +0200 Subject: [PATCH 4/4] review comments resolved --- events/cognito.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/events/cognito.go b/events/cognito.go index 93f9be46..d2a751e3 100644 --- a/events/cognito.go +++ b/events/cognito.go @@ -117,13 +117,13 @@ type CognitoEventUserPoolsCustomMessage struct { // CognitoEventUserPoolsCustomMessageRequest contains the request portion of a CustomMessage event type CognitoEventUserPoolsCustomMessageRequest struct { - UserAttributes map[string]bool `json:"userAttributes"` - CodeParameter string `json:"codeParameter"` + UserAttributes map[string]interface{} `json:"userAttributes"` + CodeParameter string `json:"codeParameter"` } // CognitoEventUserPoolsCustomMessageResponse contains the response portion of a CustomMessage event type CognitoEventUserPoolsCustomMessageResponse struct { - SmsMessage string `json:"smsMessage"` + SMSMessage string `json:"smsMessage"` EmailMessage string `json:"emailMessage"` EmailSubject string `json:"emailSubject"` }