9 "github.com/bmizerany/assert"
12func testGitLabProvider(hostname string) *GitLabProvider {
13 p := NewGitLabProvider(
17 RedeemURL: &url.URL{},
18 ProfileURL: &url.URL{},
19 ValidateURL: &url.URL{},
22 updateURL(p.Data().LoginURL, hostname)
23 updateURL(p.Data().RedeemURL, hostname)
24 updateURL(p.Data().ProfileURL, hostname)
25 updateURL(p.Data().ValidateURL, hostname)
30func testGitLabBackend(payload string) *httptest.Server {
31 path := "/api/v3/user"
32 query := "access_token=imaginary_access_token"
34 return httptest.NewServer(http.HandlerFunc(
35 func(w http.ResponseWriter, r *http.Request) {
37 if url.Path != path || url.RawQuery != query {
41 w.Write([]byte(payload))
46func TestGitLabProviderDefaults(t *testing.T) {
47 p := testGitLabProvider("")
48 assert.NotEqual(t, nil, p)
49 assert.Equal(t, "GitLab", p.Data().ProviderName)
50 assert.Equal(t, "https://gitlab.com/oauth/authorize",
51 p.Data().LoginURL.String())
52 assert.Equal(t, "https://gitlab.com/oauth/token",
53 p.Data().RedeemURL.String())
54 assert.Equal(t, "https://gitlab.com/api/v3/user",
55 p.Data().ValidateURL.String())
56 assert.Equal(t, "api", p.Data().Scope)
59func TestGitLabProviderOverrides(t *testing.T) {
60 p := NewGitLabProvider(
69 Path: "/oauth/token"},
70 ValidateURL: &url.URL{
73 Path: "/api/v3/user"},
75 assert.NotEqual(t, nil, p)
76 assert.Equal(t, "GitLab", p.Data().ProviderName)
77 assert.Equal(t, "https://example.com/oauth/auth",
78 p.Data().LoginURL.String())
79 assert.Equal(t, "https://example.com/oauth/token",
80 p.Data().RedeemURL.String())
81 assert.Equal(t, "https://example.com/api/v3/user",
82 p.Data().ValidateURL.String())
83 assert.Equal(t, "profile", p.Data().Scope)
86func TestGitLabProviderGetEmailAddress(t *testing.T) {
87 b := testGitLabBackend("{\"email\": \"michael.bland@gsa.gov\"}")
90 b_url, _ := url.Parse(b.URL)
91 p := testGitLabProvider(b_url.Host)
93 session := &SessionState{AccessToken: "imaginary_access_token"}
94 email, err := p.GetEmailAddress(session)
95 assert.Equal(t, nil, err)
96 assert.Equal(t, "michael.bland@gsa.gov", email)
99// Note that trying to trigger the "failed building request" case is not
100// practical, since the only way it can fail is if the URL fails to parse.
101func TestGitLabProviderGetEmailAddressFailedRequest(t *testing.T) {
102 b := testGitLabBackend("unused payload")
105 b_url, _ := url.Parse(b.URL)
106 p := testGitLabProvider(b_url.Host)
108 // We'll trigger a request failure by using an unexpected access
109 // token. Alternatively, we could allow the parsing of the payload as
111 session := &SessionState{AccessToken: "unexpected_access_token"}
112 email, err := p.GetEmailAddress(session)
113 assert.NotEqual(t, nil, err)
114 assert.Equal(t, "", email)
117func TestGitLabProviderGetEmailAddressEmailNotPresentInPayload(t *testing.T) {
118 b := testGitLabBackend("{\"foo\": \"bar\"}")
121 b_url, _ := url.Parse(b.URL)
122 p := testGitLabProvider(b_url.Host)
124 session := &SessionState{AccessToken: "imaginary_access_token"}
125 email, err := p.GetEmailAddress(session)
126 assert.NotEqual(t, nil, err)
127 assert.Equal(t, "", email)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list