forked from ipfs/gateway-conformance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrustless_gateway_ipns_test.go
99 lines (94 loc) · 3.09 KB
/
trustless_gateway_ipns_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
package tests
import (
"testing"
"github.com/ipfs/gateway-conformance/tooling"
. "github.com/ipfs/gateway-conformance/tooling/ipns"
"github.com/ipfs/gateway-conformance/tooling/specs"
. "github.com/ipfs/gateway-conformance/tooling/test"
)
func TestGatewayIPNSRecord(t *testing.T) {
tooling.LogTestGroup(t, GroupIPNS)
tests := SugarTests{
{
Name: "GET IPNS Record (V1+V2) with format=ipns-record has expected HTTP headers and valid key",
Request: Request().
Path("/ipns/{{name}}", ipnsV1V2.Key()).
Query("format", "ipns-record"),
Response: Expect().
Headers(
Header("Content-Disposition").Contains("attachment;"),
Header("Content-Type").Contains("application/vnd.ipfs.ipns-record"),
Header("Cache-Control").Contains("public, max-age=1800"),
).
Body(
IsIPNSRecord(ipnsV1V2.Key()).
IsValid().
PointsTo(ipnsV1V2.Value()),
),
},
{
Name: "GET IPNS Record (V2) with format=ipns-record has expected HTTP headers and valid key",
Request: Request().
Path("/ipns/{{name}}", ipnsV2.Key()).
Query("format", "ipns-record"),
Response: Expect().
Headers(
Header("Content-Disposition").Contains("attachment;"),
Header("Content-Type").Contains("application/vnd.ipfs.ipns-record"),
Header("Cache-Control").Contains("public, max-age=1800"),
).
Body(
IsIPNSRecord(ipnsV2.Key()).
IsValid().
PointsTo(ipnsV2.Value()),
),
},
{
Name: "GET IPNS Record (V1+V2) with 'Accept: application/vnd.ipfs.ipns-record' has expected HTTP headers and valid key",
Request: Request().
Path("/ipns/{{name}}", ipnsV1V2.Key()).
Header("Accept", "application/vnd.ipfs.ipns-record"),
Response: Expect().
Headers(
Header("Content-Disposition").Contains("attachment;"),
Header("Content-Type").Contains("application/vnd.ipfs.ipns-record"),
Header("Cache-Control").Contains("public, max-age=1800"),
).
Body(
IsIPNSRecord(ipnsV1V2.Key()).
IsValid().
PointsTo(ipnsV1V2.Value()),
),
},
{
Name: "GET IPNS Record (V2) with 'Accept: application/vnd.ipfs.ipns-record' has expected HTTP headers and valid key",
Request: Request().
Path("/ipns/{{name}}", ipnsV2.Key()).
Header("Accept", "application/vnd.ipfs.ipns-record"),
Response: Expect().
Headers(
Header("Content-Disposition").Contains("attachment;"),
Header("Content-Type").Contains("application/vnd.ipfs.ipns-record"),
Header("Cache-Control").Contains("public, max-age=1800"),
).
Body(
IsIPNSRecord(ipnsV2.Key()).
IsValid().
PointsTo(ipnsV2.Value()),
),
},
{
Name: "GET IPNS Record with explicit ?filename= succeeds with modified Content-Disposition header",
Request: Request().
Path("/ipns/{{name}}", ipnsV1V2.Key()).
Query("format", "ipns-record").
Query("filename", "testтест.ipns-record"),
Response: Expect().
Headers(
Header("Content-Disposition").
Contains(`attachment; filename="test____.ipns-record"; filename*=UTF-8''test%D1%82%D0%B5%D1%81%D1%82.ipns-record`),
),
},
}
RunWithSpecs(t, tests, specs.TrustlessGatewayIPNS)
}