-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgettoken_test.go
126 lines (120 loc) · 3.19 KB
/
gettoken_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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2019 Alberto Bregliano. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package token_test
import (
"context"
rand "math/rand"
"testing"
"time"
"github.com/axamon/hashstring"
"github.com/axamon/token"
)
func TestCheckLocalCredentials(t *testing.T) {
ctxshort, cancel := context.WithTimeout(context.Background(), time.Microsecond)
defer cancel()
type args struct {
ctx context.Context
c *token.Credentials
}
tests := []struct {
name string
args args
want bool
wantErr bool
}{
// TODO: Add test cases.
{name: "first", args: args{ctx: context.TODO(),
c: &token.Credentials{
User: "pippo",
Hashpass: hashstring.Md5Sum("pippo")}},
want: true, wantErr: false},
{name: "second", args: args{ctx: context.TODO(),
c: &token.Credentials{
User: "pluto",
Hashpass: hashstring.Md5Sum("pippo")}},
want: false, wantErr: true},
{name: "third", args: args{ctx: context.TODO(),
c: &token.Credentials{
User: "pippo",
Hashpass: hashstring.Md5Sum("pipp")}},
want: false, wantErr: false},
{name: "forth", args: args{ctx: ctxshort,
c: &token.Credentials{
User: "pipp",
Hashpass: hashstring.Md5Sum("pippo")}},
want: false, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
time.Sleep(time.Millisecond) // modified after bloomfilter introduction.
got, err := token.CheckLocalCredentials(tt.args.ctx, tt.args.c)
if (err != nil) != tt.wantErr {
t.Errorf("CheckLocalCredentials() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("CheckLocalCredentials() = %v, want %v", got, tt.want)
}
})
}
}
func TestCheckLocalCredentials2(t *testing.T) {
token.CredentialsJSONFile = "file.json"
type args struct {
ctx context.Context
c *token.Credentials
}
tests := []struct {
name string
args args
want bool
wantErr bool
}{
// TODO: Add test cases.
{name: "first", args: args{ctx: context.TODO(),
c: &token.Credentials{
User: "pippo",
Hashpass: hashstring.Md5Sum("pippo")}},
want: false, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := token.CheckLocalCredentials(tt.args.ctx, tt.args.c)
if (err != nil) != tt.wantErr {
t.Errorf("CheckLocalCredentials() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("CheckLocalCredentials() = %v, want %v", got, tt.want)
}
})
}
}
func TestGenerateToken(t *testing.T) {
rand.Seed(int64(99))
type args struct {
ctx context.Context
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
// TODO: Add test cases.
{name: "first", args: args{ctx: context.TODO()}, want: "75ed1842-49e9-bc19-675e-4d1f766213da", wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := token.GenerateCtx(tt.args.ctx)
if (err != nil) != tt.wantErr {
t.Errorf("GenerateCtx() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("GenerateCtx() = %v, want %v", got, tt.want)
}
})
}
}