From 5ee0d34f2cfb4357fe92b944c4e48549dfa0ff1f Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 13:36:10 +1000 Subject: [PATCH 01/17] fix: cleanup CSR requirements and description Signed-off-by: James Hateley --- spec/api-spec-v2.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/api-spec-v2.yaml b/spec/api-spec-v2.yaml index 4e30cd1..2d55c5e 100644 --- a/spec/api-spec-v2.yaml +++ b/spec/api-spec-v2.yaml @@ -174,13 +174,12 @@ paths: description: | Registers a new agent with the Agent Name Service. - The Registration Authority (RA) validates the agent's identity and - submitted information, then interacts with the CA to issue certificates - or validates provided (BYOC) server certificates. + The request MAY include a Certificate Signing Request (CSR) so that + an Identity certificate can be issued. Identity certificates are + issued by the RA. - The request MUST include an identity CSR. The request can optionally - include a server CSR (for RA-issued server cert) or a BYOC server - certificate with its chain. + The request can optionally include a server CSR (for RA-issued server cert) + or a BYOC server certificate with its chain. operationId: registerAgent requestBody: description: Agent registration request @@ -1607,6 +1606,9 @@ components: - agentHost - endpoints - version + oneOf: + - required: [serverCsrPEM] + - required: [serverCertificatePEM] AgentRevocationRequest: type: object From 3da54a9e77325c047e97b6b7f602f08d3bd01d4e Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 13:37:10 +1000 Subject: [PATCH 02/17] fix: fix tl eventType enum api-spec Signed-off-by: James Hateley --- spec/api-spec-tl-v2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-spec-tl-v2.yaml b/spec/api-spec-tl-v2.yaml index 4664a78..f5035b7 100644 --- a/spec/api-spec-tl-v2.yaml +++ b/spec/api-spec-tl-v2.yaml @@ -997,7 +997,7 @@ components: ansName: { type: string, example: "ans://v1.0.0.agent.example.com" } eventType: type: string - enum: [AGENT_REGISTRATION, DOMAIN_VALIDATION, AGENT_ACTIVE, AGENT_REVOCATION] + enum: [AGENT_REGISTERED, AGENT_RENEWED, AGENT_DEPRECATED, AGENT_REVOKED] raId: { type: string, example: "ans-ra-local" } issuedAt: { type: string, format: date-time } timestamp: { type: string, format: date-time } From 9d798b44dcf5b65bd49a1ff96ca026af5751b9b9 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 13:37:46 +1000 Subject: [PATCH 03/17] fix: add missing dnssecVerified field to v2.json Signed-off-by: James Hateley --- internal/tl/service/schemas/V2.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/tl/service/schemas/V2.json b/internal/tl/service/schemas/V2.json index c2d5502..b1d9fc0 100644 --- a/internal/tl/service/schemas/V2.json +++ b/internal/tl/service/schemas/V2.json @@ -124,6 +124,10 @@ "TXT" ], "type": "string" + }, + "dnssecVerified": { + "description": "Indicates that the RA's verifier observed the DNSSEC authenticated-data bit on the response that produced the attestation", + "type": "boolean" } }, "type": "object" From af67e83b1b6e210fc2d3d2df6311ab946be10326 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 13:45:58 +1000 Subject: [PATCH 04/17] fix: fix enum casing for transports and protocols Signed-off-by: James Hateley --- internal/adapter/docsui/openapi/ra.yaml | 17 ++++++++++------- internal/domain/protocol_test.go | 1 + spec/api-spec-v2.yaml | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/adapter/docsui/openapi/ra.yaml b/internal/adapter/docsui/openapi/ra.yaml index 4e30cd1..a3335e2 100644 --- a/internal/adapter/docsui/openapi/ra.yaml +++ b/internal/adapter/docsui/openapi/ra.yaml @@ -174,12 +174,12 @@ paths: description: | Registers a new agent with the Agent Name Service. - The Registration Authority (RA) validates the agent's identity and - submitted information, then interacts with the CA to issue certificates - or validates provided (BYOC) server certificates. + The request MAY include a Certificate Signing Request (CSR) so that + an Identity certificate can be issued. Identity certificates are + issued by the RA. - The request MUST include an identity CSR. The request can optionally - include a server CSR (for RA-issued server cert) or a BYOC server + The request can optionally include a server CSR (for RA-issued server cert) + or a BYOC server certificate with its chain. certificate with its chain. operationId: registerAgent requestBody: @@ -1472,7 +1472,7 @@ components: Protocol: type: string - enum: [A2A, MCP, HTTP-API] + enum: [A2A, MCP, HTTP_API] DiscoveryProfile: type: string @@ -1607,6 +1607,9 @@ components: - agentHost - endpoints - version + oneOf: + - required: [serverCsrPEM] + - required: [serverCertificatePEM] AgentRevocationRequest: type: object @@ -1887,7 +1890,7 @@ components: type: array items: type: string - enum: [STREAMABLE-HTTP, SSE, JSON-RPC, GRPC, REST, HTTP] + enum: [STREAMABLE_HTTP, SSE, JSON_RPC, GRPC, REST, HTTP] required: - protocol - agentUrl diff --git a/internal/domain/protocol_test.go b/internal/domain/protocol_test.go index 16ec6a0..f2c2136 100644 --- a/internal/domain/protocol_test.go +++ b/internal/domain/protocol_test.go @@ -60,6 +60,7 @@ func TestParseTransport(t *testing.T) { {"STREAMABLE-HTTP", TransportStreamableHTTP, false}, {"sse", TransportSSE, false}, {"json-rpc", TransportJSONRPC, false}, + {"json_rpc", TransportJSONRPC, false}, {"JSONRPC", TransportJSONRPC, false}, {"GRPC", TransportGRPC, false}, {"REST", TransportREST, false}, diff --git a/spec/api-spec-v2.yaml b/spec/api-spec-v2.yaml index 2d55c5e..074bc8c 100644 --- a/spec/api-spec-v2.yaml +++ b/spec/api-spec-v2.yaml @@ -1471,7 +1471,7 @@ components: Protocol: type: string - enum: [A2A, MCP, HTTP-API] + enum: [A2A, MCP, HTTP_API] DiscoveryProfile: type: string @@ -1889,7 +1889,7 @@ components: type: array items: type: string - enum: [STREAMABLE-HTTP, SSE, JSON-RPC, GRPC, REST, HTTP] + enum: [STREAMABLE_HTTP, SSE, JSON_RPC, GRPC, REST, HTTP] required: - protocol - agentUrl From 83acc91a4969f43aa201d5db2f93aaeeaf162d02 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 16:01:50 +1000 Subject: [PATCH 05/17] fix: fix api spec drift from previous commit Signed-off-by: James Hateley --- internal/adapter/docsui/openapi/ra.yaml | 1 - internal/adapter/docsui/openapi/tl.yaml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/adapter/docsui/openapi/ra.yaml b/internal/adapter/docsui/openapi/ra.yaml index a3335e2..074bc8c 100644 --- a/internal/adapter/docsui/openapi/ra.yaml +++ b/internal/adapter/docsui/openapi/ra.yaml @@ -180,7 +180,6 @@ paths: The request can optionally include a server CSR (for RA-issued server cert) or a BYOC server certificate with its chain. - certificate with its chain. operationId: registerAgent requestBody: description: Agent registration request diff --git a/internal/adapter/docsui/openapi/tl.yaml b/internal/adapter/docsui/openapi/tl.yaml index 4664a78..f5035b7 100644 --- a/internal/adapter/docsui/openapi/tl.yaml +++ b/internal/adapter/docsui/openapi/tl.yaml @@ -997,7 +997,7 @@ components: ansName: { type: string, example: "ans://v1.0.0.agent.example.com" } eventType: type: string - enum: [AGENT_REGISTRATION, DOMAIN_VALIDATION, AGENT_ACTIVE, AGENT_REVOCATION] + enum: [AGENT_REGISTERED, AGENT_RENEWED, AGENT_DEPRECATED, AGENT_REVOKED] raId: { type: string, example: "ans-ra-local" } issuedAt: { type: string, format: date-time } timestamp: { type: string, format: date-time } From 80b6646334807841ee48d209aa79483a6cfa9c0a Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 16:02:29 +1000 Subject: [PATCH 06/17] fix: align AgentFunction validation with api-spec Signed-off-by: James Hateley --- internal/domain/endpoint.go | 20 ++++++++++++++++++-- internal/domain/endpoint_test.go | 12 +++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/internal/domain/endpoint.go b/internal/domain/endpoint.go index 73da712..acaac85 100644 --- a/internal/domain/endpoint.go +++ b/internal/domain/endpoint.go @@ -9,8 +9,10 @@ import ( ) const ( - maxFunctionTags = 20 - maxTagLength = 20 + maxFunctionTags = 5 + maxTagLength = 20 + maxFunctionIdLength = 64 + maxFunctionNameLength = 64 // maxMetadataURLLength bounds the operator-supplied metadataUrl. It // is emitted verbatim as the DNSAID `cap` SvcParam and embedded in the // signed TL attestation, so an unbounded value would bloat the @@ -29,12 +31,26 @@ type AgentFunction struct { // Validate checks that the function has valid fields. func (f AgentFunction) Validate() error { + if len(f.ID) > maxFunctionIdLength { + return NewValidationError( + "INVALID_FUNCTION", + fmt.Sprintf("function id length %d exceeds %d characters", len(f.ID), maxFunctionIdLength), + ) + } if strings.TrimSpace(f.ID) == "" { return NewValidationError("INVALID_FUNCTION", "function id cannot be blank") } + + if len(f.Name) > maxFunctionNameLength { + return NewValidationError( + "INVALID_FUNCTION", + fmt.Sprintf("function name length %d exceeds %d characters", len(f.Name), maxFunctionNameLength), + ) + } if strings.TrimSpace(f.Name) == "" { return NewValidationError("INVALID_FUNCTION", "function name cannot be blank") } + for _, tag := range f.Tags { if len(tag) > maxTagLength { return NewValidationError( diff --git a/internal/domain/endpoint_test.go b/internal/domain/endpoint_test.go index 26a31d8..e05d778 100644 --- a/internal/domain/endpoint_test.go +++ b/internal/domain/endpoint_test.go @@ -14,11 +14,21 @@ func TestAgentFunction_Validate(t *testing.T) { assert.NoError(t, f.Validate()) }) + t.Run("reject long id", func(t *testing.T) { + err := AgentFunction{ID: strings.Repeat("x", 65), Name: "n"}.Validate() + assert.ErrorIs(t, err, ErrValidation) + }) + t.Run("reject blank id", func(t *testing.T) { err := AgentFunction{ID: " ", Name: "ok"}.Validate() assert.ErrorIs(t, err, ErrValidation) }) + t.Run("reject long name", func(t *testing.T) { + err := AgentFunction{ID: "id", Name: strings.Repeat("x", 65)}.Validate() + assert.ErrorIs(t, err, ErrValidation) + }) + t.Run("reject blank name", func(t *testing.T) { err := AgentFunction{ID: "id", Name: ""}.Validate() assert.ErrorIs(t, err, ErrValidation) @@ -30,7 +40,7 @@ func TestAgentFunction_Validate(t *testing.T) { }) t.Run("reject too many tags", func(t *testing.T) { - tags := make([]string, 21) + tags := make([]string, 6) for i := range tags { tags[i] = "t" } From 07c1360369db154f586a6d1fe36fd268e9a5d5c7 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 17:08:03 +1000 Subject: [PATCH 07/17] fix: align AgentLifecycleStatusFilter validation with api-spec Signed-off-by: James Hateley --- internal/ra/handler/lifecycle.go | 9 ++++++++- internal/ra/handler/lifecycle_test.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/ra/handler/lifecycle.go b/internal/ra/handler/lifecycle.go index 89101da..6476eef 100644 --- a/internal/ra/handler/lifecycle.go +++ b/internal/ra/handler/lifecycle.go @@ -62,7 +62,14 @@ func (h *LifecycleHandler) List(w http.ResponseWriter, r *http.Request) { filter.Statuses = nil break } - filter.Statuses = append(filter.Statuses, domain.RegistrationStatus(s)) + switch domain.RegistrationStatus(s) { + case domain.StatusPendingDNS, domain.StatusActive, domain.StatusDeprecated, domain.StatusRevoked: + filter.Statuses = append(filter.Statuses, domain.RegistrationStatus(s)) + default: + WriteError(w, domain.NewValidationError("INVALID_STATUS", + "status must be one of PENDING_DNS, ACTIVE, DEPRECATED, REVOKED, ALL")) + return + } } } else { filter.Statuses = []domain.RegistrationStatus{domain.StatusActive} diff --git a/internal/ra/handler/lifecycle_test.go b/internal/ra/handler/lifecycle_test.go index 1988a02..bec878b 100644 --- a/internal/ra/handler/lifecycle_test.go +++ b/internal/ra/handler/lifecycle_test.go @@ -120,6 +120,26 @@ func TestList_BadLimitReturns422(t *testing.T) { } } +func TestList_BadStatusReturns422(t *testing.T) { + t.Parallel() + fx := newHandlerFixture(t) + rec := fx.request(t, http.MethodGet, "/v2/ans/agents?status=BOGUS", nil, fx.asOwner("alice")) + if rec.Code != http.StatusUnprocessableEntity { + t.Fatalf("want 422, got %d body=%s", rec.Code, rec.Body) + } +} + +func TestList_UnfilterableStatusReturns422(t *testing.T) { + t.Parallel() + fx := newHandlerFixture(t) + // PENDING_VALIDATION/FAILED/EXPIRED are valid AgentLifecycleStatus + // values but are not in AgentLifecycleStatusFilter — not filterable. + rec := fx.request(t, http.MethodGet, "/v2/ans/agents?status=PENDING_VALIDATION", nil, fx.asOwner("alice")) + if rec.Code != http.StatusUnprocessableEntity { + t.Fatalf("want 422, got %d body=%s", rec.Code, rec.Body) + } +} + func TestDetail_OwnedReturns200(t *testing.T) { t.Parallel() fx := newHandlerFixture(t) From d270d59f5608690148860319421fcb156845897f Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 17:26:04 +1000 Subject: [PATCH 08/17] fix: fix lint issue from previous commit Signed-off-by: James Hateley --- internal/domain/endpoint.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/domain/endpoint.go b/internal/domain/endpoint.go index acaac85..d077fb1 100644 --- a/internal/domain/endpoint.go +++ b/internal/domain/endpoint.go @@ -11,7 +11,7 @@ import ( const ( maxFunctionTags = 5 maxTagLength = 20 - maxFunctionIdLength = 64 + maxFunctionIDLength = 64 maxFunctionNameLength = 64 // maxMetadataURLLength bounds the operator-supplied metadataUrl. It // is emitted verbatim as the DNSAID `cap` SvcParam and embedded in the @@ -31,10 +31,10 @@ type AgentFunction struct { // Validate checks that the function has valid fields. func (f AgentFunction) Validate() error { - if len(f.ID) > maxFunctionIdLength { + if len(f.ID) > maxFunctionIDLength { return NewValidationError( "INVALID_FUNCTION", - fmt.Sprintf("function id length %d exceeds %d characters", len(f.ID), maxFunctionIdLength), + fmt.Sprintf("function id length %d exceeds %d characters", len(f.ID), maxFunctionIDLength), ) } if strings.TrimSpace(f.ID) == "" { From 3df37d7c8e9b14c6944832e488a508095a71c909 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 17:27:56 +1000 Subject: [PATCH 09/17] fix: align spec with metadata hash endpoint validation Signed-off-by: James Hateley --- internal/adapter/docsui/openapi/ra.yaml | 16 ++++++++++++++++ spec/api-spec-v2.yaml | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/internal/adapter/docsui/openapi/ra.yaml b/internal/adapter/docsui/openapi/ra.yaml index 074bc8c..109a411 100644 --- a/internal/adapter/docsui/openapi/ra.yaml +++ b/internal/adapter/docsui/openapi/ra.yaml @@ -1554,6 +1554,14 @@ components: endpoints: type: array minItems: 1 + description: >- + One or more protocol endpoints. Each protocol may appear at + most once across the array — a second endpoint with an + already-used protocol is rejected with 422 DUPLICATE_PROTOCOL, + and an exact protocol+agentUrl repeat with 422 + DUPLICATE_ENDPOINT. (By-field uniqueness is not expressible in + OpenAPI/JSON Schema; enforced in + internal/domain/endpoint.go AgentEndpoints.Validate.) items: $ref: '#/components/schemas/AgentEndpoint' serverCsrPEM: @@ -1876,6 +1884,10 @@ components: metaDataHash: type: string pattern: '^SHA256:[a-f0-9]{64}$' + description: >- + Optional integrity pin over the metadata descriptor. + Meaningless on its own: it MUST be accompanied by metaDataUrl. + A metaDataHash without a metaDataUrl is rejected with 422 INVALID_ENDPOINT. documentationUrl: type: string format: uri @@ -1893,6 +1905,10 @@ components: required: - protocol - agentUrl + anyOf: + - not: + required: [metaDataHash] + - required: [metaDataUrl] AgentFunction: type: object diff --git a/spec/api-spec-v2.yaml b/spec/api-spec-v2.yaml index 074bc8c..109a411 100644 --- a/spec/api-spec-v2.yaml +++ b/spec/api-spec-v2.yaml @@ -1554,6 +1554,14 @@ components: endpoints: type: array minItems: 1 + description: >- + One or more protocol endpoints. Each protocol may appear at + most once across the array — a second endpoint with an + already-used protocol is rejected with 422 DUPLICATE_PROTOCOL, + and an exact protocol+agentUrl repeat with 422 + DUPLICATE_ENDPOINT. (By-field uniqueness is not expressible in + OpenAPI/JSON Schema; enforced in + internal/domain/endpoint.go AgentEndpoints.Validate.) items: $ref: '#/components/schemas/AgentEndpoint' serverCsrPEM: @@ -1876,6 +1884,10 @@ components: metaDataHash: type: string pattern: '^SHA256:[a-f0-9]{64}$' + description: >- + Optional integrity pin over the metadata descriptor. + Meaningless on its own: it MUST be accompanied by metaDataUrl. + A metaDataHash without a metaDataUrl is rejected with 422 INVALID_ENDPOINT. documentationUrl: type: string format: uri @@ -1893,6 +1905,10 @@ components: required: - protocol - agentUrl + anyOf: + - not: + required: [metaDataHash] + - required: [metaDataUrl] AgentFunction: type: object From 4c1d806760e4783719cd08ba1a705b900ec735b1 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 19:44:06 +1000 Subject: [PATCH 10/17] fix: enforce required display name and cap on revoke comments Signed-off-by: James Hateley --- internal/domain/agent.go | 3 +++ internal/domain/agent_test.go | 13 +++++++------ internal/ra/handler/v1lifecycle.go | 11 +++++++++++ internal/ra/handler/v1lifecycle_test.go | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/internal/domain/agent.go b/internal/domain/agent.go index d3562eb..b496324 100644 --- a/internal/domain/agent.go +++ b/internal/domain/agent.go @@ -118,6 +118,9 @@ func NewRegistration( if ownerID == "" { return nil, NewValidationError("MISSING_OWNER_ID", "ownerId is required") } + if displayName == "" { + return nil, NewValidationError("MISSING_DISPLAY_NAME", "displayName is required") + } if ansName.IsZero() { return nil, NewValidationError("MISSING_ANS_NAME", "ansName is required") } diff --git a/internal/domain/agent_test.go b/internal/domain/agent_test.go index 71d1603..449bbe2 100644 --- a/internal/domain/agent_test.go +++ b/internal/domain/agent_test.go @@ -85,12 +85,13 @@ func TestNewRegistration_Validations(t *testing.T) { csr *AgentCSR code string }{ - {"missing agent id", "", "o", validName, "", "", validEndpoints, nil, &validCSR, "MISSING_AGENT_ID"}, - {"missing owner", "a", "", validName, "", "", validEndpoints, nil, &validCSR, "MISSING_OWNER_ID"}, - {"missing ans name", "a", "o", AnsName{}, "", "", validEndpoints, nil, &validCSR, "MISSING_ANS_NAME"}, + {"missing agent id", "", "o", validName, "displayName", "", validEndpoints, nil, &validCSR, "MISSING_AGENT_ID"}, + {"missing owner", "a", "", validName, "displayName", "", validEndpoints, nil, &validCSR, "MISSING_OWNER_ID"}, + {"missing ans name", "a", "o", AnsName{}, "displayName", "", validEndpoints, nil, &validCSR, "MISSING_ANS_NAME"}, + {"missing display name", "a", "o", validName, "", "", validEndpoints, nil, &validCSR, "MISSING_DISPLAY_NAME"}, {"display name too long", "a", "o", validName, strings.Repeat("x", 65), "", validEndpoints, nil, &validCSR, "DISPLAY_NAME_TOO_LONG"}, - {"description too long", "a", "o", validName, "", strings.Repeat("x", 151), validEndpoints, nil, &validCSR, "DESCRIPTION_TOO_LONG"}, - {"no endpoints", "a", "o", validName, "", "", nil, nil, &validCSR, "MISSING_ENDPOINTS"}, + {"description too long", "a", "o", validName, "displayName", strings.Repeat("x", 151), validEndpoints, nil, &validCSR, "DESCRIPTION_TOO_LONG"}, + {"no endpoints", "a", "o", validName, "displayName", "", nil, nil, &validCSR, "MISSING_ENDPOINTS"}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { @@ -109,7 +110,7 @@ func TestNewRegistration_CertFQDNMismatch(t *testing.T) { ep := []AgentEndpoint{{Protocol: ProtocolMCP, AgentURL: "https://agent.example.com/mcp"}} cert := &ByocServerCertificate{SubjectCommonName: "other.example.com"} - _, err := NewRegistration("a", "o", ansName, "", "", ep, cert, &csr, time.Now()) + _, err := NewRegistration("a", "o", ansName, "displayName", "", ep, cert, &csr, time.Now()) assert.ErrorIs(t, err, ErrCertificate) } diff --git a/internal/ra/handler/v1lifecycle.go b/internal/ra/handler/v1lifecycle.go index c208b94..036cee5 100644 --- a/internal/ra/handler/v1lifecycle.go +++ b/internal/ra/handler/v1lifecycle.go @@ -2,6 +2,7 @@ package handler import ( "encoding/json" + "fmt" "net/http" "github.com/go-chi/chi/v5" @@ -10,6 +11,10 @@ import ( "github.com/godaddy/ans/internal/ra/service" ) +const ( + maxCommentsLength = 200 +) + // V1LifecycleHandler groups the V1 post-registration transitions: // verify-acme, verify-dns, revoke. Shares the `RegistrationService` // with V2; diverges only in DTO shape and TL-lane emission. @@ -149,6 +154,12 @@ func (h *V1LifecycleHandler) Revoke(w http.ResponseWriter, r *http.Request) { return } + if len(req.Comments) > 200 { + WriteError(w, domain.NewValidationError("COMMENTS_TOO_LONG", + fmt.Sprintf("comments exceeds %d characters", maxCommentsLength))) + return + } + agentID := chi.URLParam(r, "agentId") res, err := h.svc.Revoke(r.Context(), agentID, service.RevokeInput{ Reason: domain.RevocationReason(req.Reason), diff --git a/internal/ra/handler/v1lifecycle_test.go b/internal/ra/handler/v1lifecycle_test.go index 162721c..7ecd921 100644 --- a/internal/ra/handler/v1lifecycle_test.go +++ b/internal/ra/handler/v1lifecycle_test.go @@ -385,6 +385,24 @@ func TestV1Revoke_MissingReason_422(t *testing.T) { } } +func TestV1Revoke_CommentsTooLong_422(t *testing.T) { + t.Parallel() + fx := newHandlerFixture(t) + agentID, _ := fx.v1RegisterAgent(t, "alice", "agent.example.com", "1.0.0") + revBody, _ := json.Marshal(map[string]any{ + "reason": "KEY_COMPROMISE", + "comments": strings.Repeat("a", 201), + }) + rec := fx.request(t, http.MethodPost, "/v1/agents/"+agentID+"/revoke", + bytes.NewReader(revBody), fx.asOwner("alice")) + if rec.Code != http.StatusUnprocessableEntity { + t.Fatalf("want 422, got %d body=%s", rec.Code, rec.Body) + } + if !strings.Contains(rec.Body.String(), "COMMENTS_TOO_LONG") { + t.Errorf("expected COMMENTS_TOO_LONG code, got %s", rec.Body) + } +} + // TestV1Revoke_NotOwned_403 confirms WriteOwnership 403 on // not-owned revoke attempts (as opposed to read routes which 404). func TestV1Revoke_NotOwned_403(t *testing.T) { From 890265d52995c8e40c29d3e329fe8caaffa8e194 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Tue, 14 Jul 2026 20:08:39 +1000 Subject: [PATCH 11/17] fix: align revocation reason code spec, tl, ra Signed-off-by: James Hateley --- internal/adapter/docsui/openapi/ra.yaml | 4 ++++ internal/domain/status.go | 12 ++++++++---- internal/domain/status_test.go | 8 ++++---- internal/tl/event/event.go | 4 ++++ internal/tl/event/event_test.go | 12 ++++++++++++ internal/tl/event/v1/event.go | 5 +++++ internal/tl/event/v1/event_test.go | 12 ++++++++++++ spec/api-spec-v2.yaml | 4 ++++ 8 files changed, 53 insertions(+), 8 deletions(-) diff --git a/internal/adapter/docsui/openapi/ra.yaml b/internal/adapter/docsui/openapi/ra.yaml index 109a411..6ae0c5d 100644 --- a/internal/adapter/docsui/openapi/ra.yaml +++ b/internal/adapter/docsui/openapi/ra.yaml @@ -1525,13 +1525,17 @@ components: RevocationReason: type: string enum: + - UNSPECIFIED - KEY_COMPROMISE + - CA_COMPROMISE - CESSATION_OF_OPERATION - AFFILIATION_CHANGED - SUPERSEDED - CERTIFICATE_HOLD + - REMOVE_FROM_CRL - PRIVILEGE_WITHDRAWN - AA_COMPROMISE + - EXPIRED_CERT AgentRegistrationRequest: type: object diff --git a/internal/domain/status.go b/internal/domain/status.go index 314d222..3e450ba 100644 --- a/internal/domain/status.go +++ b/internal/domain/status.go @@ -139,22 +139,26 @@ const ( type RevocationReason string const ( + RevocationUnspecified RevocationReason = "UNSPECIFIED" RevocationKeyCompromise RevocationReason = "KEY_COMPROMISE" + RevocationCACompromise RevocationReason = "CA_COMPROMISE" RevocationCessationOfOperation RevocationReason = "CESSATION_OF_OPERATION" RevocationAffiliationChanged RevocationReason = "AFFILIATION_CHANGED" RevocationSuperseded RevocationReason = "SUPERSEDED" RevocationCertificateHold RevocationReason = "CERTIFICATE_HOLD" + RevocationRemoveFromCRL RevocationReason = "REMOVE_FROM_CRL" RevocationPrivilegeWithdrawn RevocationReason = "PRIVILEGE_WITHDRAWN" RevocationAACompromise RevocationReason = "AA_COMPROMISE" + RevocationExpiredCert RevocationReason = "EXPIRED_CERT" ) // IsValid returns true if the revocation reason is a recognized value. func (r RevocationReason) IsValid() bool { switch r { - case RevocationKeyCompromise, RevocationCessationOfOperation, - RevocationAffiliationChanged, RevocationSuperseded, - RevocationCertificateHold, RevocationPrivilegeWithdrawn, - RevocationAACompromise: + case RevocationUnspecified, RevocationKeyCompromise, RevocationCACompromise, + RevocationCessationOfOperation, RevocationAffiliationChanged, RevocationSuperseded, + RevocationCertificateHold, RevocationRemoveFromCRL, RevocationPrivilegeWithdrawn, + RevocationAACompromise, RevocationExpiredCert: return true default: return false diff --git a/internal/domain/status_test.go b/internal/domain/status_test.go index 0f9c94a..71cd0f2 100644 --- a/internal/domain/status_test.go +++ b/internal/domain/status_test.go @@ -79,10 +79,10 @@ func TestRegistrationStatus_ValidateTransition(t *testing.T) { func TestRevocationReason_IsValid(t *testing.T) { valid := []RevocationReason{ - RevocationKeyCompromise, RevocationCessationOfOperation, - RevocationAffiliationChanged, RevocationSuperseded, - RevocationCertificateHold, RevocationPrivilegeWithdrawn, - RevocationAACompromise, + RevocationUnspecified, RevocationKeyCompromise, RevocationCACompromise, + RevocationCessationOfOperation, RevocationAffiliationChanged, RevocationSuperseded, + RevocationCertificateHold, RevocationRemoveFromCRL, RevocationPrivilegeWithdrawn, + RevocationAACompromise, RevocationExpiredCert, } for _, r := range valid { assert.True(t, r.IsValid(), "expected %s valid", r) diff --git a/internal/tl/event/event.go b/internal/tl/event/event.go index 3e6473b..bf93a8a 100644 --- a/internal/tl/event/event.go +++ b/internal/tl/event/event.go @@ -38,6 +38,7 @@ import ( "time" anscrypto "github.com/godaddy/ans/internal/crypto" + "github.com/godaddy/ans/internal/domain" ) // SchemaVersion pins the envelope version. "V2" because our V2 RA @@ -279,6 +280,9 @@ func (ev *Event) Validate() error { if _, err := time.Parse(time.RFC3339, ev.Timestamp); err != nil { return fmt.Errorf("event: timestamp must be RFC3339: %w", err) } + if ev.RevocationReasonCode != "" && !domain.RevocationReason(ev.RevocationReasonCode).IsValid() { + return fmt.Errorf("event: invalid revocationReasonCode %q", ev.RevocationReasonCode) + } return nil } diff --git a/internal/tl/event/event_test.go b/internal/tl/event/event_test.go index 8459906..5ce7a53 100644 --- a/internal/tl/event/event_test.go +++ b/internal/tl/event/event_test.go @@ -121,6 +121,15 @@ func TestEnvelope_Validate_Success(t *testing.T) { } } +func TestEnvelope_Validate_RevocationReasonCode_Valid(t *testing.T) { + t.Parallel() + env := fixedEnvelope() + env.Payload.Producer.Event.RevocationReasonCode = "CA_COMPROMISE" + if err := env.Validate(); err != nil { + t.Fatalf("Validate: %v", err) + } +} + func TestEnvelope_Validate_MissingFields(t *testing.T) { t.Parallel() cases := map[string]func(e *event.Envelope){ @@ -137,6 +146,9 @@ func TestEnvelope_Validate_MissingFields(t *testing.T) { "no ansName": func(e *event.Envelope) { e.Payload.Producer.Event.AnsName = "" }, "no timestamp": func(e *event.Envelope) { e.Payload.Producer.Event.Timestamp = "" }, "non-RFC3339 time": func(e *event.Envelope) { e.Payload.Producer.Event.Timestamp = "yesterday" }, + "bad revocationReasonCode": func(e *event.Envelope) { + e.Payload.Producer.Event.RevocationReasonCode = "BOGUS" + }, } for name, mutate := range cases { t.Run(name, func(t *testing.T) { diff --git a/internal/tl/event/v1/event.go b/internal/tl/event/v1/event.go index a449bc2..a7a2068 100644 --- a/internal/tl/event/v1/event.go +++ b/internal/tl/event/v1/event.go @@ -31,6 +31,8 @@ import ( "errors" "fmt" "time" + + "github.com/godaddy/ans/internal/domain" ) // SchemaVersion pins the envelope label for V1 events. Producer + @@ -186,6 +188,9 @@ func (e *Event) Validate() error { if _, err := time.Parse(time.RFC3339, e.Timestamp); err != nil { return fmt.Errorf("event/v1: event.timestamp not RFC3339: %w", err) } + if e.RevocationReasonCode != "" && !domain.RevocationReason(e.RevocationReasonCode).IsValid() { + return fmt.Errorf("event/v1: invalid revocationReasonCode %q", e.RevocationReasonCode) + } return nil } diff --git a/internal/tl/event/v1/event_test.go b/internal/tl/event/v1/event_test.go index 14d7e80..e5fb4a9 100644 --- a/internal/tl/event/v1/event_test.go +++ b/internal/tl/event/v1/event_test.go @@ -140,6 +140,15 @@ func TestEnvelope_Validate_Success(t *testing.T) { } } +func TestEnvelope_Validate_RevocationReasonCode_Valid(t *testing.T) { + t.Parallel() + env := fixedEnvelope() + env.Payload.Producer.Event.RevocationReasonCode = "REMOVE_FROM_CRL" + if err := env.Validate(); err != nil { + t.Fatalf("Validate: %v", err) + } +} + func TestEnvelope_Validate_Failures(t *testing.T) { t.Parallel() cases := map[string]func(e *v1.Envelope){ @@ -155,6 +164,9 @@ func TestEnvelope_Validate_Failures(t *testing.T) { "no ansName": func(e *v1.Envelope) { e.Payload.Producer.Event.AnsName = "" }, "no timestamp": func(e *v1.Envelope) { e.Payload.Producer.Event.Timestamp = "" }, "non-RFC3339 time": func(e *v1.Envelope) { e.Payload.Producer.Event.Timestamp = "yesterday" }, + "bad revocationReasonCode": func(e *v1.Envelope) { + e.Payload.Producer.Event.RevocationReasonCode = "BOGUS" + }, } for name, mutate := range cases { t.Run(name, func(t *testing.T) { diff --git a/spec/api-spec-v2.yaml b/spec/api-spec-v2.yaml index 109a411..6ae0c5d 100644 --- a/spec/api-spec-v2.yaml +++ b/spec/api-spec-v2.yaml @@ -1525,13 +1525,17 @@ components: RevocationReason: type: string enum: + - UNSPECIFIED - KEY_COMPROMISE + - CA_COMPROMISE - CESSATION_OF_OPERATION - AFFILIATION_CHANGED - SUPERSEDED - CERTIFICATE_HOLD + - REMOVE_FROM_CRL - PRIVILEGE_WITHDRAWN - AA_COMPROMISE + - EXPIRED_CERT AgentRegistrationRequest: type: object From a7d3353cabd76b34bcae7f4e836052caa9d56828 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Wed, 15 Jul 2026 11:01:19 +1000 Subject: [PATCH 12/17] fix: revert reason code enum to original 7 Signed-off-by: James Hateley --- internal/adapter/docsui/openapi/ra.yaml | 4 ---- internal/domain/status.go | 12 ++++-------- internal/domain/status_test.go | 8 ++++---- internal/tl/event/event_test.go | 2 +- internal/tl/event/v1/event_test.go | 2 +- internal/tl/service/schemas/V0.json | 8 ++------ internal/tl/service/schemas/V1.json | 8 ++------ internal/tl/service/schemas/V2.json | 8 ++------ spec/api-spec-v2.yaml | 4 ---- 9 files changed, 16 insertions(+), 40 deletions(-) diff --git a/internal/adapter/docsui/openapi/ra.yaml b/internal/adapter/docsui/openapi/ra.yaml index 6ae0c5d..109a411 100644 --- a/internal/adapter/docsui/openapi/ra.yaml +++ b/internal/adapter/docsui/openapi/ra.yaml @@ -1525,17 +1525,13 @@ components: RevocationReason: type: string enum: - - UNSPECIFIED - KEY_COMPROMISE - - CA_COMPROMISE - CESSATION_OF_OPERATION - AFFILIATION_CHANGED - SUPERSEDED - CERTIFICATE_HOLD - - REMOVE_FROM_CRL - PRIVILEGE_WITHDRAWN - AA_COMPROMISE - - EXPIRED_CERT AgentRegistrationRequest: type: object diff --git a/internal/domain/status.go b/internal/domain/status.go index 3e450ba..314d222 100644 --- a/internal/domain/status.go +++ b/internal/domain/status.go @@ -139,26 +139,22 @@ const ( type RevocationReason string const ( - RevocationUnspecified RevocationReason = "UNSPECIFIED" RevocationKeyCompromise RevocationReason = "KEY_COMPROMISE" - RevocationCACompromise RevocationReason = "CA_COMPROMISE" RevocationCessationOfOperation RevocationReason = "CESSATION_OF_OPERATION" RevocationAffiliationChanged RevocationReason = "AFFILIATION_CHANGED" RevocationSuperseded RevocationReason = "SUPERSEDED" RevocationCertificateHold RevocationReason = "CERTIFICATE_HOLD" - RevocationRemoveFromCRL RevocationReason = "REMOVE_FROM_CRL" RevocationPrivilegeWithdrawn RevocationReason = "PRIVILEGE_WITHDRAWN" RevocationAACompromise RevocationReason = "AA_COMPROMISE" - RevocationExpiredCert RevocationReason = "EXPIRED_CERT" ) // IsValid returns true if the revocation reason is a recognized value. func (r RevocationReason) IsValid() bool { switch r { - case RevocationUnspecified, RevocationKeyCompromise, RevocationCACompromise, - RevocationCessationOfOperation, RevocationAffiliationChanged, RevocationSuperseded, - RevocationCertificateHold, RevocationRemoveFromCRL, RevocationPrivilegeWithdrawn, - RevocationAACompromise, RevocationExpiredCert: + case RevocationKeyCompromise, RevocationCessationOfOperation, + RevocationAffiliationChanged, RevocationSuperseded, + RevocationCertificateHold, RevocationPrivilegeWithdrawn, + RevocationAACompromise: return true default: return false diff --git a/internal/domain/status_test.go b/internal/domain/status_test.go index 71cd0f2..0f9c94a 100644 --- a/internal/domain/status_test.go +++ b/internal/domain/status_test.go @@ -79,10 +79,10 @@ func TestRegistrationStatus_ValidateTransition(t *testing.T) { func TestRevocationReason_IsValid(t *testing.T) { valid := []RevocationReason{ - RevocationUnspecified, RevocationKeyCompromise, RevocationCACompromise, - RevocationCessationOfOperation, RevocationAffiliationChanged, RevocationSuperseded, - RevocationCertificateHold, RevocationRemoveFromCRL, RevocationPrivilegeWithdrawn, - RevocationAACompromise, RevocationExpiredCert, + RevocationKeyCompromise, RevocationCessationOfOperation, + RevocationAffiliationChanged, RevocationSuperseded, + RevocationCertificateHold, RevocationPrivilegeWithdrawn, + RevocationAACompromise, } for _, r := range valid { assert.True(t, r.IsValid(), "expected %s valid", r) diff --git a/internal/tl/event/event_test.go b/internal/tl/event/event_test.go index 5ce7a53..052d797 100644 --- a/internal/tl/event/event_test.go +++ b/internal/tl/event/event_test.go @@ -124,7 +124,7 @@ func TestEnvelope_Validate_Success(t *testing.T) { func TestEnvelope_Validate_RevocationReasonCode_Valid(t *testing.T) { t.Parallel() env := fixedEnvelope() - env.Payload.Producer.Event.RevocationReasonCode = "CA_COMPROMISE" + env.Payload.Producer.Event.RevocationReasonCode = "AA_COMPROMISE" if err := env.Validate(); err != nil { t.Fatalf("Validate: %v", err) } diff --git a/internal/tl/event/v1/event_test.go b/internal/tl/event/v1/event_test.go index e5fb4a9..5374c00 100644 --- a/internal/tl/event/v1/event_test.go +++ b/internal/tl/event/v1/event_test.go @@ -143,7 +143,7 @@ func TestEnvelope_Validate_Success(t *testing.T) { func TestEnvelope_Validate_RevocationReasonCode_Valid(t *testing.T) { t.Parallel() env := fixedEnvelope() - env.Payload.Producer.Event.RevocationReasonCode = "REMOVE_FROM_CRL" + env.Payload.Producer.Event.RevocationReasonCode = "SUPERSEDED" if err := env.Validate(); err != nil { t.Fatalf("Validate: %v", err) } diff --git a/internal/tl/service/schemas/V0.json b/internal/tl/service/schemas/V0.json index f80878e..9406dcd 100644 --- a/internal/tl/service/schemas/V0.json +++ b/internal/tl/service/schemas/V0.json @@ -256,19 +256,15 @@ "type": "string" }, "revocationReasonCode": { - "description": "RFC 5280 revocation reason code", + "description": "Revocation reason code", "enum": [ "AA_COMPROMISE", "AFFILIATION_CHANGED", - "CA_COMPROMISE", "CERTIFICATE_HOLD", "CESSATION_OF_OPERATION", - "EXPIRED_CERT", "KEY_COMPROMISE", "PRIVILEGE_WITHDRAWN", - "REMOVE_FROM_CRL", - "SUPERSEDED", - "UNSPECIFIED" + "SUPERSEDED" ], "type": "string" } diff --git a/internal/tl/service/schemas/V1.json b/internal/tl/service/schemas/V1.json index 736228b..178f036 100644 --- a/internal/tl/service/schemas/V1.json +++ b/internal/tl/service/schemas/V1.json @@ -189,19 +189,15 @@ "type": "string" }, "revocationReasonCode": { - "description": "RFC 5280 revocation reason code", + "description": "Revocation reason code", "enum": [ "AA_COMPROMISE", "AFFILIATION_CHANGED", - "CA_COMPROMISE", "CERTIFICATE_HOLD", "CESSATION_OF_OPERATION", - "EXPIRED_CERT", "KEY_COMPROMISE", "PRIVILEGE_WITHDRAWN", - "REMOVE_FROM_CRL", - "SUPERSEDED", - "UNSPECIFIED" + "SUPERSEDED" ], "type": "string" }, diff --git a/internal/tl/service/schemas/V2.json b/internal/tl/service/schemas/V2.json index b1d9fc0..0d48783 100644 --- a/internal/tl/service/schemas/V2.json +++ b/internal/tl/service/schemas/V2.json @@ -184,19 +184,15 @@ "type": "string" }, "revocationReasonCode": { - "description": "RFC 5280 revocation reason code", + "description": "Revocation reason code", "enum": [ "AA_COMPROMISE", "AFFILIATION_CHANGED", - "CA_COMPROMISE", "CERTIFICATE_HOLD", "CESSATION_OF_OPERATION", - "EXPIRED_CERT", "KEY_COMPROMISE", "PRIVILEGE_WITHDRAWN", - "REMOVE_FROM_CRL", - "SUPERSEDED", - "UNSPECIFIED" + "SUPERSEDED" ], "type": "string" }, diff --git a/spec/api-spec-v2.yaml b/spec/api-spec-v2.yaml index 6ae0c5d..109a411 100644 --- a/spec/api-spec-v2.yaml +++ b/spec/api-spec-v2.yaml @@ -1525,17 +1525,13 @@ components: RevocationReason: type: string enum: - - UNSPECIFIED - KEY_COMPROMISE - - CA_COMPROMISE - CESSATION_OF_OPERATION - AFFILIATION_CHANGED - SUPERSEDED - CERTIFICATE_HOLD - - REMOVE_FROM_CRL - PRIVILEGE_WITHDRAWN - AA_COMPROMISE - - EXPIRED_CERT AgentRegistrationRequest: type: object From d440e697bd3dbc88eecbcfcfeaf6c9c21b0adcc8 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Wed, 15 Jul 2026 11:13:56 +1000 Subject: [PATCH 13/17] fix: use const for maxCommentsLength Signed-off-by: James Hateley --- internal/ra/handler/v1lifecycle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ra/handler/v1lifecycle.go b/internal/ra/handler/v1lifecycle.go index 036cee5..edd3e3f 100644 --- a/internal/ra/handler/v1lifecycle.go +++ b/internal/ra/handler/v1lifecycle.go @@ -154,7 +154,7 @@ func (h *V1LifecycleHandler) Revoke(w http.ResponseWriter, r *http.Request) { return } - if len(req.Comments) > 200 { + if len(req.Comments) > maxCommentsLength { WriteError(w, domain.NewValidationError("COMMENTS_TOO_LONG", fmt.Sprintf("comments exceeds %d characters", maxCommentsLength))) return From 20acee641ac199967133ceb40548d9a9ebfa87ed Mon Sep 17 00:00:00 2001 From: James Hateley Date: Fri, 17 Jul 2026 10:59:36 +1000 Subject: [PATCH 14/17] fix: revert change to historical json schema Signed-off-by: James Hateley --- internal/tl/service/schemas/V0.json | 6 +++++- internal/tl/service/schemas/V1.json | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/tl/service/schemas/V0.json b/internal/tl/service/schemas/V0.json index 9406dcd..c906987 100644 --- a/internal/tl/service/schemas/V0.json +++ b/internal/tl/service/schemas/V0.json @@ -260,11 +260,15 @@ "enum": [ "AA_COMPROMISE", "AFFILIATION_CHANGED", + "CA_COMPROMISE", "CERTIFICATE_HOLD", "CESSATION_OF_OPERATION", + "EXPIRED_CERT", "KEY_COMPROMISE", "PRIVILEGE_WITHDRAWN", - "SUPERSEDED" + "REMOVE_FROM_CRL", + "SUPERSEDED", + "UNSPECIFIED" ], "type": "string" } diff --git a/internal/tl/service/schemas/V1.json b/internal/tl/service/schemas/V1.json index 178f036..1f053d8 100644 --- a/internal/tl/service/schemas/V1.json +++ b/internal/tl/service/schemas/V1.json @@ -193,11 +193,15 @@ "enum": [ "AA_COMPROMISE", "AFFILIATION_CHANGED", + "CA_COMPROMISE", "CERTIFICATE_HOLD", "CESSATION_OF_OPERATION", + "EXPIRED_CERT", "KEY_COMPROMISE", "PRIVILEGE_WITHDRAWN", - "SUPERSEDED" + "REMOVE_FROM_CRL", + "SUPERSEDED", + "UNSPECIFIED" ], "type": "string" }, From 275391163b78e4c627c8d896f0295298aa84160b Mon Sep 17 00:00:00 2001 From: James Hateley Date: Fri, 17 Jul 2026 11:05:43 +1000 Subject: [PATCH 15/17] fix: optional -> must for server cert in registerAgent description Signed-off-by: James Hateley --- internal/adapter/docsui/openapi/ra.yaml | 2 +- spec/api-spec-v2.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/adapter/docsui/openapi/ra.yaml b/internal/adapter/docsui/openapi/ra.yaml index 297f598..5a62544 100644 --- a/internal/adapter/docsui/openapi/ra.yaml +++ b/internal/adapter/docsui/openapi/ra.yaml @@ -178,7 +178,7 @@ paths: an Identity certificate can be issued. Identity certificates are issued by the RA. - The request can optionally include a server CSR (for RA-issued server cert) + The request must include a server CSR (for RA-issued server cert) or a BYOC server certificate with its chain. operationId: registerAgent requestBody: diff --git a/spec/api-spec-v2.yaml b/spec/api-spec-v2.yaml index 297f598..5a62544 100644 --- a/spec/api-spec-v2.yaml +++ b/spec/api-spec-v2.yaml @@ -178,7 +178,7 @@ paths: an Identity certificate can be issued. Identity certificates are issued by the RA. - The request can optionally include a server CSR (for RA-issued server cert) + The request must include a server CSR (for RA-issued server cert) or a BYOC server certificate with its chain. operationId: registerAgent requestBody: From 938d0d2a4b276e641380a382f44d927800962569 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Fri, 17 Jul 2026 12:17:07 +1000 Subject: [PATCH 16/17] fix: add test for valid statuses Signed-off-by: James Hateley --- internal/ra/handler/lifecycle_test.go | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/ra/handler/lifecycle_test.go b/internal/ra/handler/lifecycle_test.go index bec878b..35dfdce 100644 --- a/internal/ra/handler/lifecycle_test.go +++ b/internal/ra/handler/lifecycle_test.go @@ -140,6 +140,44 @@ func TestList_UnfilterableStatusReturns422(t *testing.T) { } } +func TestList_ValidFilterableStatusesReturn200(t *testing.T) { + t.Parallel() + // The four AgentLifecycleStatusFilter members (spec + // §AgentLifecycleStatusFilter, non-ALL) are each accepted by the + // status filter. A new caller owns nothing, so every valid filter + // resolves to 200 with an empty items list. + for _, status := range []string{"PENDING_DNS", "ACTIVE", "DEPRECATED", "REVOKED"} { + t.Run(status, func(t *testing.T) { + t.Parallel() + fx := newHandlerFixture(t) + rec := fx.request(t, http.MethodGet, "/v2/ans/agents?status="+status, nil, fx.asOwner("alice")) + if rec.Code != http.StatusOK { + t.Fatalf("status=%s want 200, got %d body=%s", status, rec.Code, rec.Body) + } + var resp struct { + Items []any `json:"items"` + } + if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil { + t.Fatalf("unmarshal: %v", err) + } + if len(resp.Items) != 0 { + t.Errorf("new caller should see 0 items; got %d", len(resp.Items)) + } + }) + } +} + +func TestList_MultipleValidStatusesReturn200(t *testing.T) { + t.Parallel() + fx := newHandlerFixture(t) + // Multiple status values combine (OR); all valid → 200. + rec := fx.request(t, http.MethodGet, + "/v2/ans/agents?status=ACTIVE&status=DEPRECATED&status=REVOKED", nil, fx.asOwner("alice")) + if rec.Code != http.StatusOK { + t.Fatalf("want 200, got %d body=%s", rec.Code, rec.Body) + } +} + func TestDetail_OwnedReturns200(t *testing.T) { t.Parallel() fx := newHandlerFixture(t) From a2af16fb49b5ada36d4c472bc22f82bb86935f61 Mon Sep 17 00:00:00 2001 From: James Hateley Date: Fri, 17 Jul 2026 12:35:13 +1000 Subject: [PATCH 17/17] fix: validate revoke comments length in v2 lane Signed-off-by: James Hateley --- internal/ra/handler/lifecycle.go | 8 ++++++++ internal/ra/handler/lifecycle_test.go | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/internal/ra/handler/lifecycle.go b/internal/ra/handler/lifecycle.go index 6476eef..c8bcb1d 100644 --- a/internal/ra/handler/lifecycle.go +++ b/internal/ra/handler/lifecycle.go @@ -3,6 +3,7 @@ package handler import ( "context" "encoding/json" + "fmt" "net/http" "strconv" @@ -380,11 +381,18 @@ func (h *LifecycleHandler) Revoke(w http.ResponseWriter, r *http.Request) { WriteError(w, domain.NewValidationError("BAD_JSON", "invalid request body: "+err.Error())) return } + if req.Reason == "" { WriteError(w, domain.NewValidationError("MISSING_REASON", "reason is required")) return } + if len(req.Comments) > maxCommentsLength { + WriteError(w, domain.NewValidationError("COMMENTS_TOO_LONG", + fmt.Sprintf("comments exceeds %d characters", maxCommentsLength))) + return + } + agentID := chi.URLParam(r, "agentId") res, err := h.svc.Revoke(r.Context(), agentID, service.RevokeInput{ Reason: domain.RevocationReason(req.Reason), diff --git a/internal/ra/handler/lifecycle_test.go b/internal/ra/handler/lifecycle_test.go index 35dfdce..abdaee9 100644 --- a/internal/ra/handler/lifecycle_test.go +++ b/internal/ra/handler/lifecycle_test.go @@ -847,6 +847,24 @@ func TestRevoke_BadReason_422(t *testing.T) { } } +func TestRevoke_CommentsTooLong_422(t *testing.T) { + t.Parallel() + fx := newHandlerFixture(t) + agentID, _ := fx.v1RegisterAgent(t, "alice", "agent.example.com", "1.0.0") + revBody, _ := json.Marshal(map[string]any{ + "reason": "KEY_COMPROMISE", + "comments": strings.Repeat("a", 201), + }) + rec := fx.request(t, http.MethodPost, "/v2/ans/agents/"+agentID+"/revoke", + bytes.NewReader(revBody), fx.asOwner("alice")) + if rec.Code != http.StatusUnprocessableEntity { + t.Fatalf("want 422, got %d body=%s", rec.Code, rec.Body) + } + if !strings.Contains(rec.Body.String(), "COMMENTS_TOO_LONG") { + t.Errorf("expected COMMENTS_TOO_LONG code, got %s", rec.Body) + } +} + func TestRevoke_NotOwnedReturns403(t *testing.T) { t.Parallel() fx := newHandlerFixture(t)