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.

test(cloudcp): prove Pulse Account page route behavior

rcourtman8ceaf5c2311e
diff --git a/internal/cloudcp/portal/templates/portal.html b/internal/cloudcp/portal/templates/portal.html
index 98b6e5be5d..320db382ad 100644
--- a/internal/cloudcp/portal/templates/portal.html
+++ b/internal/cloudcp/portal/templates/portal.html
@@ -19,7 +19,7 @@
<main class="main">
<section class="intro-card">
<h1>Pulse Account</h1>
- <p>Manage hosted Cloud and MSP workspaces here today. Self-hosted license and recovery tools still live on the public commercial surface during the current rollout, and are linked below so the account experience does not stay fragmented forever.</p>
+ <p>Manage Cloud workspaces, MSP access, and self-hosted commercial account services from one account surface. Hosted workspace lifecycle lives here today, and the self-hosted billing, license recovery, refund, and privacy tools below now share the same Pulse Account shell instead of staying fragmented across public utility pages.</p>
</section>
{{if eq (len .Accounts) 0}}
<div class="empty-state" style="margin-top:48px">
diff --git a/internal/cloudcp/routes_auth_test.go b/internal/cloudcp/routes_auth_test.go
index 89f0f3b3f4..b9ffe00ee2 100644
--- a/internal/cloudcp/routes_auth_test.go
+++ b/internal/cloudcp/routes_auth_test.go
@@ -339,3 +339,95 @@ func TestRegisterRoutes_PortalBootstrapRequiresSession(t *testing.T) {
t.Fatalf("revoked status = %d, want %d (body=%q)", revokedRec.Code, http.StatusUnauthorized, revokedRec.Body.String())
}
}
+
+func TestRegisterRoutes_PortalPageSessionModes(t *testing.T) {
+ dir := t.TempDir()
+ reg, err := registry.NewTenantRegistry(dir)
+ if err != nil {
+ t.Fatalf("NewTenantRegistry: %v", err)
+ }
+ t.Cleanup(func() { _ = reg.Close() })
+
+ accountID, err := registry.GenerateAccountID()
+ if err != nil {
+ t.Fatalf("GenerateAccountID: %v", err)
+ }
+ if err := reg.CreateAccount(&registry.Account{
+ ID: accountID,
+ Kind: registry.AccountKindMSP,
+ DisplayName: "Acme MSP",
+ }); err != nil {
+ t.Fatalf("CreateAccount: %v", err)
+ }
+
+ userID, err := registry.GenerateUserID()
+ if err != nil {
+ t.Fatalf("GenerateUserID: %v", err)
+ }
+ if err := reg.CreateUser(&registry.User{
+ ID: userID,
+ Email: "[email protected]",
+ }); err != nil {
+ t.Fatalf("CreateUser: %v", err)
+ }
+ if err := reg.CreateMembership(&registry.AccountMembership{
+ AccountID: accountID,
+ UserID: userID,
+ Role: registry.MemberRoleOwner,
+ }); err != nil {
+ t.Fatalf("CreateMembership: %v", err)
+ }
+
+ magicSvc, err := cpauth.NewService(dir)
+ if err != nil {
+ t.Fatalf("NewService: %v", err)
+ }
+ t.Cleanup(magicSvc.Close)
+
+ token, err := magicSvc.GenerateSessionToken(userID, "[email protected]", cpauth.SessionTTL)
+ if err != nil {
+ t.Fatalf("GenerateSessionToken: %v", err)
+ }
+
+ mux := http.NewServeMux()
+ RegisterRoutes(mux, &Deps{
+ Config: &CPConfig{
+ DataDir: dir,
+ AdminKey: "test-admin-key",
+ BaseURL: "https://cloud.example.com",
+ StripeWebhookSecret: "whsec_test",
+ },
+ Registry: reg,
+ MagicLinks: magicSvc,
+ Version: "test",
+ })
+
+ unauthReq := httptest.NewRequest(http.MethodGet, portal.PortalPagePath, nil)
+ unauthRec := httptest.NewRecorder()
+ mux.ServeHTTP(unauthRec, unauthReq)
+ if unauthRec.Code != http.StatusOK {
+ t.Fatalf("unauth status = %d, want %d (body=%q)", unauthRec.Code, http.StatusOK, unauthRec.Body.String())
+ }
+ if !strings.Contains(unauthRec.Body.String(), "Sign in to manage Cloud workspaces, MSP access, and commercial account services.") {
+ t.Fatalf("expected login shell in unauthenticated portal page, body=%q", unauthRec.Body.String())
+ }
+
+ authReq := httptest.NewRequest(http.MethodGet, portal.PortalPagePath, nil)
+ authReq.Header.Set("Authorization", "Bearer "+token)
+ authRec := httptest.NewRecorder()
+ mux.ServeHTTP(authRec, authReq)
+ if authRec.Code != http.StatusOK {
+ t.Fatalf("auth status = %d, want %d (body=%q)", authRec.Code, http.StatusOK, authRec.Body.String())
+ }
+ for _, needle := range []string{
+ "Pulse Account",
+ "Acme MSP",
+ `id="pulse-account-bootstrap"`,
+ "Other account services",
+ "self-hosted billing, license recovery, refund, and privacy tools below now share the same Pulse Account shell",
+ } {
+ if !strings.Contains(authRec.Body.String(), needle) {
+ t.Fatalf("expected authenticated portal page to contain %q, body=%q", needle, authRec.Body.String())
+ }
+ }
+}