Skip to content

Commit

Permalink
Merge pull request #628 from smacker/fix_permissions_check
Browse files Browse the repository at this point in the history
fix permissions check
  • Loading branch information
smacker authored Apr 12, 2019
2 parents d866389 + d30ed56 commit 6949f7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions provider/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ func (c *Client) Username() (string, error) {
return c.username, nil
}

u, _, err := c.Users.Get(context.Background(), "me")
u, _, err := c.Users.Get(context.Background(), "")
if err != nil {
return "", err
}

c.username = u.GetName()
c.username = u.GetLogin()
return c.username, nil
}

Expand Down Expand Up @@ -490,7 +490,7 @@ func ValidateTokenPermissions(client *Client) error {

// authorizations api can be accessed only with username and password, not token
// read headers of any endpoint instead
_, r, err := client.Users.Get(ctx, "me")
_, r, err := client.Users.Get(ctx, "")
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions provider/github/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ func TestCanPostStatus(t *testing.T) {
require := require.New(t)

mt := roundTripFunc(func(req *http.Request) *http.Response {
fmt.Println(req.URL.Path)
if req.URL.Path == "/users/me" {
b, _ := json.Marshal(&github.User{Name: strptr("test")})
if req.URL.Path == "/user" {
b, _ := json.Marshal(&github.User{Login: strptr("test")})
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewBuffer(b)),
Expand Down Expand Up @@ -279,7 +278,7 @@ func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
// returns correct permissions to pass the permissions checks
func mockPermissions(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/users/me" {
if r.URL.Path == "/user" {
// set headers to pass token checks
w.Header().Add("X-Oauth-Scopes", "repo")
json.NewEncoder(w).Encode(&github.User{})
Expand Down

0 comments on commit 6949f7b

Please sign in to comment.