π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Handle stale Play purchase tokens
Neeraj Gupta4678b6fcf7f3
diff --git a/server/pkg/controller/billing.go b/server/pkg/controller/billing.goindex a0d4e709b5..8ad2a74e95 100644--- a/server/pkg/controller/billing.go+++ b/server/pkg/controller/billing.go@@ -286,11 +286,13 @@ func (c *BillingController) VerifySubscription(func shouldSkipVerifiedSubscriptionReplacement(currentSubscription ente.Subscription, verifiedSubscription ente.Subscription, now int64) bool {effectiveExpiry := verifiedSubscription.ExpiryTime + billing.ProviderToExpiryGracePeriodMap[verifiedSubscription.PaymentProvider]+ isSameSubscription := currentSubscription.PaymentProvider == verifiedSubscription.PaymentProvider &&+ currentSubscription.ProductID == verifiedSubscription.ProductID &&+ (verifiedSubscription.PaymentProvider == ente.PlayStore ||+ currentSubscription.OriginalTransactionID == verifiedSubscription.OriginalTransactionID)return effectiveExpiry < now ||(currentSubscription.ProductID != ente.FreePlanProductID &&- currentSubscription.PaymentProvider == verifiedSubscription.PaymentProvider &&- currentSubscription.OriginalTransactionID == verifiedSubscription.OriginalTransactionID &&- currentSubscription.ProductID == verifiedSubscription.ProductID &&+ isSameSubscription &&verifiedSubscription.ExpiryTime < currentSubscription.ExpiryTime)}diff --git a/server/pkg/controller/billing_test.go b/server/pkg/controller/billing_test.goindex e11716329f..1386760c83 100644--- a/server/pkg/controller/billing_test.go+++ b/server/pkg/controller/billing_test.go@@ -42,9 +42,15 @@ func TestShouldSkipVerifiedSubscriptionReplacement(t *testing.T) {verified: paid(ente.AppStore, "apple", now-appStoreGrace+1),},{- name: "accepts active Play purchase with a new token",- current: paid(ente.PlayStore, "old-token", now+45),- verified: paid(ente.PlayStore, "new-token", now+30),+ name: "rejects older Play purchase with a different token",+ current: paid(ente.PlayStore, "new-token", now+45),+ verified: paid(ente.PlayStore, "old-token", now+30),+ want: true,+ },+ {+ name: "accepts newer Play purchase with a different token",+ current: paid(ente.PlayStore, "old-token", now+30),+ verified: paid(ente.PlayStore, "new-token", now+45),},{name: "rejects older version of the same subscription",@@ -61,6 +67,15 @@ func TestShouldSkipVerifiedSubscriptionReplacement(t *testing.T) {ProductID: "new", PaymentProvider: ente.AppStore, OriginalTransactionID: "apple", ExpiryTime: now + 30,},},+ {+ name: "accepts Play Store product change with earlier expiry",+ current: ente.Subscription{+ ProductID: "old", PaymentProvider: ente.PlayStore, OriginalTransactionID: "old-token", ExpiryTime: now + 45,+ },+ verified: ente.Subscription{+ ProductID: "new", PaymentProvider: ente.PlayStore, OriginalTransactionID: "new-token", ExpiryTime: now + 30,+ },+ },}for _, test := range tests {