Skip to content

Commit

Permalink
add support to old way to set authorization token header
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Nov 23, 2021
1 parent d63ccf3 commit a1f5a5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions handlers/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
}
req.Header.Set("Content-Type", contentTypeHeader)

authorization := msg.Channel().StringConfigForKey(courier.ConfigSendAuthorization, "")
if authorization != "" {
req.Header.Set("Authorization", authorization)
}

headers := msg.Channel().ConfigForKey(courier.ConfigSendHeaders, map[string]interface{}{}).(map[string]interface{})

if len(headers) > 0 {
Expand Down
10 changes: 10 additions & 0 deletions handlers/external/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,14 @@ func TestSending(t *testing.T) {

RunChannelSendTestCases(t, nationalChannel, newHandler(), nationalGetSendTestCases, nil)

var jsonChannelWithSendAuthorization = courier.NewMockChannel("8eb23e93-5ecb-45ba-b726-3b064e0c56ab", "EX", "2020", "US",
map[string]interface{}{
"send_path": "",
courier.ConfigSendBody: `{ "to":{{to}}, "text":{{text}}, "from":{{from}}, "quick_replies":{{quick_replies}} }`,
courier.ConfigContentType: contentJSON,
courier.ConfigSendMethod: http.MethodPost,
courier.ConfigSendAuthorization: "Token ABCDEF",
})
RunChannelSendTestCases(t, jsonChannelWithSendAuthorization, newHandler(), jsonSendTestCases, nil)

}

0 comments on commit a1f5a5d

Please sign in to comment.