(t *testing.T)
| 20 | ) |
| 21 | |
| 22 | func TestNewDeviceRequestWithPublicClient(t *testing.T) { |
| 23 | ctrl := gomock.NewController(t) |
| 24 | store := internal.NewMockStorage(ctrl) |
| 25 | clientManager := internal.NewMockClientManager(ctrl) |
| 26 | deviceClient := &DefaultClient{ID: "client_id"} |
| 27 | deviceClient.Public = true |
| 28 | deviceClient.Scopes = []string{"17", "42"} |
| 29 | deviceClient.Audience = []string{"aud2"} |
| 30 | deviceClient.GrantTypes = []string{"urn:ietf:params:oauth:grant-type:device_code"} |
| 31 | |
| 32 | authCodeClient := &DefaultClient{ID: "client_id_2"} |
| 33 | authCodeClient.Public = true |
| 34 | authCodeClient.Scopes = []string{"17", "42"} |
| 35 | authCodeClient.GrantTypes = []string{"authorization_code"} |
| 36 | |
| 37 | t.Cleanup(ctrl.Finish) |
| 38 | config := &Config{ScopeStrategy: ExactScopeStrategy, AudienceMatchingStrategy: DefaultAudienceMatchingStrategy} |
| 39 | fosite := &Fosite{Store: store, Config: config} |
| 40 | for k, c := range []struct { |
| 41 | header http.Header |
| 42 | form url.Values |
| 43 | method string |
| 44 | expectedError error |
| 45 | mock func() |
| 46 | expect DeviceRequester |
| 47 | description string |
| 48 | }{{ |
| 49 | description: "invalid method", |
| 50 | expectedError: ErrInvalidRequest, |
| 51 | method: "GET", |
| 52 | mock: func() {}, |
| 53 | }, { |
| 54 | description: "empty request", |
| 55 | expectedError: ErrInvalidRequest, |
| 56 | method: "POST", |
| 57 | mock: func() {}, |
| 58 | }, { |
| 59 | description: "invalid client", |
| 60 | form: url.Values{ |
| 61 | "client_id": {"client_id"}, |
| 62 | "scope": {"foo bar"}, |
| 63 | }, |
| 64 | expectedError: ErrInvalidClient, |
| 65 | method: "POST", |
| 66 | mock: func() { |
| 67 | store.EXPECT().FositeClientManager().Return(clientManager).Times(1) |
| 68 | clientManager.EXPECT().GetClient(gomock.Any(), gomock.Eq("client_id")).Return(nil, errors.New("")) |
| 69 | }, |
| 70 | }, { |
| 71 | description: "fails because scope not allowed", |
| 72 | form: url.Values{ |
| 73 | "client_id": {"client_id"}, |
| 74 | "scope": {"17 42 foo"}, |
| 75 | }, |
| 76 | method: "POST", |
| 77 | mock: func() { |
| 78 | store.EXPECT().FositeClientManager().Return(clientManager).Times(1) |
| 79 | clientManager.EXPECT().GetClient(gomock.Any(), gomock.Eq("client_id")).Return(deviceClient, nil) |
nothing calls this directly
no test coverage detected