feat: implement license platform business flows and delivery tooling
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:
83
backend/internal/migrations/v6_integration_test.go
Normal file
83
backend/internal/migrations/v6_integration_test.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
migrate "github.com/golang-migrate/migrate/v4"
|
||||
_ "github.com/golang-migrate/migrate/v4/database/mysql"
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func TestV6Rehearsal(t *testing.T) {
|
||||
dsn := os.Getenv("MIGRATION_REHEARSAL_DSN")
|
||||
if dsn == "" {
|
||||
t.Skip("isolated rehearsal DSN required")
|
||||
}
|
||||
directory, err := filepath.Abs("../../migrations")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m, err := migrate.New((&url.URL{Scheme: "file", Path: filepath.ToSlash(directory)}).String(), "mysql://"+dsn+"?multiStatements=true")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer m.Close()
|
||||
if err = m.Migrate(5); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
statements := []string{
|
||||
"INSERT INTO admins(id,email,password_hash) VALUES(1,'rehearsal@example.invalid','not-a-login-hash')",
|
||||
"INSERT INTO customers(id,name,contact_email) VALUES(1,'rehearsal','rehearsal@example.invalid')",
|
||||
"INSERT INTO products(id,code,name,description) VALUES(1,'rehearsal','rehearsal','')",
|
||||
"INSERT INTO licenses(id,license_key,customer_id,product_id,starts_at,expires_at,idempotency_key,issued_by) VALUES(1,REPEAT('a',32),1,1,UTC_TIMESTAMP(),DATE_ADD(UTC_TIMESTAMP(),INTERVAL 1 YEAR),'rehearsal',1)",
|
||||
"INSERT INTO license_instances(id,instance_id,license_id,customer_id,product_id,secret_hash,created_by) VALUES(1,'00000000-0000-4000-8000-000000000001',1,1,1,UNHEX(REPEAT('00',32)),1)",
|
||||
"INSERT INTO activation_operations(instance_id,actor_admin_id,idempotency_key,request_fingerprint,response) VALUES(1,1,'rehearsal',UNHEX(REPEAT('00',32)),JSON_OBJECT('fixture',true))",
|
||||
"INSERT INTO audit_events(actor_admin_id,action,resource_type,resource_id,details) VALUES(1,'fixture','license_instance',1,JSON_OBJECT('fixture',true))",
|
||||
}
|
||||
for _, s := range statements {
|
||||
if _, err = db.Exec(s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err = m.Migrate(6); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = db.Exec("INSERT INTO heartbeat_operations(instance_id,idempotency_key,request_fingerprint,response,state) VALUES(1,'fixture',UNHEX(REPEAT('00',32)),JSON_OBJECT('fixture',true),'active')"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = db.Exec("INSERT INTO instance_state_operations(instance_id,actor_admin_id,idempotency_key,request_fingerprint,response) VALUES(1,1,'fixture',UNHEX(REPEAT('00',32)),JSON_OBJECT('fixture',true))"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = m.Steps(-1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, table := range []string{"admins", "customers", "products", "licenses", "license_instances", "activation_operations", "audit_events"} {
|
||||
var n int
|
||||
if err = db.QueryRow("SELECT COUNT(*) FROM " + table).Scan(&n); err != nil || n != 1 {
|
||||
t.Fatalf("old table %s n=%d err=%v", table, n, err)
|
||||
}
|
||||
}
|
||||
if err = m.Steps(1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, table := range []string{"heartbeat_operations", "instance_state_operations"} {
|
||||
var n int
|
||||
if err = db.QueryRow("SELECT COUNT(*) FROM " + table).Scan(&n); err != nil || n != 0 {
|
||||
t.Fatalf("v6 table %s n=%d err=%v", table, n, err)
|
||||
}
|
||||
}
|
||||
v, dirty, err := m.Version()
|
||||
if err != nil || v != 6 || dirty {
|
||||
t.Fatalf("version=%d dirty=%v err=%v", v, dirty, err)
|
||||
}
|
||||
t.Log("005 -> 006 -> 005 -> 006 clean; seven pre-v6 fixture rows preserved; v6 operation history and lease/freeze fields intentionally removed by down")
|
||||
}
|
||||
Reference in New Issue
Block a user