-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
54 lines (49 loc) · 1.16 KB
/
main_test.go
File metadata and controls
54 lines (49 loc) · 1.16 KB
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
package main
import (
"net/http"
"net/url"
"os"
"testing"
)
func TestMain(m *testing.M) {
proxy := newProxy("", "", "")
api := newApi(proxy)
go api.run("8001")
go proxy.run("8000")
os.Exit(m.Run())
}
func TestLocalhost(t *testing.T) {
resp, err := http.Get("http://localhost:8000")
if err != nil {
t.Fatal(err)
}
if resp.StatusCode != 403 {
t.Fatalf("Received non-403 response: %d\n", resp.StatusCode)
}
}
func TestSimpleForward(t *testing.T) {
client := &http.Client{}
req, _ := http.NewRequest("GET", "http://localhost:8000", nil)
req.Host = "doc.api.lovebystep.com"
resp, err := client.Do(req)
if err != nil {
t.Fatal(err)
}
if resp.StatusCode != 200 {
t.Fatalf("Received non-200 response: %d\n", resp.StatusCode)
}
}
func TestSimpleBlacklist(t *testing.T) {
http.PostForm("http://localhost:8001/forbid",
url.Values{"regex": {"doc.api.lovebystep.com"}})
client := &http.Client{}
req, _ := http.NewRequest("GET", "http://localhost:8000", nil)
req.Host = "doc.api.lovebystep.com"
resp, err := client.Do(req)
if err != nil {
t.Fatal(err)
}
if resp.StatusCode != 403 {
t.Fatalf("Received non-403 response: %d\n", resp.StatusCode)
}
}