Files
Pulse/pkg/licensing/upgrade_test.go
T
rcourtman 107c4e29f9 Make metric history free on every plan
Community installs already stored 90 days of daily metric averages and
366 days of availability history, but the chart, availability and agent
history reads refused anything past seven days, and lapsed paid installs
had history past seven days purged 60 days after a downgrade. Locking
users out of data on their own disk is the kind of limit that drew the
loudest complaints before (the monitored-system cap, SSO), and it is not
what people pay for: 12 of 88 covered paid installs read past seven days
in the last 30 days.

The history routes now serve every supported range on every plan, and
storage retention alone decides how far back the answer goes.
long_term_metrics moves into Community as a compatibility key with no
upgrade reason. TierHistoryDays, max_history_days and the downgrade
purge (DowngradeRetentionState, the metrics store commercial ceiling and
the generated-report purge) are removed, so nothing deletes history or
reports because a plan ended. The chart and drawer lock panels, the
history plan link, the billing summary row and the plan copy that sold
history go with them. Paying users lose nothing.

The public pricing pages and licence server copy in pulse-pro change
when the release carrying this ships.
2026-11-17 20:11:48 +00:00

178 lines
5.9 KiB
Go

package licensing
import (
"strings"
"testing"
)
func TestResolveProTrialSignupURL_DefaultWhenUnset(t *testing.T) {
if got := ResolveProTrialSignupURL(""); got != DefaultProTrialSignupURL {
t.Fatalf("ResolveProTrialSignupURL(\"\") = %q, want %q", got, DefaultProTrialSignupURL)
}
}
func TestResolveProTrialSignupURL_DefaultIsHostedCommercialBase(t *testing.T) {
if strings.Contains(DefaultProTrialSignupURL, "start-pro-trial") {
t.Fatalf("DefaultProTrialSignupURL=%q must not point at retired trial signup route", DefaultProTrialSignupURL)
}
}
func TestResolveProTrialSignupURL_UsesValidOverride(t *testing.T) {
const override = "https://example.com/commercial-base?src=test"
if got := ResolveProTrialSignupURL(override); got != override {
t.Fatalf("ResolveProTrialSignupURL() = %q, want %q", got, override)
}
}
func TestResolveProTrialSignupURL_AllowsLoopbackHTTPOverride(t *testing.T) {
const override = "http://127.0.0.1:8080/commercial-base?src=test"
if got := ResolveProTrialSignupURL(override); got != override {
t.Fatalf("ResolveProTrialSignupURL() = %q, want %q", got, override)
}
}
func TestResolveProTrialSignupURL_RejectsInvalidOverrides(t *testing.T) {
testCases := []string{
"relative/path",
"javascript:alert(1)",
"https://",
"http://192.168.1.20/commercial-base",
"ftp://example.com/commercial-base",
}
for _, tc := range testCases {
t.Run(tc, func(t *testing.T) {
if got := ResolveProTrialSignupURL(tc); got != DefaultProTrialSignupURL {
t.Fatalf("ResolveProTrialSignupURL() = %q, want default %q", got, DefaultProTrialSignupURL)
}
})
}
}
func TestResolvePulseAccountPortalURL_DefaultWhenUnset(t *testing.T) {
if got := ResolvePulseAccountPortalURL(""); got != DefaultPulseAccountPortalURL {
t.Fatalf("ResolvePulseAccountPortalURL(\"\") = %q, want %q", got, DefaultPulseAccountPortalURL)
}
}
// In-app Buy must land on a page that is served. Hosted Cloud was hibernated
// on 2026-06-01, so the purchase page lives on the licence server.
func TestDefaultPulseAccountPortalURL_IsLicenceServerPurchasePage(t *testing.T) {
if DefaultPulseAccountPortalURL != "https://license.pulserelay.pro/buy" {
t.Fatalf("DefaultPulseAccountPortalURL = %q, want the licence server purchase page", DefaultPulseAccountPortalURL)
}
if strings.Contains(DefaultPulseAccountPortalURL, "cloud.pulserelay.pro") {
t.Fatalf("DefaultPulseAccountPortalURL = %q must not use the hibernated Cloud host", DefaultPulseAccountPortalURL)
}
}
func TestResolvePulseAccountPortalURL_UsesValidOverride(t *testing.T) {
const override = "https://example.com/portal?src=test"
if got := ResolvePulseAccountPortalURL(override); got != override {
t.Fatalf("ResolvePulseAccountPortalURL() = %q, want %q", got, override)
}
}
func TestResolvePulseAccountPortalURL_AllowsLoopbackHTTPOverride(t *testing.T) {
const override = "http://localhost:8080/portal?src=test"
if got := ResolvePulseAccountPortalURL(override); got != override {
t.Fatalf("ResolvePulseAccountPortalURL() = %q, want %q", got, override)
}
}
func TestResolvePulseAccountPortalURL_RejectsInvalidOverrides(t *testing.T) {
testCases := []string{
"relative/path",
"javascript:alert(1)",
"https://",
"http://10.0.0.25/portal",
"ftp://example.com/portal",
}
for _, tc := range testCases {
t.Run(tc, func(t *testing.T) {
if got := ResolvePulseAccountPortalURL(tc); got != DefaultPulseAccountPortalURL {
t.Fatalf("ResolvePulseAccountPortalURL() = %q, want default %q", got, DefaultPulseAccountPortalURL)
}
})
}
}
func TestOperatorOutcomeUpgradeReasonsRemainCanonical(t *testing.T) {
expected := map[string]string{
FeatureAIAlerts: "Upgrade to Pro so Patrol can investigate issues instead of handing you a stack of symptoms.",
FeatureAIAutoFix: "Upgrade to Pro so Patrol can investigate issues, apply safe fixes within Patrol mode, and verify the result.",
FeatureExternalProbe: "Upgrade to Pro to run availability checks from an agent outside the monitored site and report the results back to Pulse for alerting.",
}
found := make(map[string]bool, len(expected))
for _, entry := range UpgradeReasonMatrix {
want, ok := expected[entry.Feature]
if !ok {
continue
}
if entry.Reason != want {
t.Fatalf("reason for %q = %q, want %q", entry.Feature, entry.Reason, want)
}
found[entry.Feature] = true
}
for feature := range expected {
if !found[feature] {
t.Errorf("missing current upgrade reason for %q", feature)
}
}
}
func TestCompatibilityOnlyFeaturesStayOutOfGenericUpgradeReasons(t *testing.T) {
reasons := GenerateUpgradeReasons(nil)
for _, entry := range reasons {
if entry.Feature == FeatureKubernetesAI {
t.Fatalf("compatibility-only feature %q should not produce a generic upgrade reason", entry.Feature)
}
}
}
func TestCompatibilityOnlyFeatureUpgradeURLsFallBackToGenericPricing(t *testing.T) {
foundCompatibilityOnlyFeature := false
for _, entry := range AllFeatureMetadata() {
if !IsCompatibilityOnlyFeature(entry.Key) {
continue
}
foundCompatibilityOnlyFeature = true
if got := UpgradeURLForFeature(entry.Key); got != DefaultUpgradeURL {
t.Fatalf("UpgradeURLForFeature(%q) = %q, want generic pricing URL %q", entry.Key, got, DefaultUpgradeURL)
}
}
if !foundCompatibilityOnlyFeature {
t.Fatal("expected at least one compatibility-only feature in metadata")
}
}
func TestUpgradeReasonMatrixDerivesFromCanonicalFeatureMetadata(t *testing.T) {
expectedOrder := []string{
FeatureAIAutoFix,
FeatureAIAlerts,
FeatureRBAC,
FeatureAgentProfiles,
FeatureExternalProbe,
FeatureAuditLogging,
FeatureAdvancedReporting,
}
if len(UpgradeReasonMatrix) != len(expectedOrder) {
t.Fatalf("UpgradeReasonMatrix length = %d, want %d", len(UpgradeReasonMatrix), len(expectedOrder))
}
for idx, feature := range expectedOrder {
if UpgradeReasonMatrix[idx].Feature != feature {
t.Fatalf("UpgradeReasonMatrix[%d].Feature = %q, want %q", idx, UpgradeReasonMatrix[idx].Feature, feature)
}
}
}