MCPcopy Create free account
hub / github.com/pace/bricks / TestAuthenticationSuccessScopeError

Function TestAuthenticationSuccessScopeError

http/oauth2/oauth2_test.go:162–191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func TestAuthenticationSuccessScopeError(t *testing.T) {
163 auth := NewAuthorizer(&tokenIntrospectedSuccessful{&IntrospectResponse{
164 Active: true,
165 Scope: "ABC DEF DFE",
166 ClientID: "ClientId",
167 UserID: "UserId",
168 }}, &Config{}).WithScope("DE")
169
170 w := httptest.NewRecorder()
171 r := httptest.NewRequest("GET", "/", nil)
172 r.Header.Add("Authorization", "Bearer bearer")
173
174 _, b := auth.Authorize(r, w)
175
176 resp := w.Result()
177 body, err := io.ReadAll(resp.Body)
178 defer resp.Body.Close()
179 if err != nil {
180 t.Fatal(err)
181 }
182 if b {
183 t.Errorf("Expected error in Authentication, but was succesfull with code %d and body %v", resp.StatusCode, string(body))
184 }
185 if got, ex := w.Code, http.StatusForbidden; got != ex {
186 t.Errorf("Expected status code %d, got %d", ex, got)
187 }
188 if got, ex := string(body), "Forbidden - requires scope \"DE\"\n"; got != ex {
189 t.Errorf("Expected status code %q, got %q", ex, got)
190 }
191}
192
193func TestAuthenticationWithErrors(t *testing.T) {
194 testCases := []struct {

Callers

nothing calls this directly

Calls 7

WithScopeMethod · 0.80
CloseMethod · 0.80
FatalMethod · 0.80
ErrorfMethod · 0.80
NewAuthorizerFunction · 0.70
AddMethod · 0.65
AuthorizeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…