(t *testing.T)
| 209 | } |
| 210 | |
| 211 | func TestNewAccessRequestWithoutClientAuth(t *testing.T) { |
| 212 | ctrl := gomock.NewController(t) |
| 213 | store := internal.NewMockStorage(ctrl) |
| 214 | handler := internal.NewMockTokenEndpointHandler(ctrl) |
| 215 | handler.EXPECT().CanHandleTokenEndpointRequest(gomock.Any(), gomock.Any()).Return(true).AnyTimes() |
| 216 | handler.EXPECT().CanSkipClientAuth(gomock.Any(), gomock.Any()).Return(true).AnyTimes() |
| 217 | hasher := internal.NewMockHasher(ctrl) |
| 218 | defer ctrl.Finish() |
| 219 | |
| 220 | client := &DefaultClient{} |
| 221 | anotherClient := &DefaultClient{ID: "another"} |
| 222 | config := &Config{ClientSecretsHasher: hasher, AudienceMatchingStrategy: DefaultAudienceMatchingStrategy} |
| 223 | fosite := &Fosite{Store: store, Config: config} |
| 224 | for k, c := range []struct { |
| 225 | header http.Header |
| 226 | form url.Values |
| 227 | mock func() |
| 228 | method string |
| 229 | expectErr error |
| 230 | expect *AccessRequest |
| 231 | handlers TokenEndpointHandlers |
| 232 | }{ |
| 233 | // No grant type -> error |
| 234 | { |
| 235 | form: url.Values{}, |
| 236 | mock: func() { |
| 237 | store.EXPECT().GetClient(gomock.Any(), gomock.Any()).Times(0) |
| 238 | }, |
| 239 | method: "POST", |
| 240 | expectErr: ErrInvalidRequest, |
| 241 | }, |
| 242 | // No registered handlers -> error |
| 243 | { |
| 244 | form: url.Values{ |
| 245 | "grant_type": {"foo"}, |
| 246 | }, |
| 247 | mock: func() { |
| 248 | store.EXPECT().GetClient(gomock.Any(), gomock.Any()).Times(0) |
| 249 | }, |
| 250 | method: "POST", |
| 251 | expectErr: ErrInvalidRequest, |
| 252 | handlers: TokenEndpointHandlers{}, |
| 253 | }, |
| 254 | // Handler can skip client auth and ignores missing client. |
| 255 | { |
| 256 | header: http.Header{ |
| 257 | "Authorization": {basicAuth("foo", "bar")}, |
| 258 | }, |
| 259 | form: url.Values{ |
| 260 | "grant_type": {"foo"}, |
| 261 | }, |
| 262 | mock: func() { |
| 263 | // despite error from storage, we should success, because client auth is not required |
| 264 | store.EXPECT().GetClient(gomock.Any(), "foo").Return(nil, errors.New("no client")).Times(1) |
| 265 | handler.EXPECT().HandleTokenEndpointRequest(gomock.Any(), gomock.Any()).Return(nil) |
| 266 | }, |
| 267 | method: "POST", |
| 268 | expect: &AccessRequest{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…