forked from dexidp/dex
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes dexidp#1102. Github connector returns full team list when no or…
…g specified.
- Loading branch information
Joshua Winters
committed
Feb 6, 2018
1 parent
01d63b0
commit 5e86278
Showing
2 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestUserGroups(t *testing.T) { | ||
|
||
orgs := []org{ | ||
{Login: "org-1"}, | ||
{Login: "org-2"}, | ||
{Login: "org-3"}, | ||
} | ||
|
||
teams := []team{ | ||
{Name: "team-1", Org: org{Login: "org-1"}}, | ||
{Name: "team-2", Org: org{Login: "org-1"}}, | ||
{Name: "team-3", Org: org{Login: "org-1"}}, | ||
{Name: "team-4", Org: org{Login: "org-2"}}, | ||
} | ||
|
||
s := newTestServer(map[string]interface{}{ | ||
"/user/orgs": orgs, | ||
"/user/teams": teams, | ||
}) | ||
|
||
connector := githubConnector{apiURL: s.URL} | ||
groups, err := connector.userGroups(context.Background(), s.Client()) | ||
|
||
expectNil(t, err) | ||
expectEquals(t, groups, []string{ | ||
"org-1:team-1", | ||
"org-1:team-2", | ||
"org-1:team-3", | ||
"org-2:team-4", | ||
"org-3", | ||
}) | ||
|
||
s.Close() | ||
} | ||
|
||
func TestUserGroupsWithoutOrgs(t *testing.T) { | ||
|
||
s := newTestServer(map[string]interface{}{ | ||
"/user/orgs": []org{}, | ||
"/user/teams": []team{}, | ||
}) | ||
|
||
connector := githubConnector{apiURL: s.URL} | ||
groups, err := connector.userGroups(context.Background(), s.Client()) | ||
|
||
expectNil(t, err) | ||
expectEquals(t, len(groups), 0) | ||
|
||
s.Close() | ||
} | ||
|
||
func newTestServer(responses map[string]interface{}) *httptest.Server { | ||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
json.NewEncoder(w).Encode(responses[r.URL.Path]) | ||
})) | ||
} | ||
|
||
func expectNil(t *testing.T, a interface{}) { | ||
if a != nil { | ||
t.Errorf("Expected %+v to equal nil", a) | ||
} | ||
} | ||
|
||
func expectEquals(t *testing.T, a interface{}, b interface{}) { | ||
if !reflect.DeepEqual(a, b) { | ||
t.Errorf("Expected %+v to equal %+v", a, b) | ||
} | ||
} |