forked from abbot/go-http-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_test.go
34 lines (30 loc) · 850 Bytes
/
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
// (C) Modifications copyright 2019, Tom Andrade <[email protected]>
// Package auth is a implementation of HTTP Basic in Go language.
package auth
import (
"os"
"testing"
"time"
)
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-existent 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")
}