mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-10 02:25:56 +00:00
Stabilize v5 license migration fixtures
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing"
|
||||
)
|
||||
|
||||
func handleMigrationInstallationStatus(w http.ResponseWriter, r *http.Request) bool {
|
||||
if r.URL.Path != "/v1/grants/status" {
|
||||
return false
|
||||
}
|
||||
if r.Method != http.MethodPost {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return true
|
||||
}
|
||||
|
||||
var req pkglicensing.InstallationStatusRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return true
|
||||
}
|
||||
licenseVersion := req.CurrentLicenseVersion
|
||||
if licenseVersion <= 0 {
|
||||
licenseVersion = 1
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(pkglicensing.InstallationStatusResponse{
|
||||
LicenseVersion: licenseVersion,
|
||||
StatusPolicy: pkglicensing.StatusHints{
|
||||
IntervalSeconds: 300,
|
||||
JitterPercent: 20,
|
||||
},
|
||||
})
|
||||
return true
|
||||
}
|
||||
@@ -128,6 +128,9 @@ func TestV5PaidLicenseUpgrade_CommercialMigrationFailureMatrix(t *testing.T) {
|
||||
require.NoError(t, persistence.Save(legacyLicense))
|
||||
|
||||
exchangeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if handleMigrationInstallationStatus(w, r) {
|
||||
return
|
||||
}
|
||||
require.Equal(t, "/v1/licenses/exchange", r.URL.Path)
|
||||
|
||||
var req pkglicensing.ExchangeLegacyLicenseRequest
|
||||
@@ -212,14 +215,15 @@ func TestV5PaidLicenseUpgrade_CommercialMigrationClearsAfterLocalRetry(t *testin
|
||||
require.NoError(t, persistence.Save(legacyLicense))
|
||||
|
||||
grantJWT, grantPublicKey, err := pkglicensing.GenerateGrantJWTForTesting(pkglicensing.GrantClaims{
|
||||
LicenseID: "lic_v5_retry_migrated",
|
||||
Tier: string(pkglicensing.TierPro),
|
||||
PlanKey: "v5_pro_monthly_grandfathered",
|
||||
State: "active",
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierPro]...),
|
||||
IssuedAt: time.Now().Unix(),
|
||||
ExpiresAt: time.Now().Add(72 * time.Hour).Unix(),
|
||||
Email: "legacy-retry@example.com",
|
||||
LicenseID: "lic_v5_retry_migrated",
|
||||
LicenseVersion: 1,
|
||||
Tier: string(pkglicensing.TierPro),
|
||||
PlanKey: "v5_pro_monthly_grandfathered",
|
||||
State: "active",
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierPro]...),
|
||||
IssuedAt: time.Now().Unix(),
|
||||
ExpiresAt: time.Now().Add(72 * time.Hour).Unix(),
|
||||
Email: "legacy-retry@example.com",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
pkglicensing.SetPublicKey(grantPublicKey)
|
||||
@@ -227,6 +231,9 @@ func TestV5PaidLicenseUpgrade_CommercialMigrationClearsAfterLocalRetry(t *testin
|
||||
|
||||
var exchangeAvailable atomic.Bool
|
||||
exchangeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if handleMigrationInstallationStatus(w, r) {
|
||||
return
|
||||
}
|
||||
require.Equal(t, "/v1/licenses/exchange", r.URL.Path)
|
||||
|
||||
var req pkglicensing.ExchangeLegacyLicenseRequest
|
||||
@@ -246,10 +253,11 @@ func TestV5PaidLicenseUpgrade_CommercialMigrationClearsAfterLocalRetry(t *testin
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
require.NoError(t, json.NewEncoder(w).Encode(pkglicensing.ActivateInstallationResponse{
|
||||
License: pkglicensing.ActivateResponseLicense{
|
||||
LicenseID: "lic_v5_retry_migrated",
|
||||
State: "active",
|
||||
Tier: string(pkglicensing.TierPro),
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierPro]...),
|
||||
LicenseID: "lic_v5_retry_migrated",
|
||||
LicenseVersion: 1,
|
||||
State: "active",
|
||||
Tier: string(pkglicensing.TierPro),
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierPro]...),
|
||||
},
|
||||
Installation: pkglicensing.ActivateResponseInstallation{
|
||||
InstallationID: "inst_v5_retry_migrated",
|
||||
|
||||
@@ -450,20 +450,24 @@ func TestV5FullUpgradeScenario(t *testing.T) {
|
||||
require.NoError(t, persistence.Save(legacyLicense))
|
||||
|
||||
grantJWT, grantPublicKey, err := pkglicensing.GenerateGrantJWTForTesting(pkglicensing.GrantClaims{
|
||||
LicenseID: "lic_v5_migrated",
|
||||
Tier: string(pkglicensing.TierLifetime),
|
||||
PlanKey: "v5_lifetime_grandfathered",
|
||||
State: "active",
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierLifetime]...),
|
||||
IssuedAt: time.Now().Unix(),
|
||||
ExpiresAt: time.Now().Add(72 * time.Hour).Unix(),
|
||||
Email: "legacy-lifetime@example.com",
|
||||
LicenseID: "lic_v5_migrated",
|
||||
LicenseVersion: 1,
|
||||
Tier: string(pkglicensing.TierLifetime),
|
||||
PlanKey: "v5_lifetime_grandfathered",
|
||||
State: "active",
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierLifetime]...),
|
||||
IssuedAt: time.Now().Unix(),
|
||||
ExpiresAt: time.Now().Add(72 * time.Hour).Unix(),
|
||||
Email: "legacy-lifetime@example.com",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
pkglicensing.SetPublicKey(grantPublicKey)
|
||||
t.Cleanup(func() { pkglicensing.SetPublicKey(nil) })
|
||||
|
||||
exchangeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if handleMigrationInstallationStatus(w, r) {
|
||||
return
|
||||
}
|
||||
require.Equal(t, "/v1/licenses/exchange", r.URL.Path)
|
||||
|
||||
var req pkglicensing.ExchangeLegacyLicenseRequest
|
||||
@@ -473,10 +477,11 @@ func TestV5FullUpgradeScenario(t *testing.T) {
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
require.NoError(t, json.NewEncoder(w).Encode(pkglicensing.ActivateInstallationResponse{
|
||||
License: pkglicensing.ActivateResponseLicense{
|
||||
LicenseID: "lic_v5_migrated",
|
||||
State: "active",
|
||||
Tier: string(pkglicensing.TierLifetime),
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierLifetime]...),
|
||||
LicenseID: "lic_v5_migrated",
|
||||
LicenseVersion: 1,
|
||||
State: "active",
|
||||
Tier: string(pkglicensing.TierLifetime),
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierLifetime]...),
|
||||
},
|
||||
Installation: pkglicensing.ActivateResponseInstallation{
|
||||
InstallationID: "inst_v5_migrated",
|
||||
@@ -587,20 +592,24 @@ func TestV5FullUpgradeScenario(t *testing.T) {
|
||||
require.NoError(t, persistence.Save(legacyLicense))
|
||||
|
||||
grantJWT, grantPublicKey, err := pkglicensing.GenerateGrantJWTForTesting(pkglicensing.GrantClaims{
|
||||
LicenseID: tc.licenseID,
|
||||
Tier: string(pkglicensing.TierPro),
|
||||
PlanKey: tc.planKey,
|
||||
State: "active",
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierPro]...),
|
||||
IssuedAt: time.Now().Unix(),
|
||||
ExpiresAt: time.Now().Add(72 * time.Hour).Unix(),
|
||||
Email: tc.email,
|
||||
LicenseID: tc.licenseID,
|
||||
LicenseVersion: 1,
|
||||
Tier: string(pkglicensing.TierPro),
|
||||
PlanKey: tc.planKey,
|
||||
State: "active",
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierPro]...),
|
||||
IssuedAt: time.Now().Unix(),
|
||||
ExpiresAt: time.Now().Add(72 * time.Hour).Unix(),
|
||||
Email: tc.email,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
pkglicensing.SetPublicKey(grantPublicKey)
|
||||
t.Cleanup(func() { pkglicensing.SetPublicKey(nil) })
|
||||
|
||||
exchangeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if handleMigrationInstallationStatus(w, r) {
|
||||
return
|
||||
}
|
||||
require.Equal(t, "/v1/licenses/exchange", r.URL.Path)
|
||||
|
||||
var req pkglicensing.ExchangeLegacyLicenseRequest
|
||||
@@ -610,10 +619,11 @@ func TestV5FullUpgradeScenario(t *testing.T) {
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
require.NoError(t, json.NewEncoder(w).Encode(pkglicensing.ActivateInstallationResponse{
|
||||
License: pkglicensing.ActivateResponseLicense{
|
||||
LicenseID: tc.licenseID,
|
||||
State: "active",
|
||||
Tier: string(pkglicensing.TierPro),
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierPro]...),
|
||||
LicenseID: tc.licenseID,
|
||||
LicenseVersion: 1,
|
||||
State: "active",
|
||||
Tier: string(pkglicensing.TierPro),
|
||||
Features: append([]string(nil), pkglicensing.TierFeatures[pkglicensing.TierPro]...),
|
||||
},
|
||||
Installation: pkglicensing.ActivateResponseInstallation{
|
||||
InstallationID: tc.installID,
|
||||
|
||||
@@ -317,6 +317,7 @@ func startManagedLicenseServer(
|
||||
"PULSE_LICENSE_PLANS="+plansJSON,
|
||||
"PULSE_LICENSE_STRIPE_IPS_FILE="+stripeIPsPath,
|
||||
"PULSE_LICENSE_STRIPE_IPS_ENFORCE=true",
|
||||
"PULSE_LICENSE_RELAY_FEED_TOKEN=test-relay-feed-token",
|
||||
"PULSE_LICENSE_V6_ENABLED=true",
|
||||
)
|
||||
cmd.Stdout = logBuf
|
||||
|
||||
Reference in New Issue
Block a user