feat: implement license platform business flows and delivery tooling
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled

Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation.

Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
2026-10-09 15:33:22 +08:00
parent 3ab651d3a8
commit 54c318c615
142 changed files with 11105 additions and 178 deletions

View File

@@ -0,0 +1,64 @@
package config
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestLoadDefaults(t *testing.T) {
c, err := Load(func(string) string { return "" })
if err != nil || c.HTTPAddr != "127.0.0.1:18080" || c.ReadHeaderTimeout != 5*time.Second || c.ShutdownTimeout != 10*time.Second {
t.Fatalf("config=%+v err=%v", c, err)
}
}
func TestLoadOverrides(t *testing.T) {
values := map[string]string{"HTTP_ADDR": "[::1]:18081", "HTTP_WRITE_TIMEOUT": "2m"}
c, err := Load(func(key string) string { return values[key] })
if err != nil || c.HTTPAddr != values["HTTP_ADDR"] || c.WriteTimeout != 2*time.Minute {
t.Fatalf("config=%+v err=%v", c, err)
}
}
func TestLoadKeyFileAndStorage(t *testing.T) {
root := t.TempDir()
key := filepath.Join(root, "key.pem")
if err := os.WriteFile(key, []byte("test-only-content"), 0600); err != nil {
t.Fatal(err)
}
values := map[string]string{"LICENSE_SIGNING_PRIVATE_KEY_FILE": key, "PACKAGE_STORAGE_ROOT": root}
cfg, err := Load(func(k string) string { return values[k] })
if err != nil || cfg.SigningPrivateKeyPEM != "test-only-content" {
t.Fatal("file injection failed")
}
values["LICENSE_SIGNING_PRIVATE_KEY_PEM"] = "conflicting-source"
if _, err := Load(func(k string) string { return values[k] }); err == nil {
t.Fatal("ambiguous key sources accepted")
}
}
func TestLoadRejectsInvalid(t *testing.T) {
for _, tc := range []struct{ key, value string }{
{"HTTP_TRUSTED_PROXY_CIDRS", "0.0.0.0/0"}, {"HTTP_TRUSTED_PROXY_CIDRS", "::/0"},
{"HTTP_TRUSTED_PROXY_CIDRS", "127.0.0.1"}, {"HTTP_TRUSTED_PROXY_CIDRS", "bad"},
{"SESSION_COOKIE_SECURE", "yes"},
{"PACKAGE_STORAGE_ROOT", "relative/packages"}, {"LICENSE_SIGNING_PRIVATE_KEY_FILE", "relative/key.pem"},
{"HTTP_ADDR", "localhost"}, {"HTTP_ADDR", ":0"}, {"HTTP_ADDR", ":65536"}, {"HTTP_ADDR", ":abc"},
{"HTTP_READ_HEADER_TIMEOUT", "bad"}, {"HTTP_READ_TIMEOUT", "0s"},
{"HTTP_WRITE_TIMEOUT", "-1s"}, {"HTTP_IDLE_TIMEOUT", "6m"}, {"HTTP_SHUTDOWN_TIMEOUT", "0s"},
} {
t.Run(tc.key+tc.value, func(t *testing.T) {
_, err := Load(func(key string) string {
if key == tc.key {
return tc.value
}
return ""
})
if err == nil {
t.Fatal("expected configuration error")
}
})
}
}