-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathproviders_test.go
More file actions
106 lines (85 loc) · 2.21 KB
/
providers_test.go
File metadata and controls
106 lines (85 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package oauth2
import (
"context"
"io"
"net/http"
"strings"
"testing"
"time"
"golang.org/x/oauth2"
)
func init() {
// This has an extra parameter that the Google client wouldn't normally
// get, but it'll safely be ignored.
clientGet = func(_ *http.Client, url string) (*http.Response, error) {
return &http.Response{
Body: io.NopCloser(strings.NewReader(`{"id":"id", "email":"email", "name": "name"}`)),
}, nil
}
}
func TestGoogle(t *testing.T) {
t.Parallel()
cfg := *testProviders["google"].OAuth2Config
tok := &oauth2.Token{
AccessToken: "token",
TokenType: "Bearer",
RefreshToken: "refresh",
Expiry: time.Now().Add(60 * time.Minute),
}
details, err := GoogleUserDetails(context.Background(), cfg, tok)
if err != nil {
t.Error(err)
}
if uid, ok := details[OAuth2UID]; !ok || uid != "id" {
t.Error("UID wrong:", uid)
}
if email, ok := details[OAuth2Email]; !ok || email != "email" {
t.Error("Email wrong:", email)
}
}
func TestFacebook(t *testing.T) {
t.Parallel()
cfg := *testProviders["facebook"].OAuth2Config
tok := &oauth2.Token{
AccessToken: "token",
TokenType: "Bearer",
RefreshToken: "refresh",
Expiry: time.Now().Add(60 * time.Minute),
}
details, err := FacebookUserDetails(context.Background(), cfg, tok)
if err != nil {
t.Error(err)
}
if uid, ok := details[OAuth2UID]; !ok || uid != "id" {
t.Error("UID wrong:", uid)
}
if email, ok := details[OAuth2Email]; !ok || email != "email" {
t.Error("Email wrong:", email)
}
if name, ok := details[OAuth2Name]; !ok || name != "name" {
t.Error("Name wrong:", name)
}
}
func TestGithub(t *testing.T) {
t.Parallel()
cfg := *testProviders["github"].OAuth2Config
tok := &oauth2.Token{
AccessToken: "token",
TokenType: "Bearer",
RefreshToken: "refresh",
Expiry: time.Now().Add(60 * time.Minute),
}
details, err := GithubUserDetails(context.Background(), cfg, tok)
if err != nil {
t.Error(err)
}
if uid, ok := details[OAuth2UID]; !ok || uid != "id" {
t.Error("UID wrong:", uid)
}
if email, ok := details[OAuth2Email]; !ok || email != "email" {
t.Error("Email wrong:", email)
}
if name, ok := details[OAuth2Name]; !ok || name != "name" {
t.Error("Name wrong:", name)
}
}