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,47 @@
package httpapi
import (
"net/http/httptest"
"strings"
"testing"
"github.com/gin-gonic/gin"
)
func TestAdminCredentialValidation(t *testing.T) {
for _, name := range []string{"admin", "admin-1", "ops_team", strings.Repeat("a", 32)} {
if !validAdminUsername(name) {
t.Fatalf("valid username rejected: %s", name)
}
}
for _, name := range []string{"", "ab", "name with space", "root@example.test", "管理员", "ADMIN", strings.Repeat("a", 33)} {
if validAdminUsername(name) {
t.Fatalf("invalid username accepted: %s", name)
}
}
if normalizeAdminUsername(" TEAM_1 ") != "team_1" {
t.Fatal("normalization")
}
for _, password := range []string{"x", strings.Repeat("a", 72), strings.Repeat("中", 24)} {
if !validAdminPassword(password) {
t.Fatal("valid password rejected")
}
}
for _, password := range []string{"", strings.Repeat("a", 73), strings.Repeat("中", 25)} {
if validAdminPassword(password) {
t.Fatal("invalid password accepted")
}
}
}
func TestAdminCannotDisableSelf(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("POST", "/admins/1/active", strings.NewReader(`{"active":false}`))
c.Request.Header.Set("Content-Type", "application/json")
c.Params = gin.Params{{Key: "id", Value: "1"}}
c.Set("admin_id", uint64(1))
(&BusinessAPI{}).setAdminActive(c)
if w.Code != 400 || !strings.Contains(w.Body.String(), "不能停用当前登录的管理员") {
t.Fatalf("%d %s", w.Code, w.Body)
}
}