forked from bruwozniak/jupyterhub-proxy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
headers_test.go
78 lines (67 loc) · 1.96 KB
/
headers_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
package main
import (
"net/http"
"testing"
)
func TestRequestHeader(t *testing.T) {
header := make(map[string][]string)
header["Location"] = []string{"/hue"}
header["Referer"] = []string{"https://jove.com/hue/user/user@comp/hue"}
prefix := "/user/user@comp/"
req := http.Request{
Proto: "HTTP/1.0",
ProtoMajor: 1,
ProtoMinor: 0,
Header: header,
Body: nil,
ContentLength: 0,
TransferEncoding: nil,
Close: false,
Trailer: nil,
TLS: nil,
}
correct_headers(&req.Header, prefix)
location := req.Header.Get("Location")
want_location := "/user/user@comp/hue"
if location != want_location {
t.Fatalf("correct_headers() = %s want %s", location, want_location)
}
referer := req.Header.Get("Referer")
want_referer := "https://jove.com/user/user@comp/hue"
if referer != want_referer {
t.Fatalf("correct_headers() = %s want %s", referer, want_referer)
}
}
func TestResponseHeader(t *testing.T) {
header := make(map[string][]string)
header["Location"] = []string{"/hue"}
header["Referer"] = []string{"https://jove.com/hue/user/user@comp/hue"}
prefix := "/user/user@comp/"
resp := http.Response{
Status: "200 OK",
StatusCode: 200,
Proto: "HTTP/1.0",
ProtoMajor: 1,
ProtoMinor: 0,
Header: header,
Body: nil,
ContentLength: 0,
TransferEncoding: nil,
Close: false,
Uncompressed: false,
Trailer: nil,
Request: nil,
TLS: nil,
}
correct_headers(&resp.Header, prefix)
location := resp.Header.Get("Location")
want_location := "/user/user@comp/hue"
if location != want_location {
t.Fatalf("correct_headers() = %s want %s", location, want_location)
}
referer := resp.Header.Get("Referer")
want_referer := "https://jove.com/user/user@comp/hue"
if referer != want_referer {
t.Fatalf("correct_headers() = %s want %s", referer, want_referer)
}
}