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

Function TestAuthZRes

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

Source from the content-addressed store, hash-verified

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}`
100
101 response, err := http.Post(
102 "http://localhost:32456/AuthZPlugin.AuthZRes",
103 sdk.DefaultContentTypeV1_1,
104 strings.NewReader(request),
105 )
106 if err != nil {
107 t.Fatal(err)
108 }
109
110 defer response.Body.Close()
111
112 body, err := io.ReadAll(response.Body)
113 if err != nil {
114 t.Fatal(err)
115 }
116
117 var r Response
118 if err := json.Unmarshal(body, &r); err != nil {
119 t.Fatal(err)
120 }
121
122 if r.Msg != "You are not authorized" {
123 t.Fatal("Authorization message does not match")
124 }
125
126 if r.Allow {
127 t.Fatal("The request has been allowed while should not be")
128 }
129
130 if r.Err != "" {
131 t.Fatal("Authorization Error should be empty")
132 }
133}
134
135func TestPeerCertificateMarshalJSON(t *testing.T) {
136 template := &x509.Certificate{

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…