feat: support permanent credentials and overlapping token rotation

This commit is contained in:
2026-09-27 11:45:15 +08:00
parent 87aa710013
commit 385a618154
29 changed files with 718 additions and 161 deletions

View File

@@ -91,8 +91,8 @@ func TestConsolePreparedApplicationRoundTrip(t *testing.T) {
queue, _ := core.NewID()
opID, _ := core.NewID()
token, _, _ := auth.Issue(ns, cred)
for _, kind := range []string{"CREATE", "ROTATE"} {
op := consoleauth.ApplicationOperation{Input: consoleauth.ApplicationInput{Kind: kind, ValidDays: 30, Reason: "test"}, OperationID: opID, ApplicationID: app, NamespaceID: ns, CredentialID: cred, Token: token, ExpiresAt: time.Now().UTC()}
for _, kind := range []string{"CREATE", "ROTATE", "SET_EXPIRY", "FINALIZE"} {
op := consoleauth.ApplicationOperation{Input: consoleauth.ApplicationInput{Kind: kind, ValidDays: 30, Reason: "test"}, OperationID: opID, ApplicationID: app, NamespaceID: ns, CredentialID: cred, Token: token, ExpiresAt: func() *time.Time { v := time.Now().UTC(); return &v }()}
if kind == "CREATE" {
op.QueueID = queue
op.Input.Application = "sample"
@@ -104,6 +104,12 @@ func TestConsolePreparedApplicationRoundTrip(t *testing.T) {
op.Input.CredentialID = cred
op.Input.ExpectedRevision = 1
}
if kind == "SET_EXPIRY" || kind == "FINALIZE" {
op.Version = 2
op.Token = ""
op.ExpiresAt = nil
op.Input.ValidDays = 0
}
raw, err := json.Marshal(op)
if err != nil {
t.Fatal(err)
@@ -114,7 +120,7 @@ func TestConsolePreparedApplicationRoundTrip(t *testing.T) {
if err := decodeBody(req, &got); err != nil {
t.Fatalf("%s prepared output rejected: %v", kind, err)
}
if got.Token != token || got.Input.Kind != kind {
if got.Token != op.Token || got.Input.Kind != kind {
t.Fatal("prepared operation changed")
}
}