forked from abbot/go-http-auth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
users_test.go
48 lines (44 loc) · 1.19 KB
/
users_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 auth
import (
"os"
"testing"
"time"
)
func TestHtdigestFile(t *testing.T) {
t.Parallel()
secrets := HtdigestFileProvider("test.htdigest")
digest := secrets("test", "example.com")
if digest != "aa78524fceb0e50fd8ca96dd818b8cf9" {
t.Fatal("Incorrect digest for test user:", digest)
}
digest = secrets("test", "example1.com")
if digest != "" {
t.Fatal("Got digest for user in non-existant realm:", digest)
}
digest = secrets("test1", "example.com")
if digest != "" {
t.Fatal("Got digest for non-existant user:", digest)
}
}
func TestHtpasswdFile(t *testing.T) {
t.Parallel()
secrets := HtpasswdFileProvider("test.htpasswd")
passwd := secrets("test", "blah")
if passwd != "{SHA}qvTGHdzF6KLavt4PO0gs2a6pQ00=" {
t.Fatal("Incorrect passwd for test user:", passwd)
}
passwd = secrets("nosuchuser", "blah")
if passwd != "" {
t.Fatal("Got passwd for non-existant user:", passwd)
}
}
// TestConcurrent verifies potential race condition in users reading logic
func TestConcurrent(t *testing.T) {
t.Parallel()
secrets := HtpasswdFileProvider("test.htpasswd")
os.Chtimes("test.htpasswd", time.Now(), time.Now())
go func() {
secrets("test", "blah")
}()
secrets("test", "blah")
}