Skip to content

Commit

Permalink
Fix FCM authentication config retrieve to expect map[string]string
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Aug 7, 2024
1 parent d787494 commit 17fc110
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
8 changes: 3 additions & 5 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, "")
credentialsFile := msg.Channel().ConfigForKey(configCredentialsFile, "")
if credentialsFile == "" {
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 17fc110

Please sign in to comment.