feat(onprem): refuse unknown product keys, no trials in the catalog, tighter tests

- Start fails when PRODUCTS or a URL override names no catalog product.
- The on-prem catalog sets supports_trial=false (the portal hides the button).
- Test that seeded cloud provision URLs are never called on-prem, with a
  cloud control; the outbox test gets its cloud control too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 3e42b1ceb8)
This commit is contained in:
Sharang Parnerkar committed 2026-11-20 17:08:48 +01:00
1 parent a4fb318773
commit b30b5e3f1c
6 files changed
+196 -5

No files matched your search

+5 -1
View File
@@ -24,7 +24,11 @@ func (s *Server) getCatalog(w http.ResponseWriter, r *http.Request) {
}
items := make([]store.CatalogEntry, 0, len(products))
for _, p := range products {
items = append(items, p.Catalog(s.env()))
e := p.Catalog(s.env())
if s.onPrem() {
e.SupportsTrial = false // no trials on a customer's node: the portal hides the button
}
items = append(items, e)
}
writeJSON(w, http.StatusOK, map[string]any{"items": items})
}
+101 -1
View File
@@ -79,12 +79,23 @@ func TestOnPrem_cloudOnlyRoutesAnswer404(t *testing.T) {
func TestOnPrem_newWorkspaceIsActiveAndQueuesNothingForTheERP(t *testing.T) {
eachStore(t, func(t *testing.T, h *testHarness) {
onPremHarness(h, nil)
ctx := context.Background()
// Control: in the cloud a new workspace queues its ERP customer.
before, err := h.store.PendingOutbox(ctx)
if err != nil {
t.Fatal(err)
}
if resp, body := h.do("POST", "/v1/tenants", map[string]any{"slug": "cloud-ws", "name": "Cloud GmbH"}); resp.StatusCode != http.StatusCreated {
t.Fatalf("cloud create = %d %s", resp.StatusCode, body)
}
if n, _ := h.store.PendingOutbox(ctx); n != before+1 {
t.Fatalf("cloud outbox %d → %d, want +1", before, n)
}
onPremHarness(h, nil)
before, err = h.store.PendingOutbox(ctx)
if err != nil {
t.Fatal(err)
}
resp, body := h.do("POST", "/v1/tenants", map[string]any{"slug": "werk", "name": "Werk GmbH"})
if resp.StatusCode != http.StatusCreated {
t.Fatalf("create = %d %s", resp.StatusCode, body)
@@ -190,3 +201,92 @@ func newTrial(t *testing.T, h *testHarness) *store.Tenant {
}
return tr
}
// cloudURLStore serves Prüfwerk with seeded stage/prod provision URLs, as the
// migrations do on a real database.
type cloudURLStore struct {
store.Store
url string
}
func (c cloudURLStore) seed(p *store.Product) {
if p.Key == "pruefwerk" {
p.ProvisionURLs = map[string]string{"stage": c.url + "/{id}/stage", "prod": c.url + "/{id}/prod"}
}
}
func (c cloudURLStore) GetProduct(ctx context.Context, key string) (*store.Product, error) {
p, err := c.Store.GetProduct(ctx, key)
if err == nil {
c.seed(p)
}
return p, err
}
func (c cloudURLStore) ListProducts(ctx context.Context, all bool) ([]store.Product, error) {
ps, err := c.Store.ListProducts(ctx, all)
for i := range ps {
c.seed(&ps[i])
}
return ps, err
}
// Blocker #1: the seeded cloud URLs are never called on-prem, even when the
// values file gives a product no provision URL of its own.
func TestOnPrem_seededCloudProvisionURLsAreNeverCalled(t *testing.T) {
eachStore(t, func(t *testing.T, h *testHarness) {
var mu sync.Mutex
calls := 0
cloud := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mu.Lock()
calls++
mu.Unlock()
w.WriteHeader(http.StatusOK)
}))
defer cloud.Close()
seeded := cloudURLStore{Store: h.store, url: cloud.URL}
activate := func() {
t.Helper()
if resp, body := h.do("POST", "/v1/tenants/"+h.tenant.ID+"/activate", map[string]any{
"products": []map[string]any{{"key": "pruefwerk"}},
}); resp.StatusCode != http.StatusOK {
t.Fatalf("activate = %d %s", resp.StatusCode, body)
}
}
// Control: in the cloud (dev reads stage) the seeded URL is called.
h.app.Store = seeded
activate()
mu.Lock()
if calls != 1 {
t.Fatalf("cloud: %d calls to the seeded URL, want 1", calls)
}
calls = 0
mu.Unlock()
h.app.Cfg = &config.Config{Env: config.EnvOnPrem, LicenceTTLDays: 30}
h.app.Store = store.WithProductOverrides(seeded, h.app.Cfg.CatalogEnv(), []string{"pruefwerk"},
map[string]string{"pruefwerk": "https://pruefwerk.onprem.test"}, nil)
activate()
mu.Lock()
defer mu.Unlock()
if calls != 0 {
t.Errorf("on-prem: %d calls to a seeded cloud URL", calls)
}
})
}
func TestOnPrem_catalogOffersNoTrials(t *testing.T) {
eachStore(t, func(t *testing.T, h *testHarness) {
onPremHarness(h, nil)
_, body := h.do("GET", "/v1/catalog", nil)
out := decode[struct {
Items []store.CatalogEntry `json:"items"`
}](t, body)
for _, it := range out.Items {
if it.SupportsTrial {
t.Errorf("%s offers a trial on-prem", it.Key)
}
}
})
}