-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathglobal_limits_test.go
96 lines (82 loc) · 2.06 KB
/
global_limits_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package filedrop_test
import (
"net/http/httptest"
"strconv"
"strings"
"testing"
"time"
"github.com/foxcpp/filedrop"
)
func TestGlobalMaxUses(t *testing.T) {
conf := filedrop.Default
conf.Limits.MaxUses = 2
serv := initServ(conf)
ts := httptest.NewServer(serv)
defer cleanServ(serv)
defer ts.Close()
c := ts.Client()
url := string(doPOST(t, c, ts.URL+"/filedrop", "text/plain", strings.NewReader(file)))
t.Run("1 use", func(t *testing.T) {
doGET(t, c, url)
})
t.Run("2 use", func(t *testing.T) {
doGET(t, c, url)
})
t.Run("3 use (fail)", func(t *testing.T) {
if code := doGETFail(t, c, url); code != 404 {
t.Error("GET: HTTP", code)
t.FailNow()
}
})
}
func TestGlobalMaxFileSize(t *testing.T) {
conf := filedrop.Default
conf.Limits.MaxFileSize = uint(len(file) - 20)
serv := initServ(conf)
ts := httptest.NewServer(serv)
defer cleanServ(serv)
defer ts.Close()
c := ts.Client()
t.Log("Max size:", conf.Limits.MaxFileSize, "bytes")
if !t.Run("submit with size "+strconv.Itoa(len(file)), func(t *testing.T) {
doPOSTFail(t, c, ts.URL+"/filedrop", "text/plain", strings.NewReader(file))
}) {
t.FailNow()
}
strippedFile := file[:25]
if !t.Run("submit with size "+strconv.Itoa(len(strippedFile)), func(t *testing.T) {
doPOST(t, c, ts.URL+"/filedrop", "text/plain", strings.NewReader(strippedFile))
}) {
t.FailNow()
}
}
func TestGlobalMaxStoreTime(t *testing.T) {
conf := filedrop.Default
conf.Limits.MaxStoreSecs = 3
serv := initServ(conf)
ts := httptest.NewServer(serv)
defer cleanServ(serv)
defer ts.Close()
c := ts.Client()
var url string
if !t.Run("submit", func(t *testing.T) {
url = string(doPOST(t, c, ts.URL+"/filedrop", "text/plain", strings.NewReader(file)))
}) {
t.FailNow()
}
time.Sleep(1 * time.Second)
if !t.Run("get after 1 second", func(t *testing.T) {
doGET(t, c, url)
}) {
t.FailNow()
}
time.Sleep(3 * time.Second)
if !t.Run("get after 3 seconds (fail)", func(t *testing.T) {
if code := doGETFail(t, c, url); code != 404 {
t.Error("GET: HTTP", code)
t.FailNow()
}
}) {
t.FailNow()
}
}