forked from abbot/go-http-auth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc_test.go
39 lines (34 loc) · 1.17 KB
/
misc_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
package auth
import (
"reflect"
"testing"
)
func TestH(t *testing.T) {
t.Parallel()
const hello = "Hello, world!"
const helloMD5 = "6cd3556deb0da54bca060b4c39479839"
h := H(hello)
if h != helloMD5 {
t.Fatal("Incorrect digest for test string:", h, "instead of", helloMD5)
}
}
func TestParsePairs(t *testing.T) {
t.Parallel()
const header = `username="\test", realm="a \"quoted\" string", nonce="FRPnGdb8lvM1UHhi", uri="/css?family=Source+Sans+Pro:400,700,400italic,700italic|Source+Code+Pro", algorithm=MD5, response="fdcdd78e5b306ffed343d0ec3967f2e5", opaque="lEgVjogmIar2fg/t", qop=auth, nc=00000001, cnonce="e76b05db27a3b323"`
want := map[string]string{
"username": "test",
"realm": `a "quoted" string`,
"nonce": "FRPnGdb8lvM1UHhi",
"uri": "/css?family=Source+Sans+Pro:400,700,400italic,700italic|Source+Code+Pro",
"algorithm": "MD5",
"response": "fdcdd78e5b306ffed343d0ec3967f2e5",
"opaque": "lEgVjogmIar2fg/t",
"qop": "auth",
"nc": "00000001",
"cnonce": "e76b05db27a3b323",
}
got := ParsePairs(header)
if !reflect.DeepEqual(got, want) {
t.Fatalf("failed to correctly parse pairs, got %v, want %v", got, want)
}
}