(t *testing.T)
| 164 | } |
| 165 | |
| 166 | func TestGetUserInfo(t *testing.T) { |
| 167 | setUp() |
| 168 | |
| 169 | userInfoContent, _ := json.Marshal(structs.GitHubUser{ |
| 170 | User: structs.User{ |
| 171 | Username: "test", |
| 172 | CreatedOn: 123, |
| 173 | Email: "email@example.com", |
| 174 | ID: 1, |
| 175 | LastUpdate: 123, |
| 176 | Name: "name", |
| 177 | }, |
| 178 | Login: "myusername", |
| 179 | Picture: "avatar-url", |
| 180 | }) |
| 181 | mockResponse(urlEquals(cfg.GenOAuth.UserInfoURL), http.StatusOK, map[string]string{}, userInfoContent) |
| 182 | |
| 183 | cfg.Cfg.TeamWhiteList = append(cfg.Cfg.TeamWhiteList, "myOtherOrg", "myorg/myteam") |
| 184 | |
| 185 | mockResponse(regexMatcher(".*teams.*"), http.StatusOK, map[string]string{}, []byte("{\"state\": \"active\"}")) |
| 186 | mockResponse(regexMatcher(".*members.*"), http.StatusNoContent, map[string]string{}, []byte("")) |
| 187 | |
| 188 | provider := Provider{PrepareTokensAndClient: func(_ *http.Request, _ *structs.PTokens, _ bool, opts ...oauth2.AuthCodeOption) (*http.Client, *oauth2.Token, error) { |
| 189 | return client, token, nil |
| 190 | }} |
| 191 | err := provider.GetUserInfo(nil, user, &structs.CustomClaims{}, &structs.PTokens{}) |
| 192 | |
| 193 | assert.Nil(t, err) |
| 194 | assert.Equal(t, "myusername", user.Username) |
| 195 | assert.Equal(t, []string{"myOtherOrg", "myorg/myteam"}, user.TeamMemberships) |
| 196 | |
| 197 | expectedTeamMembershipURL := "https://api.github.com/orgs/myorg/teams/myteam/memberships/myusername" |
| 198 | assertURLCalled(t, expectedTeamMembershipURL) |
| 199 | } |
nothing calls this directly
no test coverage detected