File: misc_test.go

package info (click to toggle)
golang-github-abbot-go-http-auth 0.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 164 kB
  • sloc: makefile: 13
file content (37 lines) | stat: -rw-r--r-- 1,181 bytes parent folder | download | duplicates (3)
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
package auth

import (
	"reflect"
	"testing"
)

func TestH(t *testing.T) {
	const hello = "Hello, world!"
	const hello_md5 = "6cd3556deb0da54bca060b4c39479839"
	h := H(hello)
	if h != hello_md5 {
		t.Fatal("Incorrect digest for test string:", h, "instead of", hello_md5)
	}
}

func TestParsePairs(t *testing.T) {
	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\ndiff: %s", got, want)
	}
}