Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for sub claim, not username, when validating #310

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
GitHub: Fix user info sample used for testing
GitHub doesn't provide username, createdon, lastupdate, or sub in the
user info JSON it returns.
  • Loading branch information
rhansen committed Nov 22, 2021
commit 2efe90c39103be94495574bf0e6dd27120f8385a
22 changes: 10 additions & 12 deletions pkg/providers/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ OR CONDITIONS OF ANY KIND, either express or implied.
package github

import (
"encoding/json"
"net/http"
"regexp"
"testing"
Expand Down Expand Up @@ -166,17 +165,16 @@ func TestGetOrgMembershipStateFromGitHubNoOrgAccess(t *testing.T) {
func TestGetUserInfo(t *testing.T) {
setUp()

userInfoContent, _ := json.Marshal(structs.GitHubUser{
User: structs.User{
Username: "test",
CreatedOn: 123,
Email: "[email protected]",
LastUpdate: 123,
Name: "name",
},
Login: "myusername",
Picture: "avatar-url",
})
// Use JSON directly (instead of populating a struct and converting to JSON) to reduce the chances
// of a mismatch between what GitHub provides and what is expected.
userInfoContent := []byte(`
{
"avatar_url": "avatar-url",
"email": "[email protected]",
"login": "myusername",
"name": "name"
}
`)
mockResponse(urlEquals(cfg.GenOAuth.UserInfoURL+token.AccessToken), http.StatusOK, map[string]string{}, userInfoContent)

cfg.Cfg.TeamWhiteList = append(cfg.Cfg.TeamWhiteList, "myOtherOrg", "myorg/myteam")
Expand Down