π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Limit album-share pushes to internal Android devices
AmanRajSinghMourya4f4f3534c4f7
diff --git a/server/ente/push.go b/server/ente/push.goindex 5f37e022d1..4dba725249 100644--- a/server/ente/push.go+++ b/server/ente/push.go@@ -6,25 +6,17 @@ import ()type PushTokenRequest struct {- FCMToken string `json:"fcmToken" binding:"required"`- APNSToken string `json:"apnsToken"`- Platform *string `json:"platform" binding:"required,oneof=ios android"`- Notification *PushNotificationRegistration `json:"notification"`+ FCMToken string `json:"fcmToken" binding:"required"`+ APNSToken string `json:"apnsToken"`+ Platform *string `json:"platform" binding:"required,oneof=ios android"`LastNotificationTime int64}-type PushNotificationRegistration struct {- Version int `json:"version" binding:"required,eq=1"`- PublicKey []byte `json:"publicKey" binding:"required,len=32"`-}-type PushToken struct {- Platform string `json:"-"`- UserID int64 `json:"userID"`- FCMToken string `json:"fcmToken"`- CreatedAt int64 `json:"createdAt"`- LastNotifiedAt int64 `json:"lastNotifiedAt"`- NotificationPublicKey []byte `json:"-"`+ UserID int64 `json:"userID"`+ FCMToken string `json:"fcmToken"`+ CreatedAt int64 `json:"createdAt"`+ LastNotifiedAt int64 `json:"lastNotifiedAt"`}func (pt *PushToken) MarshalJSON() ([]byte, error) {diff --git a/server/migrations/150_push_notification_registration.down.sql b/server/migrations/150_push_notification_registration.down.sqlindex 5f58086181..e832f533eb 100644--- a/server/migrations/150_push_notification_registration.down.sql+++ b/server/migrations/150_push_notification_registration.down.sql@@ -1,3 +1,2 @@ALTER TABLE push_tokens- DROP COLUMN notification_public_key,DROP COLUMN platform;diff --git a/server/migrations/150_push_notification_registration.up.sql b/server/migrations/150_push_notification_registration.up.sqlindex e8bc28b6a1..c8ea8179ac 100644--- a/server/migrations/150_push_notification_registration.up.sql+++ b/server/migrations/150_push_notification_registration.up.sql@@ -1,3 +1,2 @@ALTER TABLE push_tokens- ADD COLUMN platform TEXT NOT NULL DEFAULT 'ios' CHECK (platform IN ('ios', 'android')),- ADD COLUMN notification_public_key BYTEA CHECK (octet_length(notification_public_key) = 32);+ ADD COLUMN platform TEXT NOT NULL DEFAULT 'ios' CHECK (platform IN ('ios', 'android'));diff --git a/server/pkg/api/push_test.go b/server/pkg/api/push_test.goindex 0ac2f2eca8..cc1264baad 100644--- a/server/pkg/api/push_test.go+++ b/server/pkg/api/push_test.go@@ -1,9 +1,7 @@package apiimport (- "crypto/rand""encoding/base64"- "encoding/json""fmt""net/http""net/http/httptest"@@ -17,7 +15,6 @@ import ("github.com/ente/museum/pkg/utils/auth""github.com/gin-gonic/gin""github.com/stretchr/testify/require"- "golang.org/x/crypto/nacl/box")func TestPushRegistrationBindsRequestSession(t *testing.T) {@@ -67,7 +64,7 @@ func TestPushRegistrationBindsRequestSession(t *testing.T) {require.Equal(t, expected[:], hash)}-func TestPushRegistrationRejectsInvalidNotificationEnrollment(t *testing.T) {+func TestPushPlatformRegistration(t *testing.T) {testutil.WithServerRoot(t)db := testutil.RequireTestDB(t)testutil.ResetTables(t, db)@@ -77,98 +74,27 @@ func TestPushRegistrationRejectsInvalidNotificationEnrollment(t *testing.T) {router := gin.New()handler := PushHandler{PushController: &controller.PushController{PushRepo: &repo.PushTokenRepository{DB: db}}}router.POST("/push/token", handler.AddToken)- key := base64.StdEncoding.EncodeToString(append([]byte{9}, make([]byte, 31)...))- for _, fields := range []string{- `"platform":"web"`,- `"platform":null`,- `"notification":{}`,- fmt.Sprintf(`"notification":{"version":2,"publicKey":"%s"}`, key),- `"notification":{"version":1,"publicKey":"invalid"}`,- `"notification":{"version":1,"publicKey":"AQ=="}`,- fmt.Sprintf(`"notification":{"version":1,"publicKey":"%s"}`, base64.StdEncoding.EncodeToString(make([]byte, 32))),- fmt.Sprintf(`"platform":"android","notification":{"version":1,"publicKey":"%s"}`, key),- } {- t.Run(fields, func(t *testing.T) {- request := httptest.NewRequest(http.MethodPost, "/push/token", strings.NewReader(`{"fcmToken":"device",`+fields+`}`))- request.Header.Set("Content-Type", "application/json")- request.Header.Set("X-Auth-User-ID", "1")- request.Header.Set("X-Auth-Token", "session")- response := httptest.NewRecorder()- router.ServeHTTP(response, request)- require.Equal(t, http.StatusBadRequest, response.Code, response.Body.String())- })- }- var count int- require.NoError(t, db.QueryRow(`SELECT count(*) FROM push_tokens`).Scan(&count))- require.Zero(t, count)-}--func TestPushNotificationRegistrationLifecycle(t *testing.T) {- testutil.WithServerRoot(t)- db := testutil.RequireTestDB(t)- testutil.ResetTables(t, db)- t.Cleanup(func() { testutil.ResetTables(t, db) })- authRepo := &repo.UserAuthRepository{DB: db}- for _, id := range []int64{1, 2} {- testutil.InsertUser(t, db, testutil.UserFixture{UserID: id, Email: fmt.Sprintf("user%[email protected]", id), CreationTime: 1})- require.NoError(t, authRepo.AddToken(id, ente.Photos, fmt.Sprintf("session-%d", id), "", ""))- }- firstKey, _, err := box.GenerateKey(rand.Reader)- require.NoError(t, err)- secondKey, _, err := box.GenerateKey(rand.Reader)- require.NoError(t, err)- router := gin.New()- handler := PushHandler{PushController: &controller.PushController{PushRepo: &repo.PushTokenRepository{DB: db}}}- router.POST("/push/token", handler.AddToken)for _, tc := range []struct {- name string- userID int64- platform string- key []byte- omit bool+ name, fields, platform string+ status int}{- {"old client", 1, "", nil, true},- {"enroll", 1, "ios", firstKey[:], false},- {"replace key", 1, "ios", secondKey[:], false},- {"unenroll", 1, "ios", nil, false},- {"enroll again", 1, "ios", firstKey[:], false},- {"switch account", 2, "ios", secondKey[:], false},- {"omitted enrollment clears key", 2, "android", nil, true},+ {"old client", "", "ios", http.StatusOK},+ {"android", `,"platform":"android","apnsToken":null`, "android", http.StatusOK},+ {"ios", `,"platform":"ios"`, "ios", http.StatusOK},+ {"invalid platform", `,"platform":"web"`, "ios", http.StatusBadRequest},+ {"null platform", `,"platform":null`, "ios", http.StatusBadRequest},} {t.Run(tc.name, func(t *testing.T) {- body := map[string]any{"fcmToken": "device", "apnsToken": "apns"}- if tc.platform != "" {- body["platform"] = tc.platform- }- if !tc.omit {- body["notification"] = nil- if tc.key != nil {- body["notification"] = map[string]any{"version": 1, "publicKey": tc.key}- }- }- encoded, err := json.Marshal(body)- require.NoError(t, err)- request := httptest.NewRequest(http.MethodPost, "/push/token", strings.NewReader(string(encoded)))+ request := httptest.NewRequest(http.MethodPost, "/push/token", strings.NewReader(`{"fcmToken":"device"`+tc.fields+`}`))request.Header.Set("Content-Type", "application/json")- request.Header.Set("X-Auth-User-ID", fmt.Sprint(tc.userID))- session := fmt.Sprintf("session-%d", tc.userID)- request.Header.Set("X-Auth-Token", session)+ request.Header.Set("X-Auth-User-ID", "1")+ request.Header.Set("X-Auth-Token", "session")response := httptest.NewRecorder()router.ServeHTTP(response, request)- require.Equal(t, http.StatusOK, response.Code, response.Body.String())- var userID int64+ require.Equal(t, tc.status, response.Code, response.Body.String())var platform string- var key, hash []byte- require.NoError(t, db.QueryRow(`SELECT user_id, platform, notification_public_key, session_token_hash FROM push_tokens WHERE fcm_token='device'`).Scan(&userID, &platform, &key, &hash))- require.Equal(t, tc.userID, userID)- wantPlatform := tc.platform- if wantPlatform == "" {- wantPlatform = "ios"- }- require.Equal(t, wantPlatform, platform)- require.Equal(t, tc.key, key)- expected := auth.HashToken(session)- require.Equal(t, expected[:], hash)+ require.NoError(t, db.QueryRow(`SELECT platform FROM push_tokens WHERE fcm_token='device'`).Scan(&platform))+ require.Equal(t, tc.platform, platform)})}}diff --git a/server/pkg/controller/push.go b/server/pkg/controller/push.goindex a8de788ce9..1b7fbbfc6c 100644--- a/server/pkg/controller/push.go+++ b/server/pkg/controller/push.go@@ -3,8 +3,6 @@ package controllerimport ("bytes""context"- "crypto/rand"- "encoding/base64""encoding/json""errors""fmt"@@ -19,12 +17,10 @@ import ("github.com/ente/museum/ente""github.com/ente/museum/pkg/repo""github.com/ente/museum/pkg/utils/config"- "github.com/ente/museum/pkg/utils/crypto""github.com/ente/museum/pkg/utils/time""github.com/ente/stacktrace"log "github.com/sirupsen/logrus""github.com/spf13/viper"- "golang.org/x/crypto/nacl/box""golang.org/x/oauth2""golang.org/x/oauth2/google")@@ -104,14 +100,6 @@ func newFCMClient() (*fcmClient, error) {}func (c *PushController) AddToken(userID int64, sessionTokenHash []byte, token ente.PushTokenRequest) error {- if token.Notification != nil {- if *token.Platform != "ios" {- return ente.NewBadRequestWithMessage("notification enrollment is only supported on iOS")- }- if err := crypto.ValidateSealedBoxPublicKey(base64.StdEncoding.EncodeToString(token.Notification.PublicKey)); err != nil {- return ente.NewBadRequestWithMessage("invalid notification public key")- }- }return stacktrace.Propagate(c.PushRepo.AddToken(userID, sessionTokenHash, token), "")}@@ -129,34 +117,11 @@ func (c *PushController) NotifyAlbumShare(ctx context.Context, recipients []int6}var unregisteredTokens []stringfor _, token := range tokens {- message := map[string]any{"token": token.FCMToken}- if token.Platform == "android" {- message["data"] = map[string]string{"action": "sync"}- message["android"] = map[string]string{"priority": "high", "ttl": "86400s"}- } else {- ciphertext, err := box.SealAnonymous(nil, []byte(`{"version":1,"eventType":"album_shared"}`), (*[32]byte)(token.NotificationPublicKey), rand.Reader)- if err != nil {- log.WithError(err).Warn("album share notification encryption failed")- continue- }- message["apns"] = map[string]any{- "headers": map[string]string{- "apns-push-type": "alert",- "apns-priority": "10",- "apns-expiration": strconv.FormatInt(gotime.Now().Add(24*gotime.Hour).Unix(), 10),- },- "payload": map[string]any{- "aps": map[string]any{- "alert": map[string]string{"title": "Ente Photos", "body": "New activity"},- "mutable-content": 1,- "sound": "default",- },- "notificationVersion": 1,- "notificationCiphertext": base64.StdEncoding.EncodeToString(ciphertext),- },- }- }- err = c.fcm.sendMessage(ctx, message)+ err = c.fcm.sendMessage(ctx, map[string]any{+ "token": token.FCMToken,+ "data": map[string]string{"action": "sync"},+ "android": map[string]string{"priority": "high", "ttl": "86400s"},+ })if err != nil {log.WithError(err).Warn("album share push failed; album remains shared")if errors.Is(err, errUnregisteredToken) {diff --git a/server/pkg/controller/push_test.go b/server/pkg/controller/push_test.goindex e1b8991aef..37a9bd167b 100644--- a/server/pkg/controller/push_test.go+++ b/server/pkg/controller/push_test.go@@ -2,17 +2,13 @@ package controllerimport ("context"- "crypto/rand"- "encoding/base64""encoding/json""errors""io""net/http"- "strconv""strings""sync/atomic""testing"- "time""github.com/ente/museum/ente""github.com/ente/museum/internal/testutil"@@ -22,7 +18,6 @@ import (logtest "github.com/sirupsen/logrus/hooks/test""github.com/spf13/viper""github.com/stretchr/testify/require"- "golang.org/x/crypto/nacl/box")type roundTripFunc func(*http.Request) (*http.Response, error)@@ -168,7 +163,7 @@ func TestFCMSendDoesNotClassifyInvalidArgumentAsUnregistered(t *testing.T) {require.False(t, errors.Is(err, errUnregisteredToken))}-func TestAlbumShareSendsPlatformPayloads(t *testing.T) {+func TestAlbumShareSendsOnlyAndroidSync(t *testing.T) {testutil.WithServerRoot(t)db := testutil.RequireTestDB(t)testutil.ResetTables(t, db)@@ -178,20 +173,12 @@ func TestAlbumShareSendsPlatformPayloads(t *testing.T) {require.NoError(t, err)require.NoError(t, (&repo.UserAuthRepository{DB: db}).AddToken(1, ente.Photos, "session", "", ""))hash := auth.HashToken("session")- platform := "ios"controller := &PushController{PushRepo: &repo.PushTokenRepository{DB: db}}- keys := make(map[string][2]*[32]byte)- for _, device := range []string{"first-device", "second-device"} {- publicKey, privateKey, err := box.GenerateKey(rand.Reader)- require.NoError(t, err)- keys[device] = [2]*[32]byte{publicKey, privateKey}+ for _, platform := range []string{"ios", "android"} {require.NoError(t, controller.AddToken(1, hash[:], ente.PushTokenRequest{- FCMToken: device, APNSToken: "apns", Platform: &platform,- Notification: &ente.PushNotificationRegistration{Version: 1, PublicKey: publicKey[:]},+ FCMToken: platform + "-device", Platform: &platform,}))}- platform = "android"- require.NoError(t, controller.AddToken(1, hash[:], ente.PushTokenRequest{FCMToken: "android-device", Platform: &platform}))var messages []map[string]anycontroller.fcm = &fcmClient{projectID: "test-project", httpClient: &http.Client{Transport: roundTripFunc(func(request *http.Request) (*http.Response, error) {require.NoError(t, request.Context().Err())@@ -204,44 +191,12 @@ func TestAlbumShareSendsPlatformPayloads(t *testing.T) {})}}ctx, cancel := context.WithCancel(context.Background())cancel()- before := time.Now().Add(24 * time.Hour).Unix()controller.NotifyAlbumShare(ctx, []int64{1})- require.Len(t, messages, 3)- for _, message := range messages {- if message["token"] == "android-device" {- require.Equal(t, map[string]any{- "token": "android-device",- "data": map[string]any{"action": "sync"},- "android": map[string]any{"priority": "high", "ttl": "86400s"},- }, message)- continue- }- require.Len(t, message, 2)- device := message["token"].(string)- apns := message["apns"].(map[string]any)- headers := apns["headers"].(map[string]any)- require.Equal(t, "alert", headers["apns-push-type"])- require.Equal(t, "10", headers["apns-priority"])- expires, err := strconv.ParseInt(headers["apns-expiration"].(string), 10, 64)- require.NoError(t, err)- require.GreaterOrEqual(t, expires, before)- require.LessOrEqual(t, expires, time.Now().Add(24*time.Hour).Unix())- payload := apns["payload"].(map[string]any)- require.Len(t, payload, 3)- require.EqualValues(t, 1, payload["notificationVersion"])- aps := payload["aps"].(map[string]any)- require.EqualValues(t, 1, aps["mutable-content"])- require.Equal(t, map[string]any{"title": "Ente Photos", "body": "New activity"}, aps["alert"])- ciphertext, err := base64.StdEncoding.DecodeString(payload["notificationCiphertext"].(string))- require.NoError(t, err)- plaintext, ok := box.OpenAnonymous(nil, ciphertext, keys[device][0], keys[device][1])- require.True(t, ok)- require.JSONEq(t, `{"version":1,"eventType":"album_shared"}`, string(plaintext))- encoded, err := json.Marshal(message)- require.NoError(t, err)- require.NotContains(t, string(encoded), "album_shared")- require.NotContains(t, string(encoded), "[email protected]")- }+ require.Equal(t, []map[string]any{{+ "token": "android-device",+ "data": map[string]any{"action": "sync"},+ "android": map[string]any{"priority": "high", "ttl": "86400s"},+ }}, messages)}func TestAlbumSharePrunesOnlyUnregisteredTokens(t *testing.T) {@@ -254,9 +209,7 @@ func TestAlbumSharePrunesOnlyUnregisteredTokens(t *testing.T) {require.NoError(t, err)require.NoError(t, (&repo.UserAuthRepository{DB: db}).AddToken(1, ente.Photos, "session", "", ""))hash := auth.HashToken("session")- platform := "ios"- publicKey, _, err := box.GenerateKey(rand.Reader)- require.NoError(t, err)+ platform := "android"controller := &PushController{PushRepo: &repo.PushTokenRepository{DB: db}}responses := map[string]struct {status int@@ -271,7 +224,6 @@ func TestAlbumSharePrunesOnlyUnregisteredTokens(t *testing.T) {for token := range responses {require.NoError(t, controller.AddToken(1, hash[:], ente.PushTokenRequest{FCMToken: token, Platform: &platform,- Notification: &ente.PushNotificationRegistration{Version: 1, PublicKey: publicKey[:]},}))}var attempted []stringdiff --git a/server/pkg/repo/push.go b/server/pkg/repo/push.goindex 8b03e5709e..7a4e54ee44 100644--- a/server/pkg/repo/push.go+++ b/server/pkg/repo/push.go@@ -15,17 +15,13 @@ type PushTokenRepository struct {}func (repo *PushTokenRepository) AddToken(userID int64, sessionTokenHash []byte, token ente.PushTokenRequest) error {- var publicKey any- if token.Notification != nil {- publicKey = token.Notification.PublicKey- }- result, err := repo.DB.Exec(`INSERT INTO push_tokens(user_id, fcm_token, apns_token, session_token_hash, platform, notification_public_key)- SELECT user_id, $2, $3, token_hash, $5, $6 FROM tokens+ result, err := repo.DB.Exec(`INSERT INTO push_tokens(user_id, fcm_token, apns_token, session_token_hash, platform)+ SELECT user_id, $2, $3, token_hash, $5 FROM tokensWHERE user_id = $1 AND token_hash = $4 AND is_deleted = false FOR SHAREON CONFLICT (fcm_token) DO UPDATESET user_id = EXCLUDED.user_id, apns_token = EXCLUDED.apns_token, session_token_hash = EXCLUDED.session_token_hash,- platform = EXCLUDED.platform, notification_public_key = EXCLUDED.notification_public_key`,- userID, token.FCMToken, token.APNSToken, sessionTokenHash, token.Platform, publicKey)+ platform = EXCLUDED.platform`,+ userID, token.FCMToken, token.APNSToken, sessionTokenHash, token.Platform)if err != nil {return stacktrace.Propagate(err, "")}@@ -63,11 +59,10 @@ func (repo *PushTokenRepository) GetTokensToBeNotified(lastNotificationTime int6}func (repo *PushTokenRepository) GetTokensForAlbumShare(ctx context.Context, userIDs []int64) ([]ente.PushToken, error) {- rows, err := repo.DB.QueryContext(ctx, `SELECT p.fcm_token, p.platform, p.notification_public_key FROM push_tokens p+ rows, err := repo.DB.QueryContext(ctx, `SELECT p.fcm_token FROM push_tokens pJOIN tokens t ON t.token_hash = p.session_token_hash AND t.user_id = p.user_id AND t.is_deleted = false AND t.app = $3JOIN remote_store r ON r.user_id = p.user_id AND r.key_name = $2 AND r.key_value = 'true'- WHERE p.user_id = ANY($1)- AND (p.platform = 'android' OR (p.platform = 'ios' AND p.notification_public_key IS NOT NULL))`,+ WHERE p.user_id = ANY($1) AND p.platform = 'android'`,pq.Array(userIDs), string(ente.IsInternalUser), string(ente.Photos))if err != nil {return nil, stacktrace.Propagate(err, "")@@ -76,7 +71,7 @@ func (repo *PushTokenRepository) GetTokensForAlbumShare(ctx context.Context, usevar tokens []ente.PushTokenfor rows.Next() {var token ente.PushToken- if err := rows.Scan(&token.FCMToken, &token.Platform, &token.NotificationPublicKey); err != nil {+ if err := rows.Scan(&token.FCMToken); err != nil {return nil, stacktrace.Propagate(err, "")}tokens = append(tokens, token)diff --git a/server/pkg/repo/push_test.go b/server/pkg/repo/push_test.goindex 40ba3f5b6e..09b4245bba 100644--- a/server/pkg/repo/push_test.go+++ b/server/pkg/repo/push_test.go@@ -154,7 +154,7 @@ func TestPushRegistrationWaitsForSessionRevocation(t *testing.T) {require.Zero(t, count)}-func TestPushNotificationRegistrationMigration(t *testing.T) {+func TestPushPlatformRegistrationMigration(t *testing.T) {testutil.WithServerRoot(t)db := testutil.RequireTestDB(t)tx, err := db.Begin()@@ -170,7 +170,7 @@ func TestPushNotificationRegistrationMigration(t *testing.T) {_, err = tx.Exec(`INSERT INTO push_tokens (fcm_token) VALUES ('old-server')`)require.NoError(t, err)var count int- require.NoError(t, tx.QueryRow(`SELECT count(*) FROM push_tokens WHERE platform='ios' AND notification_public_key IS NULL`).Scan(&count))+ require.NoError(t, tx.QueryRow(`SELECT count(*) FROM push_tokens WHERE platform='ios'`).Scan(&count))require.Equal(t, 2, count)down, err := os.ReadFile("migrations/150_push_notification_registration.down.sql")require.NoError(t, err)@@ -185,27 +185,19 @@ func TestAlbumShareTokensRequireInternalAndActiveSession(t *testing.T) {db := testutil.RequireTestDB(t)testutil.ResetTables(t, db)t.Cleanup(func() { testutil.ResetTables(t, db) })- key := append([]byte{9}, make([]byte, 31)...)var userIDs []int64for id, tc := range []struct {name, platform, flag, session stringapp ente.App- key []byte}{- {"eligible", "ios", "true", "active", ente.Photos, key},- {"android", "android", "true", "active", ente.Photos, nil},- {"non-internal", "ios", "false", "active", ente.Photos, key},- {"missing flag", "ios", "", "active", ente.Photos, key},- {"unenrolled", "ios", "true", "active", ente.Photos, nil},- {"legacy", "ios", "true", "missing", ente.Photos, key},- {"revoked", "ios", "true", "revoked", ente.Photos, key},- {"wrong owner", "ios", "true", "wrong owner", ente.Photos, key},- {"other app", "ios", "true", "active", ente.Locker, key},- {"android non-internal", "android", "false", "active", ente.Photos, nil},- {"android legacy", "android", "true", "missing", ente.Photos, nil},- {"android revoked", "android", "true", "revoked", ente.Photos, nil},- {"android wrong owner", "android", "true", "wrong owner", ente.Photos, nil},- {"android other app", "android", "true", "active", ente.Locker, nil},+ {"eligible", "android", "true", "active", ente.Photos},+ {"ios", "ios", "true", "active", ente.Photos},+ {"non-internal", "android", "false", "active", ente.Photos},+ {"missing flag", "android", "", "active", ente.Photos},+ {"legacy", "android", "true", "missing", ente.Photos},+ {"revoked", "android", "true", "revoked", ente.Photos},+ {"wrong owner", "android", "true", "wrong owner", ente.Photos},+ {"other app", "android", "true", "active", ente.Locker},} {userID := int64(id + 1)userIDs = append(userIDs, userID)@@ -224,12 +216,8 @@ func TestAlbumShareTokensRequireInternalAndActiveSession(t *testing.T) {hash = sha256.Sum256([]byte("eligible"))sessionHash = hash[:]}- var publicKey any- if tc.key != nil {- publicKey = tc.key- }- _, err := db.Exec(`INSERT INTO push_tokens(user_id,fcm_token,apns_token,platform,notification_public_key,session_token_hash,last_notified_at)- VALUES($1,$2,'apns',$3,$4,$5,0)`, userID, tc.name, tc.platform, publicKey, sessionHash)+ _, err := db.Exec(`INSERT INTO push_tokens(user_id,fcm_token,apns_token,platform,session_token_hash,last_notified_at)+ VALUES($1,$2,'apns',$3,$4,0)`, userID, tc.name, tc.platform, sessionHash)require.NoError(t, err)if tc.flag != "" {_, err = db.Exec(`INSERT INTO remote_store(user_id,key_name,key_value) VALUES($1,'internalUser',$2)`, userID, tc.flag)@@ -243,7 +231,7 @@ func TestAlbumShareTokensRequireInternalAndActiveSession(t *testing.T) {for _, token := range tokens {selected = append(selected, token.FCMToken)}- require.ElementsMatch(t, []string{"eligible", "android"}, selected)+ require.Equal(t, []string{"eligible"}, selected)for _, apnsToken := range []any{"", nil} {_, err := db.Exec(`UPDATE push_tokens SET apns_token=$1 WHERE fcm_token='eligible'`, apnsToken)require.NoError(t, err)@@ -251,18 +239,11 @@ func TestAlbumShareTokensRequireInternalAndActiveSession(t *testing.T) {require.NoError(t, err)require.Len(t, tokens, 1)require.Equal(t, "eligible", tokens[0].FCMToken)- require.Equal(t, key, tokens[0].NotificationPublicKey)}- tokens, err = r.GetTokensForAlbumShare(context.Background(), []int64{2})- require.NoError(t, err)- require.Len(t, tokens, 1)- require.Equal(t, "android", tokens[0].FCMToken)- require.Empty(t, tokens[0].NotificationPublicKey)tokens, err = r.GetTokensToBeNotified(1, 100)require.NoError(t, err)- for _, token := range tokens {- require.NotEqual(t, "android", token.FCMToken)- }+ require.Len(t, tokens, 1)+ require.Equal(t, "ios", tokens[0].FCMToken)_, err = db.Exec(`UPDATE remote_store SET key_value='false' WHERE user_id=1`)require.NoError(t, err)tokens, err = r.GetTokensForAlbumShare(context.Background(), []int64{1})