mirror of https://github.com/dexidp/dex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
975 B
41 lines
975 B
package connector |
|
|
|
import ( |
|
"net/http" |
|
"testing" |
|
|
|
"github.com/coreos/go-oidc/oidc" |
|
) |
|
|
|
var ( |
|
githubExampleUser = `{"login":"octocat","id":1,"name": "monalisa octocat","email": "octocat@github.com"}` |
|
githubExampleError = `{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}` |
|
) |
|
|
|
func TestGitHubIdentity(t *testing.T) { |
|
tests := []oauth2IdentityTest{ |
|
{ |
|
urlResps: map[string]response{ |
|
githubAPIUserURL: {http.StatusOK, githubExampleUser}, |
|
}, |
|
want: oidc.Identity{ |
|
Name: "monalisa octocat", |
|
ID: "1", |
|
Email: "octocat@github.com", |
|
}, |
|
}, |
|
{ |
|
urlResps: map[string]response{ |
|
githubAPIUserURL: {http.StatusUnauthorized, githubExampleError}, |
|
}, |
|
wantErr: githubError{ |
|
Message: "Bad credentials", |
|
}, |
|
}, |
|
} |
|
conn, err := newGitHubConnector("fakeclientid", "fakeclientsecret", "http://examle.com/auth/github/callback") |
|
if err != nil { |
|
t.Fatal(err) |
|
} |
|
runOAuth2IdentityTests(t, conn, tests) |
|
}
|
|
|