-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MM-53458: Migrate to the v1 API (#108)
We use the official firebase client and move off from the legacy API. The new API uses a service account file and generates a short lived oauth2 token that gets refreshed periodically. https://mattermost.atlassian.net/browse/MM-53458
- Loading branch information
Showing
9 changed files
with
422 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAndroidInitialize(t *testing.T) { | ||
fileName := FindConfigFile("mattermost-push-proxy.sample.json") | ||
cfg, err := LoadConfig(fileName) | ||
require.NoError(t, err) | ||
|
||
logger := NewLogger(cfg) | ||
|
||
// Verify error for no service file | ||
pushSettings := AndroidPushSettings{} | ||
cfg.AndroidPushSettings[0] = pushSettings | ||
require.Error(t, NewAndroidNotificationServer(cfg.AndroidPushSettings[0], logger, nil, cfg.SendTimeoutSec).Initialize()) | ||
|
||
f, err := os.CreateTemp("", "example") | ||
require.NoError(t, err) | ||
defer os.Remove(f.Name()) // clean up | ||
|
||
cfg.AndroidPushSettings[0].ServiceFileLocation = f.Name() | ||
|
||
// Verify error for bad JSON | ||
_, err = f.Write([]byte("badJSON")) | ||
require.NoError(t, err) | ||
require.Error(t, NewAndroidNotificationServer(cfg.AndroidPushSettings[0], logger, nil, cfg.SendTimeoutSec).Initialize()) | ||
|
||
require.NoError(t, f.Truncate(0)) | ||
_, err = f.Seek(0, 0) | ||
require.NoError(t, err) | ||
|
||
// Verify no error for dummy JSON | ||
require.NoError(t, json.NewEncoder(f).Encode(serviceAccount{ | ||
Type: "service_account", | ||
ProjectID: "sample", | ||
})) | ||
require.NoError(t, f.Sync()) | ||
require.NoError(t, NewAndroidNotificationServer(cfg.AndroidPushSettings[0], logger, nil, cfg.SendTimeoutSec).Initialize()) | ||
|
||
require.NoError(t, f.Close()) | ||
} |
Oops, something went wrong.