This is an automated email from the ASF dual-hosted git repository. lahirujayathilake pushed a commit to branch custos-apps in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 20b1d3b264aafeae31d32a54d6b3ef32d42956cf Author: lahiruj <[email protected]> AuthorDate: Tue Nov 10 02:14:23 2026 -0500 Add app routes to the signer connector --- connectors/Signer/README.md | 16 +++ connectors/Signer/internal/app_handlers.go | 121 ++++++++++++++++++++ connectors/Signer/internal/app_handlers_test.go | 140 ++++++++++++++++++++++++ connectors/Signer/internal/handlers.go | 76 ++++++++----- connectors/Signer/internal/handlers_test.go | 20 ++++ connectors/Signer/pkg/signer/loader.go | 6 + pkg/service/app.go | 2 +- pkg/service/app_integration_test.go | 6 +- 8 files changed, 357 insertions(+), 30 deletions(-) diff --git a/connectors/Signer/README.md b/connectors/Signer/README.md index 950cfebd2..44c3fef4d 100644 --- a/connectors/Signer/README.md +++ b/connectors/Signer/README.md @@ -49,6 +49,22 @@ A refusal has an `error` code: `user_not_active`, `no_cluster_account`, `cluster `no_active_allocation`, `signer_unavailable`, or from the signer `reserved_username`, `invalid_public_key` and `key_type_not_allowed`. +## App routes + +An app signs in with its token and can use only these routes. It never holds the privileges above. + +| Route | Action | Does | +|------------------------------------------------------------|-----------------------------------|-------------------------------------------------------| +| `POST /connectors/signer/app/certificates` | `signer:app:generate-certificate` | Generate a certificate for the user in `user_email` | +| `GET /connectors/signer/app/certificates` | `signer:app:generate-certificate` | The certificates this app requested | +| `GET /connectors/signer/app/certificates/{serial}` | `signer:app:generate-certificate` | One certificate this app requested | +| `POST /connectors/signer/app/certificates/{serial}/revoke` | `signer:app:revoke-certificate` | Revoke one this app requested, recorded under the app | + +Generate takes `user_email`, `public_key` and an optional `source_address`. Every certificate records `app/<key>` as who +asked. The user must be active, have accepted the current user agreement, have signed in to Custos at least once, and +pass the same account and allocation checks as above. Besides the codes above, an app can get `user_not_found`, +`consent_required` and `user_not_signed_in`. + ## Configuration Settings are in the `connectors.signer` block of [`config/custos.yaml`](../../config/custos.yaml). When a required diff --git a/connectors/Signer/internal/app_handlers.go b/connectors/Signer/internal/app_handlers.go new file mode 100644 index 000000000..95443bbe0 --- /dev/null +++ b/connectors/Signer/internal/app_handlers.go @@ -0,0 +1,121 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package internal + +import ( + "encoding/json" + "errors" + "net/http" + + "github.com/apache/airavata-custos/pkg/identity" + "github.com/apache/airavata-custos/pkg/models" + "github.com/apache/airavata-custos/pkg/service" +) + +const ( + AppActionGenerateCertificate = "signer:app:generate-certificate" + AppActionRevokeCertificate = "signer:app:revoke-certificate" +) + +func appRequestedBy(r *http.Request) string { + return "app/" + identity.CallerFromContext(r.Context()).AppKey +} + +func (h *Handlers) generateCertificateForApp(w http.ResponseWriter, r *http.Request) { + var req struct { + UserEmail string `json:"user_email"` + PublicKey string `json:"public_key"` + SourceAddress string `json:"source_address"` + } + if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, maxRequestBytes)).Decode(&req); err != nil || req.PublicKey == "" { + refuse(w, http.StatusBadRequest, "invalid_public_key", "A public key is required") + return + } + user, subject, ok := h.requireEligibleUser(w, r, req.UserEmail) + if !ok { + return + } + h.issueCertificate(w, r, user.ID, map[string]any{ + "public_key": req.PublicKey, + "user_email": user.Email, + "user_sub": subject, + "requested_by": appRequestedBy(r), + "source_address": req.SourceAddress, + }) +} + +// requireEligibleUser checks the user for the app which is asking certificates for. These are the checks a user passes at login, and an app call does not go through that. +// TODO - move to core when another connector needs these checks +func (h *Handlers) requireEligibleUser(w http.ResponseWriter, r *http.Request, email string) (*models.User, string, bool) { + user, err := h.core.GetUserByEmail(r.Context(), email) + if errors.Is(err, service.ErrNotFound) { + refuse(w, http.StatusNotFound, "user_not_found", "No user has this email") + return nil, "", false + } + if err != nil { + accountReadFailed(w, err) + return nil, "", false + } + if user.Status != models.UserActive { + refuse(w, http.StatusForbidden, "user_not_active", "This user is not active") + return nil, "", false + } + pending, err := h.core.PendingUserAgreements(r.Context(), user.ID) + if err != nil { + accountReadFailed(w, err) + return nil, "", false + } + if len(pending) > 0 { + refuse(w, http.StatusForbidden, "consent_required", "The user must accept the user agreement first") + return nil, "", false + } + identities, err := h.core.ListUserIdentitiesForUser(r.Context(), user.ID) + if err != nil { + accountReadFailed(w, err) + return nil, "", false + } + for _, linked := range identities { + if linked.OIDCSub != "" { + return user, linked.OIDCSub, true + } + } + refuse(w, http.StatusForbidden, "user_not_signed_in", "This user has not signed in to Custos yet") + return nil, "", false +} + +func (h *Handlers) listCertificatesForApp(w http.ResponseWriter, r *http.Request) { + query := r.URL.Query() + query.Set("requested_by", appRequestedBy(r)) + h.relay(w, r, http.MethodGet, "/api/v1/certificates?"+query.Encode(), nil) +} + +func (h *Handlers) fetchAppsCertificate(w http.ResponseWriter, r *http.Request) ([]byte, bool) { + return h.fetchIfOwned(w, r, func(c certificateOwner) bool { return c.RequestedBy == appRequestedBy(r) }) +} + +func (h *Handlers) getCertificateForApp(w http.ResponseWriter, r *http.Request) { + if body, ok := h.fetchAppsCertificate(w, r); ok { + writeCertificate(w, body) + } +} + +func (h *Handlers) revokeCertificateForApp(w http.ResponseWriter, r *http.Request) { + if _, ok := h.fetchAppsCertificate(w, r); ok { + h.revoke(w, r, appRequestedBy(r)) + } +} diff --git a/connectors/Signer/internal/app_handlers_test.go b/connectors/Signer/internal/app_handlers_test.go new file mode 100644 index 000000000..3363f730a --- /dev/null +++ b/connectors/Signer/internal/app_handlers_test.go @@ -0,0 +1,140 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package internal + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/apache/airavata-custos/pkg/identity" + "github.com/apache/airavata-custos/pkg/models" +) + +const appCertificates = "/connectors/signer/app/certificates" + +func serveAsApp(core CoreAccounts, baseURL string, r *http.Request, actions ...string) *httptest.ResponseRecorder { + mux := http.NewServeMux() + NewHandlers(Config{BaseURL: baseURL, ServiceToken: "service-token", ClusterID: testClusterID, TTLSeconds: 3600, Timeout: 2 * time.Second}, core).RegisterRoutes(identity.NewRouter(mux)) + r = r.WithContext(identity.WithCaller(r.Context(), &identity.Caller{AppID: "app-uuid", AppKey: "test-gateway", AppActions: actions})) + rec := httptest.NewRecorder() + mux.ServeHTTP(rec, r) + return rec +} + +// Make sure the certificate is for the named user's own cluster account and says which app asked, whatever else the app sends. +func TestGenerateForApp_SignsForTheNamedUser(t *testing.T) { + srv, seen := mockSignerServer(t, http.StatusOK, `{}`) + + body := `{"user_email":"[email protected]","public_key":"ssh-ed25519 AAAA","source_address":"203.0.113.0/24","principal":"root","requested_by":"user/someone"}` + rec := serveAsApp(readyCore(), srv.URL, httptest.NewRequest(http.MethodPost, appCertificates, strings.NewReader(body)), AppActionGenerateCertificate) + + if rec.Code != http.StatusOK || seen.path != "/api/v1/sign" { + t.Fatalf("got %d, signer saw %+v", rec.Code, *seen) + } + var sent map[string]any + if err := json.Unmarshal([]byte(seen.body), &sent); err != nil { + t.Fatal(err) + } + if sent["principal"] != "jdoe" || sent["user_email"] != "[email protected]" || sent["user_sub"] != testSub { + t.Fatalf("signer got %v", sent) + } + if sent["requested_by"] != "app/test-gateway" || sent["source_address"] != "203.0.113.0/24" { + t.Fatalf("signer got %v", sent) + } +} + +// Make sure an app cannot get a certificate for a user who could not get one themselves. +func TestGenerateForApp_RefusesUserWhoCannotHaveACertificate(t *testing.T) { + cases := []struct { + name string + change func(*fakeCore) + status int + code string + }{ + {"unknown email", func(c *fakeCore) { c.user = nil }, http.StatusNotFound, "user_not_found"}, + {"suspended user", func(c *fakeCore) { c.user.Status = models.UserSuspended }, http.StatusForbidden, "user_not_active"}, + {"pending user agreement", func(c *fakeCore) { c.pending = []models.UserAgreement{{ID: "a1"}} }, http.StatusForbidden, "consent_required"}, + {"never signed in", func(c *fakeCore) { c.identities = nil }, http.StatusForbidden, "user_not_signed_in"}, + {"no cluster account", func(c *fakeCore) { c.account = nil }, http.StatusForbidden, "no_cluster_account"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + srv, seen := mockSignerServer(t, http.StatusOK, `{}`) + core := readyCore() + tc.change(core) + + body := `{"user_email":"[email protected]","public_key":"k"}` + rec := serveAsApp(core, srv.URL, httptest.NewRequest(http.MethodPost, appCertificates, strings.NewReader(body)), AppActionGenerateCertificate) + + if rec.Code != tc.status || errorCode(t, rec) != tc.code || seen.path != "" { + t.Fatalf("got %d %s, signer saw %q", rec.Code, rec.Body, seen.path) + } + }) + } +} + +// Make sure an app's list only ever holds what it requested, whatever filter it sends. +func TestListForApp_AlwaysFiltersToTheApp(t *testing.T) { + srv, seen := mockSignerServer(t, http.StatusOK, `{"certificates":[]}`) + + serveAsApp(readyCore(), srv.URL, httptest.NewRequest(http.MethodGet, appCertificates+"?requested_by=app/other&limit=5", nil), AppActionGenerateCertificate) + + if seen.query != "limit=5&requested_by=app%2Ftest-gateway" { + t.Fatalf("signer got query %q", seen.query) + } +} + +// Make sure an app cannot see or revoke a certificate that another app or a user requested. +func TestAppRoutes_HideCertificatesTheAppDidNotRequest(t *testing.T) { + for _, requester := range []string{"app/other", "user/user-1"} { + srv, seen := mockSignerServer(t, http.StatusOK, `{"requested_by":"`+requester+`"}`) + + get := serveAsApp(readyCore(), srv.URL, httptest.NewRequest(http.MethodGet, appCertificates+"/42", nil), AppActionGenerateCertificate) + revoke := serveAsApp(readyCore(), srv.URL, httptest.NewRequest(http.MethodPost, appCertificates+"/42/revoke", strings.NewReader(`{}`)), AppActionRevokeCertificate) + + if get.Code != http.StatusNotFound || revoke.Code != http.StatusNotFound || strings.HasSuffix(seen.path, "/revoke") { + t.Fatalf("%s: get %d, revoke %d, signer saw %q", requester, get.Code, revoke.Code, seen.path) + } + } +} + +// Make sure a revoke by an app is recorded under the app. +func TestRevokeForApp_RecordedAsTheApp(t *testing.T) { + srv, seen := mockSignerServer(t, http.StatusOK, `{"requested_by":"app/test-gateway"}`) + + serveAsApp(readyCore(), srv.URL, httptest.NewRequest(http.MethodPost, appCertificates+"/42/revoke", strings.NewReader(`{"reason":"rotated"}`)), AppActionRevokeCertificate) + + if !strings.Contains(seen.body, `"revoked_by":"app/test-gateway"`) || !strings.HasSuffix(seen.path, "/revoke") { + t.Fatalf("signer saw %+v", *seen) + } +} + +// Make sure an app only with the revoke action cannot generate a certificate. +func TestAppRoutes_NeedTheirOwnAction(t *testing.T) { + srv, seen := mockSignerServer(t, http.StatusOK, `{}`) + + rec := serveAsApp(readyCore(), srv.URL, httptest.NewRequest(http.MethodPost, appCertificates, strings.NewReader(`{"public_key":"k"}`)), AppActionRevokeCertificate) + + if rec.Code != http.StatusForbidden || seen.path != "" { + t.Fatalf("got %d, signer saw %q", rec.Code, seen.path) + } +} diff --git a/connectors/Signer/internal/handlers.go b/connectors/Signer/internal/handlers.go index 3b95bfbe5..0ef8b5427 100644 --- a/connectors/Signer/internal/handlers.go +++ b/connectors/Signer/internal/handlers.go @@ -48,6 +48,9 @@ type CoreAccounts interface { GetComputeClusterUserByPair(ctx context.Context, clusterID, userID string) (*models.ComputeClusterUser, error) ListAllocationsForUser(ctx context.Context, userID string) ([]models.ComputeAllocationMembership, error) GetComputeAllocation(ctx context.Context, id string) (*models.ComputeAllocation, error) + GetUserByEmail(ctx context.Context, email string) (*models.User, error) + PendingUserAgreements(ctx context.Context, userID string) ([]models.UserAgreement, error) + ListUserIdentitiesForUser(ctx context.Context, userID string) ([]models.UserIdentity, error) } type Config struct { @@ -78,6 +81,10 @@ func (h *Handlers) RegisterRoutes(router *identity.Router) { router.RequireAuth("GET /connectors/signer/me/certificates/{serial}", h.getOwnCertificate) router.RequireAuth("POST /connectors/signer/me/certificates/{serial}/revoke", h.revokeOwnCertificate) router.RequirePrivilege("GET /connectors/signer/status", CertificatesRead, h.status) + router.RequireApp("POST /connectors/signer/app/certificates", AppActionGenerateCertificate, h.generateCertificateForApp) + router.RequireApp("GET /connectors/signer/app/certificates", AppActionGenerateCertificate, h.listCertificatesForApp) + router.RequireApp("GET /connectors/signer/app/certificates/{serial}", AppActionGenerateCertificate, h.getCertificateForApp) + router.RequireApp("POST /connectors/signer/app/certificates/{serial}/revoke", AppActionRevokeCertificate, h.revokeCertificateForApp) } func refuse(w http.ResponseWriter, status int, code, message string) { @@ -163,7 +170,7 @@ func (h *Handlers) revokeAnyCertificate(w http.ResponseWriter, r *http.Request) } } -// revokedBy is the admin's email, or "self" when users revoke their own. +// revokedBy is the admin's email, the app, or "self" when users revoke their own. func (h *Handlers) revoke(w http.ResponseWriter, r *http.Request, revokedBy string) { var req struct { Reason string `json:"reason"` @@ -185,12 +192,13 @@ func (h *Handlers) listOwnCertificates(w http.ResponseWriter, r *http.Request) { h.relay(w, r, http.MethodGet, "/api/v1/certificates?"+query.Encode(), nil) } +type certificateOwner struct { + UserSub string `json:"user_sub"` + RequestedBy string `json:"requested_by"` +} + // fetchIfOwned extracts own certificate from the Signer and returns false if it is not the caller's. -func (h *Handlers) fetchIfOwned(w http.ResponseWriter, r *http.Request) ([]byte, bool) { - claims := requireClaims(w, r) - if claims == nil { - return nil, false - } +func (h *Handlers) fetchIfOwned(w http.ResponseWriter, r *http.Request, owned func(certificateOwner) bool) ([]byte, bool) { resp, err := h.callSigner(r.Context(), http.MethodGet, certificatePath(r), nil) if err != nil { signerUnavailable(w) @@ -206,31 +214,39 @@ func (h *Handlers) fetchIfOwned(w http.ResponseWriter, r *http.Request) ([]byte, signerUnavailable(w) return nil, false } - var certificate struct { - UserSub string `json:"user_sub"` - } + var certificate certificateOwner if err := json.Unmarshal(body, &certificate); err != nil { signerUnavailable(w) return nil, false } - if certificate.UserSub != claims.Sub { + if !owned(certificate) { refuse(w, http.StatusNotFound, "not_found", "Certificate not found") return nil, false } return body, true } -func (h *Handlers) getOwnCertificate(w http.ResponseWriter, r *http.Request) { - body, ok := h.fetchIfOwned(w, r) - if !ok { - return +func (h *Handlers) fetchUsersCertificate(w http.ResponseWriter, r *http.Request) ([]byte, bool) { + claims := requireClaims(w, r) + if claims == nil { + return nil, false } + return h.fetchIfOwned(w, r, func(c certificateOwner) bool { return c.UserSub == claims.Sub }) +} + +func writeCertificate(w http.ResponseWriter, body []byte) { w.Header().Set("Content-Type", "application/json") w.Write(body) } +func (h *Handlers) getOwnCertificate(w http.ResponseWriter, r *http.Request) { + if body, ok := h.fetchUsersCertificate(w, r); ok { + writeCertificate(w, body) + } +} + func (h *Handlers) revokeOwnCertificate(w http.ResponseWriter, r *http.Request) { - if _, ok := h.fetchIfOwned(w, r); ok { + if _, ok := h.fetchUsersCertificate(w, r); ok { h.revoke(w, r, "self") } } @@ -248,24 +264,32 @@ func (h *Handlers) generateCertificate(w http.ResponseWriter, r *http.Request) { refuse(w, http.StatusBadRequest, "invalid_public_key", "A public key is required") return } + h.issueCertificate(w, r, userID, map[string]any{ + "public_key": req.PublicKey, + "user_email": claims.Email, + "user_sub": claims.Sub, + "requested_by": "user/" + userID, + }) +} + +func accountReadFailed(w http.ResponseWriter, err error) { + slog.Error("signer: reading the account failed", "error", err) + refuse(w, http.StatusInternalServerError, "internal_error", "Could not read the account") +} + +func (h *Handlers) issueCertificate(w http.ResponseWriter, r *http.Request, userID string, sign map[string]any) { username, code, err := h.loginName(r.Context(), userID) if err != nil { - slog.Error("signer: reading the caller's account failed", "error", err) - refuse(w, http.StatusInternalServerError, "internal_error", "Could not read your account") + accountReadFailed(w, err) return } if code != "" { - refuse(w, http.StatusForbidden, code, "Your account cannot generate a certificate") + refuse(w, http.StatusForbidden, code, "This account cannot generate a certificate") return } - h.relay(w, r, http.MethodPost, "/api/v1/sign", map[string]any{ - "principal": username, - "public_key": req.PublicKey, - "ttl_seconds": h.cfg.TTLSeconds, - "user_email": claims.Email, - "user_sub": claims.Sub, - "requested_by": "user/" + userID, - }) + sign["principal"] = username + sign["ttl_seconds"] = h.cfg.TTLSeconds + h.relay(w, r, http.MethodPost, "/api/v1/sign", sign) } // loginName returns the username to sign for. diff --git a/connectors/Signer/internal/handlers_test.go b/connectors/Signer/internal/handlers_test.go index 1999fd765..a1cce21ee 100644 --- a/connectors/Signer/internal/handlers_test.go +++ b/connectors/Signer/internal/handlers_test.go @@ -67,6 +67,24 @@ type fakeCore struct { account *models.ComputeClusterUser memberships []models.ComputeAllocationMembership allocation models.ComputeAllocation + user *models.User + pending []models.UserAgreement + identities []models.UserIdentity +} + +func (f *fakeCore) GetUserByEmail(context.Context, string) (*models.User, error) { + if f.user == nil { + return nil, service.ErrNotFound + } + return f.user, nil +} + +func (f *fakeCore) PendingUserAgreements(context.Context, string) ([]models.UserAgreement, error) { + return f.pending, nil +} + +func (f *fakeCore) ListUserIdentitiesForUser(context.Context, string) ([]models.UserIdentity, error) { + return f.identities, nil } func (f *fakeCore) GetComputeClusterUserByPair(context.Context, string, string) (*models.ComputeClusterUser, error) { @@ -92,6 +110,8 @@ func readyCore() *fakeCore { account: &models.ComputeClusterUser{LocalUsername: "jdoe", ApprovalStatus: models.ClusterAccountApproved, ProvisionedAt: &provisioned}, memberships: []models.ComputeAllocationMembership{{ComputeAllocationID: "a1", MembershipStatus: models.ACTIVE, StartTime: start, EndTime: end}}, allocation: models.ComputeAllocation{ComputeClusterID: testClusterID, Status: models.ACTIVE, StartTime: start, EndTime: end}, + user: &models.User{ID: "user-1", Email: "[email protected]", Status: models.UserActive}, + identities: []models.UserIdentity{{OIDCSub: testSub}}, } } diff --git a/connectors/Signer/pkg/signer/loader.go b/connectors/Signer/pkg/signer/loader.go index 521c1f1bf..230d0895d 100644 --- a/connectors/Signer/pkg/signer/loader.go +++ b/connectors/Signer/pkg/signer/loader.go @@ -31,6 +31,7 @@ import ( "github.com/apache/airavata-custos/internal/connectors/health" "github.com/apache/airavata-custos/pkg/events" "github.com/apache/airavata-custos/pkg/identity" + "github.com/apache/airavata-custos/pkg/models" "github.com/apache/airavata-custos/pkg/service" ) @@ -62,6 +63,11 @@ func LoadConnector(ctx context.Context, _ *sqlx.DB, _ *events.Bus, core *service TTLSeconds: ttl, Timeout: time.Duration(timeout) * time.Second, }, core) + models.RegisterAppConnector(models.AppConnector{ + Name: Type, + NeedsUserGrant: true, + Actions: []string{internal.AppActionGenerateCertificate, internal.AppActionRevokeCertificate}, + }) handlers.RegisterRoutes(router) // In the background so a down signer does not hold up startup. go handlers.CheckHealth(ctx) diff --git a/pkg/service/app.go b/pkg/service/app.go index 5f772066f..34994fe84 100644 --- a/pkg/service/app.go +++ b/pkg/service/app.go @@ -206,7 +206,7 @@ func (s *Service) IssueAppSecret(ctx context.Context, id, actorID string) (*mode func (s *Service) ResolveApp(ctx context.Context, token string) (*identity.Caller, error) { key, secret, ok := strings.Cut(strings.TrimPrefix(token, identity.AppTokenPrefix), ".") - if !ok { + if !ok || validateAppKey(key) != nil { return nil, identity.ErrInvalidAppToken } a, err := s.apps.FindByKey(ctx, key) diff --git a/pkg/service/app_integration_test.go b/pkg/service/app_integration_test.go index 5e93c7f76..209817338 100644 --- a/pkg/service/app_integration_test.go +++ b/pkg/service/app_integration_test.go @@ -83,13 +83,13 @@ func TestApp_TokenAuthenticatesAndSecretIsNotStored(t *testing.T) { } } -// Make sure a token with the right app key but a wrong or missing secret is refused. -func TestApp_WrongSecretIsRefused(t *testing.T) { +// Make sure a token with a wrong or missing secret, or a malformed app key, is refused. +func TestApp_BadTokenIsRefused(t *testing.T) { database := setupTestDB(t) svc := newTestService(database) newTestApp(t, svc, seedAppAdmin(t, database)) - for _, token := range []string{identity.AppTokenPrefix + "test-gateway.wrong", identity.AppTokenPrefix + "test-gateway"} { + for _, token := range []string{identity.AppTokenPrefix + "test-gateway.wrong", identity.AppTokenPrefix + "test-gateway", identity.AppTokenPrefix + "\xff.secret"} { if _, err := svc.ResolveApp(ctx(), token); !errors.Is(err, identity.ErrInvalidAppToken) { t.Errorf("%s: got %v", token, err) }
