MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / TestTokenCreate_ScopesPostedAsJSONArray

Function TestTokenCreate_ScopesPostedAsJSONArray

cmd/pad/cmd_token_test.go:229–259  ·  view source on GitHub ↗

--scopes values are validated locally and posted as the JSON array the server's tokenScopeAllows requires — the raw string was stored verbatim before, minting a token every request refused (#1237 review).

(t *testing.T)

Source from the content-addressed store, hash-verified

227// server's tokenScopeAllows requires — the raw string was stored verbatim
228// before, minting a token every request refused (#1237 review).
229func TestTokenCreate_ScopesPostedAsJSONArray(t *testing.T) {
230 srv := setupTokenEnv(t)
231
232 cases := []struct {
233 flag string
234 want string
235 }{
236 {"read", `["read"]`},
237 {"read,write", `["read","write"]`},
238 {" pad:read , pad:write ", `["pad:read","pad:write"]`},
239 {"*", `["*"]`},
240 }
241 for i, tc := range cases {
242 cmd := tokenCreateCmd()
243 cmd.SetArgs([]string{"--name", "scoped", "--scopes", tc.flag})
244 var runErr error
245 captureStdout(t, func() {
246 runErr = cmd.Execute()
247 })
248 if runErr != nil {
249 t.Fatalf("token create --scopes %q: %v", tc.flag, runErr)
250 }
251 if len(srv.createBodies) != i+1 {
252 t.Fatalf("expected %d POSTs after case %q, got %d", i+1, tc.flag, len(srv.createBodies))
253 }
254 got, _ := srv.createBodies[i]["scopes"].(string)
255 if got != tc.want {
256 t.Errorf("--scopes %q posted scopes %q, want %q", tc.flag, got, tc.want)
257 }
258 }
259}
260
261// A scope outside the server's vocabulary is refused locally, naming the
262// allowed values, before any request — the server would store it verbatim

Callers

nothing calls this directly

Calls 4

setupTokenEnvFunction · 0.85
tokenCreateCmdFunction · 0.85
captureStdoutFunction · 0.85
FatalfMethod · 0.80

Tested by

no test coverage detected