Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Stabilize v5 license migration fixtures

rcourtmanbb369235d1d9
diff --git a/tests/migration/licensing_server_test_helpers_test.go b/tests/migration/licensing_server_test_helpers_test.go
new file mode 100644
index 0000000000..034c909548
--- /dev/null
+++ b/tests/migration/licensing_server_test_helpers_test.go
@@ -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
+}
diff --git a/tests/migration/v5_commercial_migration_test.go b/tests/migration/v5_commercial_migration_test.go
index 9ff6d853bb..888c1c9b35 100644
--- a/tests/migration/v5_commercial_migration_test.go
+++ b/tests/migration/v5_commercial_migration_test.go
@@ -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: "[email protected]",
+ 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: "[email protected]",
})
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",
diff --git a/tests/migration/v5_full_upgrade_test.go b/tests/migration/v5_full_upgrade_test.go
index 6657b80390..81dd8a255e 100644
--- a/tests/migration/v5_full_upgrade_test.go
+++ b/tests/migration/v5_full_upgrade_test.go
@@ -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: "[email protected]",
+ 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: "[email protected]",
})
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,
diff --git a/tests/migration/v5_real_exchange_upgrade_test.go b/tests/migration/v5_real_exchange_upgrade_test.go
index 6afedda14b..54b832328b 100644
--- a/tests/migration/v5_real_exchange_upgrade_test.go
+++ b/tests/migration/v5_real_exchange_upgrade_test.go
@@ -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