Skip to content

Commit

Permalink
fix: http courier using should use lower case json (#3740)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored Feb 9, 2024
1 parent af55834 commit 84149c4
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 79 deletions.
12 changes: 6 additions & 6 deletions courier/http_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func (c *httpChannel) ID() string {
}

type httpDataModel struct {
Recipient string
Subject string
Body string
TemplateType template.TemplateType
TemplateData Template
MessageType string
Recipient string `json:"recipient"`
Subject string `json:"subject"`
Body string `json:"body"`
TemplateType template.TemplateType `json:"template_type"`
TemplateData Template `json:"template_data"`
MessageType string `json:"message_type"`
}

func (c *httpChannel) Dispatch(ctx context.Context, msg Message) (err error) {
Expand Down
24 changes: 12 additions & 12 deletions courier/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func TestQueueHTTPEmail(t *testing.T) {
ctx := context.Background()

type sendEmailRequestBody struct {
IdentityID string
IdentityEmail string
Recipient string
TemplateType string
To string
RecoveryCode string
RecoveryURL string
VerificationURL string
VerificationCode string
Body string
Subject string
IdentityID string `json:"identity_id"`
IdentityEmail string `json:"identity_email"`
Recipient string `json:"recipient"`
TemplateType string `json:"template_type"`
To string `json:"to"`
RecoveryCode string `json:"recovery_code"`
RecoveryURL string `json:"recovery_url"`
VerificationURL string `json:"verification_url"`
VerificationCode string `json:"verification_code"`
Body string `json:"body"`
Subject string `json:"subject"`
}

expectedEmail := []*email.TestStubModel{
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestQueueHTTPEmail(t *testing.T) {
if len(actual) == len(expectedEmail) {
return nil
}
return errors.New("capacity not reached")
return errors.Errorf("capacity not reached: %d of %d", len(actual), len(expectedEmail))
}))

for i, message := range actual {
Expand Down
18 changes: 9 additions & 9 deletions courier/stub/request.config.mailer.jsonnet
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function(ctx) {
recipient: ctx.Recipient,
template_type: ctx.TemplateType,
to: if "TemplateData" in ctx && "To" in ctx.TemplateData then ctx.TemplateData.To else null,
recovery_code: if "TemplateData" in ctx && "RecoveryCode" in ctx.TemplateData then ctx.TemplateData.RecoveryCode else null,
recovery_url: if "TemplateData" in ctx && "RecoveryURL" in ctx.TemplateData then ctx.TemplateData.RecoveryURL else null,
verification_url: if "TemplateData" in ctx && "VerificationURL" in ctx.TemplateData then ctx.TemplateData.VerificationURL else null,
verification_code: if "TemplateData" in ctx && "VerificationCode" in ctx.TemplateData then ctx.TemplateData.VerificationCode else null,
subject: if "TemplateData" in ctx && "Subject" in ctx.TemplateData then ctx.TemplateData.Subject else null,
body: if "TemplateData" in ctx && "Body" in ctx.TemplateData then ctx.TemplateData.Body else null
recipient: ctx.recipient,
template_type: ctx.template_type,
to: if "template_data" in ctx && "to" in ctx.template_data then ctx.template_data.to else null,
recovery_code: if "template_data" in ctx && "recovery_code" in ctx.template_data then ctx.template_data.recovery_code else null,
recovery_url: if "template_data" in ctx && "recovery_url" in ctx.template_data then ctx.template_data.recovery_url else null,
verification_url: if "template_data" in ctx && "verification_url" in ctx.template_data then ctx.template_data.verification_url else null,
verification_code: if "template_data" in ctx && "verification_code" in ctx.template_data then ctx.template_data.verification_code else null,
subject: if "template_data" in ctx && "subject" in ctx.template_data then ctx.template_data.subject else null,
body: if "template_data" in ctx && "body" in ctx.template_data then ctx.template_data.body else null
}
4 changes: 2 additions & 2 deletions courier/stub/request.config.twilio.jsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function(ctx) {
from: "Kratos Test",
to: ctx.Recipient,
body: ctx.Body
to: ctx.recipient,
body: ctx.body
}
6 changes: 3 additions & 3 deletions courier/template/email/login_code_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type (
model *LoginCodeValidModel
}
LoginCodeValidModel struct {
To string
LoginCode string
Identity map[string]interface{}
To string `json:"to"`
LoginCode string `json:"login_code"`
Identity map[string]interface{} `json:"identity"`
}
)

Expand Down
2 changes: 1 addition & 1 deletion courier/template/email/recovery_code_invalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type (
model *RecoveryCodeInvalidModel
}
RecoveryCodeInvalidModel struct {
To string
To string `json:"to"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions courier/template/email/recovery_code_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type (
model *RecoveryCodeValidModel
}
RecoveryCodeValidModel struct {
To string
RecoveryCode string
Identity map[string]interface{}
To string `json:"to"`
RecoveryCode string `json:"recovery_code"`
Identity map[string]interface{} `json:"identity"`
}
)

Expand Down
2 changes: 1 addition & 1 deletion courier/template/email/recovery_invalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type (
m *RecoveryInvalidModel
}
RecoveryInvalidModel struct {
To string
To string `json:"to"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions courier/template/email/recovery_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type (
m *RecoveryValidModel
}
RecoveryValidModel struct {
To string
RecoveryURL string
Identity map[string]interface{}
To string `json:"to"`
RecoveryURL string `json:"recovery_url"`
Identity map[string]interface{} `json:"identity"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions courier/template/email/registration_code_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type (
model *RegistrationCodeValidModel
}
RegistrationCodeValidModel struct {
To string
Traits map[string]interface{}
RegistrationCode string
To string `json:"to"`
Traits map[string]interface{} `json:"traits"`
RegistrationCode string `json:"registration_code"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions courier/template/email/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type (
m *TestStubModel
}
TestStubModel struct {
To string
Subject string
Body string
To string `json:"to"`
Subject string `json:"subject"`
Body string `json:"body"`
}
)

Expand Down
2 changes: 1 addition & 1 deletion courier/template/email/verification_code_invalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type (
m *VerificationCodeInvalidModel
}
VerificationCodeInvalidModel struct {
To string
To string `json:"to"`
}
)

Expand Down
8 changes: 4 additions & 4 deletions courier/template/email/verification_code_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ type (
m *VerificationCodeValidModel
}
VerificationCodeValidModel struct {
To string
VerificationURL string
VerificationCode string
Identity map[string]interface{}
To string `json:"to"`
VerificationURL string `json:"verification_url"`
VerificationCode string `json:"verification_code"`
Identity map[string]interface{} `json:"identity"`
}
)

Expand Down
2 changes: 1 addition & 1 deletion courier/template/email/verification_invalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type (
m *VerificationInvalidModel
}
VerificationInvalidModel struct {
To string
To string `json:"to"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions courier/template/email/verification_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type (
m *VerificationValidModel
}
VerificationValidModel struct {
To string
VerificationURL string
Identity map[string]interface{}
To string `json:"to"`
VerificationURL string `json:"verification_url"`
Identity map[string]interface{} `json:"identity"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions courier/template/sms/login_code_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type (
model *LoginCodeValidModel
}
LoginCodeValidModel struct {
To string
LoginCode string
Identity map[string]interface{}
To string `json:"to"`
LoginCode string `json:"login_code"`
Identity map[string]interface{} `json:"identity"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions courier/template/sms/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type (
}

TestStubModel struct {
To string
Body string
Identity map[string]interface{}
To string `json:"to"`
Body string `json:"body"`
Identity map[string]interface{} `json:"identity"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions courier/template/sms/verification_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type (
}

VerificationCodeValidModel struct {
To string
VerificationCode string
Identity map[string]interface{}
To string `json:"to"`
VerificationCode string `json:"verification_code"`
Identity map[string]interface{} `json:"identity"`
}
)

Expand Down
2 changes: 1 addition & 1 deletion embedx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"format": "uri",
"pattern": "^(http|https|file|base64)://",
"description": "URI pointing to the jsonnet template used for payload generation. Only used for those HTTP methods, which support HTTP body payloads",
"default": "base64://ZnVuY3Rpb24oY3R4KSB7CiAgcmVjaXBpZW50OiBjdHguUmVjaXBpZW50LAogIHRlbXBsYXRlX3R5cGU6IGN0eC5UZW1wbGF0ZVR5cGUsCiAgdG86IGlmICJUZW1wbGF0ZURhdGEiIGluIGN0eCAmJiAiVG8iIGluIGN0eC5UZW1wbGF0ZURhdGEgdGhlbiBjdHguVGVtcGxhdGVEYXRhLlRvIGVsc2UgbnVsbCwKICByZWNvdmVyeV9jb2RlOiBpZiAiVGVtcGxhdGVEYXRhIiBpbiBjdHggJiYgIlJlY292ZXJ5Q29kZSIgaW4gY3R4LlRlbXBsYXRlRGF0YSB0aGVuIGN0eC5UZW1wbGF0ZURhdGEuUmVjb3ZlcnlDb2RlIGVsc2UgbnVsbCwKICByZWNvdmVyeV91cmw6IGlmICJUZW1wbGF0ZURhdGEiIGluIGN0eCAmJiAiUmVjb3ZlcnlVUkwiIGluIGN0eC5UZW1wbGF0ZURhdGEgdGhlbiBjdHguVGVtcGxhdGVEYXRhLlJlY292ZXJ5VVJMIGVsc2UgbnVsbCwKICB2ZXJpZmljYXRpb25fdXJsOiBpZiAiVGVtcGxhdGVEYXRhIiBpbiBjdHggJiYgIlZlcmlmaWNhdGlvblVSTCIgaW4gY3R4LlRlbXBsYXRlRGF0YSB0aGVuIGN0eC5UZW1wbGF0ZURhdGEuVmVyaWZpY2F0aW9uVVJMIGVsc2UgbnVsbCwKICB2ZXJpZmljYXRpb25fY29kZTogaWYgIlRlbXBsYXRlRGF0YSIgaW4gY3R4ICYmICJWZXJ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fZGF0YSB0aGVuIGN0eC50ZW1wbGF0ZV9kYXRhLnZlcmlmaWNhdGlvbl9jb2RlIGVsc2UgbnVsbCwKICBzdWJqZWN0OiBjdHguc3ViamVjdCwKICBib2R5OiBjdHguYm9keQp9Cg==",
"examples": [
"file:///path/to/body.jsonnet",
"file://./body.jsonnet",
Expand Down
1 change: 1 addition & 0 deletions internal/client-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
22 changes: 11 additions & 11 deletions request/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
)

type testRequestBody struct {
To string
From string
Body string
To string `json:"to"`
From string `json:"from"`
Body string `json:"body"`
}

//go:embed stub/test_body.jsonnet
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestBuildRequest(t *testing.T) {
From: "+12288534869",
Body: "test-sms-body",
},
expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+12288534869\",\n \"To\": \"+15056445993\"\n}\n",
expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+12288534869\",\n \"to\": \"+15056445993\"\n}\n",
rawConfig: `{
"url": "https://test.kratos.ory.sh/my_endpoint1",
"method": "POST",
Expand All @@ -70,7 +70,7 @@ func TestBuildRequest(t *testing.T) {
From: "+12288534869",
Body: "test-sms-body",
},
expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+12288534869\",\n \"To\": \"+15056445993\"\n}\n",
expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+12288534869\",\n \"to\": \"+15056445993\"\n}\n",
rawConfig: `{
"url": "https://test.kratos.ory.sh/my_endpoint1",
"method": "POST",
Expand All @@ -87,7 +87,7 @@ func TestBuildRequest(t *testing.T) {
From: "+12288534869",
Body: "test-sms-body",
},
expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+12288534869\",\n \"To\": \"+15056445993\"\n}\n",
expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+12288534869\",\n \"to\": \"+15056445993\"\n}\n",
rawConfig: fmt.Sprintf(
`{
"url": "https://test.kratos.ory.sh/my_endpoint1",
Expand All @@ -108,7 +108,7 @@ func TestBuildRequest(t *testing.T) {
From: "+15822228108",
Body: "test-sms-body",
},
expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+15822228108\",\n \"To\": \"+12127110378\"\n}\n",
expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+15822228108\",\n \"to\": \"+12127110378\"\n}\n",
rawConfig: `{
"url": "https://test.kratos.ory.sh/my_endpoint2",
"method": "POST",
Expand All @@ -129,7 +129,7 @@ func TestBuildRequest(t *testing.T) {
From: "+13104661805",
Body: "test-sms-body",
},
expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+13104661805\",\n \"To\": \"+14134242223\"\n}\n",
expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+13104661805\",\n \"to\": \"+14134242223\"\n}\n",
rawConfig: `{
"url": "https://test.kratos.ory.sh/my_endpoint3",
"method": "GET",
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestBuildRequest(t *testing.T) {
From: "+14253787846",
Body: "test-sms-body",
},
expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+14253787846\",\n \"To\": \"+12235499085\"\n}\n",
expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+14253787846\",\n \"to\": \"+12235499085\"\n}\n",
rawConfig: `{
"url": "https://test.kratos.ory.sh/my_endpoint5",
"method": "DELETE",
Expand All @@ -198,7 +198,7 @@ func TestBuildRequest(t *testing.T) {
From: "+13104661805",
Body: "test-sms-body",
},
expectedBody: "Body=test-sms-body&From=%2B13104661805&To=%2B14134242223",
expectedBody: "body=test-sms-body&from=%2B13104661805&to=%2B14134242223",
rawConfig: `{
"url": "https://test.kratos.ory.sh/my_endpoint6",
"method": "POST",
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestBuildRequest(t *testing.T) {
From: "+13104661805",
Body: "test-sms-body",
},
expectedBody: "{\n \"Body\": \"test-sms-body\",\n \"From\": \"+13104661805\",\n \"To\": \"+14134242223\"\n}\n",
expectedBody: "{\n \"body\": \"test-sms-body\",\n \"from\": \"+13104661805\",\n \"to\": \"+14134242223\"\n}\n",
rawConfig: `{
"url": "https://test.kratos.ory.sh/my_endpoint7",
"method": "POST",
Expand Down
6 changes: 3 additions & 3 deletions request/stub/test_body.jsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function(ctx) {
From: ctx.From,
To: ctx.To,
Body: ctx.Body,
from: ctx.from,
to: ctx.to,
body: ctx.body,
}

0 comments on commit 84149c4

Please sign in to comment.