-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathperfile_limits_test.go
110 lines (94 loc) · 2.58 KB
/
perfile_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package filedrop_test
import (
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/foxcpp/filedrop"
)
func TestPerFileMaxUses(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()
if !t.Run("submit with max-uses=WRONG (fail)", func(t *testing.T) {
doPOSTFail(t, c, ts.URL+"/filedrop?max-uses=WRONG", "text/plain", strings.NewReader(file))
}) {
t.FailNow()
}
if !t.Run("submit with max-uses=3 (fail)", func(t *testing.T) {
doPOSTFail(t, c, ts.URL+"/filedrop?max-uses=3", "text/plain", strings.NewReader(file))
}) {
t.FailNow()
}
var url string
if !t.Run("submit with max-uses=1", func(t *testing.T) {
url = string(doPOST(t, c, ts.URL+"/filedrop?max-uses=1", "text/plain", strings.NewReader(file)))
}) {
t.FailNow()
}
if !t.Run("1 use", func(t *testing.T) {
doGET(t, c, url)
}) {
t.FailNow()
}
if !t.Run("2 use", func(t *testing.T) {
doGET(t, c, url)
}) {
t.FailNow()
}
}
func TestPerFileStoreTime(t *testing.T) {
conf := filedrop.Default
conf.Limits.MaxStoreSecs = 5
serv := initServ(conf)
ts := httptest.NewServer(serv)
defer cleanServ(serv)
defer ts.Close()
c := ts.Client()
if !t.Run("submit with store-secs=WRONG (fail)", func(t *testing.T) {
doPOSTFail(t, c, ts.URL+"/filedrop?store-secs=WRONG", "text/plain", strings.NewReader(file))
}) {
t.FailNow()
}
if !t.Run("submit with store-secs=15 (fail)", func(t *testing.T) {
doPOSTFail(t, c, ts.URL+"/filedrop?store-secs=15", "text/plain", strings.NewReader(file))
}) {
t.FailNow()
}
var url string
if !t.Run("submit with store-secs=5", func(t *testing.T) {
url = string(doPOST(t, c, ts.URL+"/filedrop?store-secs=5", "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(5 * time.Second)
if !t.Run("get after 6 seconds (fail)", func(t *testing.T) {
if code := doGETFail(t, c, url); code != 404 {
t.Error("GET: HTTP", code)
t.FailNow()
}
}) {
t.FailNow()
}
}
func TestUnboundedFileLimits(t *testing.T) {
// Setting no limits in file should allow us to set them to any value in arguments.
conf := filedrop.Default
serv := initServ(conf)
ts := httptest.NewServer(serv)
defer cleanServ(serv)
defer ts.Close()
c := ts.Client()
doPOST(t, c, ts.URL+"/filedrop?store-secs=999999999", "text/plain", strings.NewReader(file))
doPOST(t, c, ts.URL+"/filedrop?max-uses=999999999", "text/plain", strings.NewReader(file))
}