MCPcopy Create free account
hub / github.com/docker/go-plugins-helpers / TestAuthZReq

Function TestAuthZReq

authorization/api_test.go:61–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestAuthZReq(t *testing.T) {
62 request := `{"User":"bob","UserAuthNMethod":"","RequestMethod":"POST","RequestURI":"http://127.0.0.1/v.1.23/containers/json","RequestBody":"","RequestHeader":"","RequestStatusCode":""}`
63
64 response, err := http.Post(
65 "http://localhost:32456/AuthZPlugin.AuthZReq",
66 sdk.DefaultContentTypeV1_1,
67 strings.NewReader(request),
68 )
69 if err != nil {
70 t.Fatal(err)
71 }
72
73 defer response.Body.Close()
74
75 body, err := io.ReadAll(response.Body)
76 if err != nil {
77 t.Fatal(err)
78 }
79
80 var r Response
81 if err := json.Unmarshal(body, &r); err != nil {
82 t.Fatal(err)
83 }
84
85 if r.Msg != "You are not authorized" {
86 t.Fatal("Authorization message does not match")
87 }
88
89 if r.Allow {
90 t.Fatal("The request has been allowed while should not be")
91 }
92
93 if r.Err != "" {
94 t.Fatal("Authorization Error should be empty")
95 }
96}
97
98func TestAuthZRes(t *testing.T) {
99 request := `{"User":"bob","UserAuthNMethod":"","RequestMethod":"POST","RequestURI":"http://127.0.0.1/v.1.23/containers/json","RequestBody":"","RequestHeader":"","RequestStatusCode":"", "ResponseBody":"","ResponseHeader":"","ResponseStatusCode":200}`

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…