2015-03-13 11:15:58 +02:00
|
|
|
package oauth2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"golang.org/x/oauth2"
|
2015-03-14 01:23:43 +02:00
|
|
|
"gopkg.in/authboss.v0"
|
2015-03-13 11:15:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGoogle(t *testing.T) {
|
|
|
|
saveClientGet := clientGet
|
|
|
|
defer func() {
|
|
|
|
clientGet = saveClientGet
|
|
|
|
}()
|
|
|
|
|
|
|
|
clientGet = func(_ *http.Client, url string) (*http.Response, error) {
|
|
|
|
return &http.Response{
|
|
|
|
Body: ioutil.NopCloser(strings.NewReader(`{"id":"id", "email":"email"}`)),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := *testProviders["google"].OAuth2Config
|
|
|
|
tok := &oauth2.Token{
|
|
|
|
AccessToken: "token",
|
|
|
|
TokenType: "Bearer",
|
|
|
|
RefreshToken: "refresh",
|
|
|
|
Expiry: time.Now().Add(60 * time.Minute),
|
|
|
|
}
|
|
|
|
|
2015-03-14 01:23:43 +02:00
|
|
|
user, err := Google(cfg, tok)
|
2015-03-13 11:15:58 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2015-03-14 01:23:43 +02:00
|
|
|
if uid, ok := user[authboss.StoreOAuth2UID]; !ok || uid != "id" {
|
|
|
|
t.Error("UID wrong:", uid)
|
2015-03-13 11:15:58 +02:00
|
|
|
}
|
2015-03-14 01:23:43 +02:00
|
|
|
if email, ok := user[authboss.StoreEmail]; !ok || email != "email" {
|
|
|
|
t.Error("Email wrong:", email)
|
2015-03-13 11:15:58 +02:00
|
|
|
}
|
|
|
|
}
|