-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
45 lines (35 loc) · 885 Bytes
/
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
package itisadb
import (
"context"
"reflect"
"testing"
api "github.com/egorgasay/itisadb-shared-proto/go"
"google.golang.org/grpc/metadata"
)
func Test_withAuth(t *testing.T) {
authMetadata = metadata.New(map[string]string{token: "XXX"})
ctx := metadata.NewOutgoingContext(context.TODO(), authMetadata)
got := withAuth(ctx)
t.Log(got)
if !reflect.DeepEqual(ctx, got) {
t.Errorf("withAuth() = %v, want %v", got, ctx)
}
}
func TestAuth(t *testing.T) {
ctx := context.Background()
cl := New(ctx, ":8833").Unwrap()
// method that requires auth
resp, err := cl.cl.Servers(withAuth(ctx), &api.ServersRequest{})
if err != nil {
t.Fatalf("Servers: %v", err)
}
t.Log("Auth OK")
t.Log(resp.ServersInfo)
err = New(ctx, ":8833", Config{Credentials: Credentials{
Login: "ddq",
Password: "qwdqd",
}}).Error()
if err == nil {
t.Fatalf("should fail")
}
}