Skip to content

fix permissions check #628

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

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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