mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-15 16:42:15 +00:00
160 lines
3.7 KiB
Go
160 lines
3.7 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/registry"
|
|
)
|
|
|
|
func TestLooksLikeMobileProofAccount(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
account *registry.Account
|
|
want bool
|
|
}{
|
|
{
|
|
name: "nil",
|
|
account: nil,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "explicit proof display",
|
|
account: ®istry.Account{
|
|
ID: "a_live",
|
|
DisplayName: "Pulse Mobile Proof",
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "synthetic msp proof id",
|
|
account: ®istry.Account{
|
|
ID: "a_msp_prod_fix_20260313111348",
|
|
DisplayName: "Pulse",
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "customer-shaped account",
|
|
account: ®istry.Account{
|
|
ID: "a_W3PT2W0YFR",
|
|
DisplayName: "Customer Account",
|
|
},
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := looksLikeMobileProofAccount(tt.account); got != tt.want {
|
|
t.Fatalf("looksLikeMobileProofAccount() = %t, want %t", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLooksLikeMobileProofTenant(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
tenant *registry.Tenant
|
|
account *registry.Account
|
|
want bool
|
|
}{
|
|
{
|
|
name: "nil",
|
|
tenant: nil,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "proof display",
|
|
tenant: ®istry.Tenant{
|
|
ID: "t-123",
|
|
DisplayName: "Pulse Mobile GA Proof",
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "proof account fallback",
|
|
tenant: ®istry.Tenant{
|
|
ID: "t-123",
|
|
AccountID: "a_msp_prod_fix_20260313111348",
|
|
},
|
|
account: ®istry.Account{
|
|
ID: "a_msp_prod_fix_20260313111348",
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "customer tenant",
|
|
tenant: ®istry.Tenant{
|
|
ID: "t-123",
|
|
AccountID: "a_customer",
|
|
DisplayName: "Customer Workspace",
|
|
},
|
|
account: ®istry.Account{
|
|
ID: "a_customer",
|
|
DisplayName: "Customer Account",
|
|
},
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := looksLikeMobileProofTenant(tt.tenant, tt.account); got != tt.want {
|
|
t.Fatalf("looksLikeMobileProofTenant() = %t, want %t", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMobileProofBaseDomainFromURL(t *testing.T) {
|
|
tests := map[string]string{
|
|
"https://cloud.pulserelay.pro": "cloud.pulserelay.pro",
|
|
"http://cloud.pulserelay.pro:8080/x": "cloud.pulserelay.pro",
|
|
"cloud.pulserelay.pro/path": "cloud.pulserelay.pro",
|
|
" cloud.pulserelay.pro ": "cloud.pulserelay.pro",
|
|
}
|
|
|
|
for input, want := range tests {
|
|
t.Run(input, func(t *testing.T) {
|
|
if got := mobileProofBaseDomainFromURL(input); got != want {
|
|
t.Fatalf("mobileProofBaseDomainFromURL(%q) = %q, want %q", input, got, want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMobileProofCommandExposesAccountAndWorkspaceLifecycle(t *testing.T) {
|
|
cmd := newMobileProofCmd()
|
|
found := map[string]bool{}
|
|
for _, sub := range cmd.Commands() {
|
|
found[sub.Name()] = true
|
|
}
|
|
for _, name := range []string{"create-account", "create-workspace", "delete-workspace", "purge-account"} {
|
|
if !found[name] {
|
|
t.Fatalf("mobile-proof subcommand %q is not registered", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSafeMobileProofTenantDataDir(t *testing.T) {
|
|
root := t.TempDir()
|
|
got, err := safeMobileProofTenantDataDir(root, "t-TEST00001")
|
|
if err != nil {
|
|
t.Fatalf("safeMobileProofTenantDataDir: %v", err)
|
|
}
|
|
want := filepath.Join(root, "t-TEST00001")
|
|
if got != want {
|
|
t.Fatalf("safeMobileProofTenantDataDir = %q, want %q", got, want)
|
|
}
|
|
|
|
for _, tenantID := range []string{"", "../escape", "nested/t-TEST00001", `nested\t-TEST00001`} {
|
|
t.Run(tenantID, func(t *testing.T) {
|
|
if _, err := safeMobileProofTenantDataDir(root, tenantID); err == nil {
|
|
t.Fatalf("expected unsafe tenant id %q to fail", tenantID)
|
|
}
|
|
})
|
|
}
|
|
}
|