Skip to content

Commit

Permalink
Merge pull request #769 from nyaruka/fix-fcm-config
Browse files Browse the repository at this point in the history
Fix FCM authentication config retrieve to expect map[string]string
  • Loading branch information
rowanseymour authored Aug 7, 2024
2 parents d787494 + 346a945 commit bec9bf9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
10 changes: 4 additions & 6 deletions handlers/firebase/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,13 @@ func (h *handler) sendWithAPIKey(ctx context.Context, msg courier.MsgOut, res *c
func (h *handler) sendWithCredsJSON(ctx context.Context, msg courier.MsgOut, res *courier.SendResult, clog *courier.ChannelLog) error {
title := msg.Channel().StringConfigForKey(configTitle, "")

credentialsFile := msg.Channel().StringConfigForKey(configCredentialsFile, "")
if credentialsFile == "" {
credentialsFile := msg.Channel().ConfigForKey(configCredentialsFile, nil)
if credentialsFile == nil {
return courier.ErrChannelConfig
}

var credentialsFileJSON map[string]string

err := json.Unmarshal([]byte(credentialsFile), &credentialsFileJSON)
if err != nil {
credentialsFileJSON, ok := credentialsFile.(map[string]string)
if !ok {
return courier.ErrChannelConfig
}

Expand Down
52 changes: 26 additions & 26 deletions handlers/firebase/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,38 @@ var testChannels = []courier.Channel{
[]string{urns.Firebase.Prefix},
map[string]any{
configTitle: "FCMTitle",
configCredentialsFile: `{
"type": "service_account",
"project_id": "foo-project-id",
"private_key_id": "123",
"private_key": "BLAH",
"client_email": "foo@example.com",
"client_id": "123123",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "",
"universe_domain": "googleapis.com"
}`,
configCredentialsFile: map[string]string{
"type": "service_account",
"project_id": "foo-project-id",
"private_key_id": "123",
"private_key": "BLAH",
"client_email": "foo@example.com",
"client_id": "123123",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "",
"universe_domain": "googleapis.com",
},
}),
test.NewMockChannel("8eb23e93-5ecb-45ba-b726-3b064e0c568c", "FCM", "1234", "",
[]string{urns.Firebase.Prefix},
map[string]any{
configNotification: true,
configTitle: "FCMTitle",
configCredentialsFile: `{
"type": "service_account",
"project_id": "bar-project-id",
"private_key_id": "123",
"private_key": "BLAH",
"client_email": "foo@example.com",
"client_id": "123123",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "",
"universe_domain": "googleapis.com"
}`,
configCredentialsFile: map[string]string{
"type": "service_account",
"project_id": "bar-project-id",
"private_key_id": "123",
"private_key": "BLAH",
"client_email": "foo@example.com",
"client_id": "123123",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "",
"universe_domain": "googleapis.com",
},
}),
}

Expand Down

0 comments on commit bec9bf9

Please sign in to comment.