forked from dkerwin/gini-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
48 lines (41 loc) · 1.15 KB
/
auth_test.go
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
package giniapi
import (
"testing"
)
func Test_newHTTPClient(t *testing.T) {
// Basic config
config := Config{
ClientID: "testclient",
ClientSecret: "secret",
Endpoints: Endpoints{
API: testHTTPServer.URL,
UserCenter: testHTTPServer.URL,
},
}
// basicAuth
config.Authentication = UseBasicAuth
if client, err := newHTTPClient(&config); client == nil || err != nil {
t.Errorf("Failed to create http client: %s", err)
}
// oauth2
config.Authentication = UseOauth2
// AuthCode
config.AuthCode = "123456"
if client, err := newHTTPClient(&config); client == nil || err != nil {
t.Errorf("Failed to exchange auth code: %s", err)
}
// Username + Password
config.AuthCode = ""
config.Username = "user1"
config.Password = "secret"
if client, err := newHTTPClient(&config); client == nil || err != nil {
t.Errorf("Failed to exchange username and password: %s", err)
}
// missing auth_code and user credentials
config.AuthCode = ""
config.Username = ""
config.Password = ""
if client, err := newHTTPClient(&config); client != nil || err == nil {
t.Errorf("Invalid oauth2 auth parameters shoulfd raise err: %s", err)
}
}