dex/connector/connector_facebook_test.go
ajanthan 464b7fb1af Connector: Connector for Facebook
This implements dex connector for facebook

Fixes #391
2016-10-07 16:19:44 -07:00

71 lines
1.6 KiB
Go

package connector
import (
"github.com/coreos/go-oidc/oidc"
"net/http"
"testing"
)
var facebookUser1 = `{
"id":"testUser1",
"name":"testUser1Fname testUser1Lname",
"email": "testUser1@facebook.com"
}`
var facebookUser2 = `{
"id":"testUser2",
"name":"testUser2Fname testUser2Lname",
"email": "testUser2@facebook.com"
}`
var facebookExampleError = `{
"error": {
"message": "Invalid OAuth access token signature.",
"type": "OAuthException",
"code": 190,
"fbtrace_id": "Ee/6W0EfrWP"
}
}`
func TestFacebookIdentity(t *testing.T) {
tests := []oauth2IdentityTest{
{
urlResps: map[string]response{
facebookGraphAPIURL: {http.StatusOK, facebookUser1},
},
want: oidc.Identity{
Name: "testUser1Fname testUser1Lname",
ID: "testUser1",
Email: "testUser1@facebook.com",
},
},
{
urlResps: map[string]response{
facebookGraphAPIURL: {http.StatusOK, facebookUser2},
},
want: oidc.Identity{
Name: "testUser2Fname testUser2Lname",
ID: "testUser2",
Email: "testUser2@facebook.com",
},
},
{
urlResps: map[string]response{
facebookGraphAPIURL: {http.StatusUnauthorized, facebookExampleError},
},
wantErr: facebookErr{
ErrorMessage: ErrorMessage{
Code: 190,
Type: "OAuthException",
Message: "Invalid OAuth access token signature.",
FbTraceId: "Ee/6W0EfrWP",
},
},
},
}
conn, err := newFacebookConnector("fakeFacebookAppID", "fakeFacebookAppSecret", "http://example.com/auth/facebook/callback")
if err != nil {
t.Fatal(err)
}
runOAuth2IdentityTests(t, conn, tests)
}