forked from ipfs/gateway-conformance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_gateway_tar_test.go
117 lines (109 loc) · 3.24 KB
/
path_gateway_tar_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
111
112
113
114
115
116
117
package tests
import (
"testing"
"github.com/ipfs/gateway-conformance/tooling"
"github.com/ipfs/gateway-conformance/tooling/car"
. "github.com/ipfs/gateway-conformance/tooling/check"
"github.com/ipfs/gateway-conformance/tooling/specs"
. "github.com/ipfs/gateway-conformance/tooling/test"
"github.com/ipfs/gateway-conformance/tooling/tmpl"
)
func TestTar(t *testing.T) {
tooling.LogTestGroup(t, GroupTar)
fixtureOutside := car.MustOpenUnixfsCar("path_gateway_tar/outside-root.car")
fixtureInside := car.MustOpenUnixfsCar("path_gateway_tar/inside-root.car")
outsideRootCID := fixtureOutside.MustGetCid()
insideRootCID := fixtureInside.MustGetCid()
fixture := car.MustOpenUnixfsCar("path_gateway_tar/fixtures.car")
dirCID := fixture.MustGetCid() // root dir
fileCID := fixture.MustGetCid("ą", "ę", "file-źł.txt")
tests := SugarTests{
{
Name: "GET TAR with format=tar and extract",
Request: Request().
Path("/ipfs/{{cid}}", fileCID).
Query("format", "tar"),
Response: Expect().
Status(200).
Headers(
Header("Content-Disposition").Contains("attachment;"),
Header("Etag").Contains(`W/"{{cid}}.x-tar`, fileCID),
Header("Content-Type").Contains("application/x-tar"),
).Body(
IsTarFile().
HasFileWithContent(
fileCID,
"I am a txt file on path with utf8\n",
),
),
},
{
Name: "GET TAR with 'Accept: application/x-tar' and extract",
Request: Request().
Path("/ipfs/{{cid}}", fileCID).
Header("Accept", "application/x-tar"),
Response: Expect().
Status(200).
Headers(
Header("Content-Disposition").Contains("attachment;"),
Header("Etag").Contains(`W/"{{cid}}.x-tar`, fileCID),
Header("Content-Type").Contains("application/x-tar"),
).Body(
IsTarFile(),
),
},
{
Name: "GET TAR has expected root directory",
Request: Request().
Path("/ipfs/{{cid}}", dirCID).
Query("format", "tar"),
Response: Expect().
Status(200).
Body(
IsTarFile().
HasFileWithContent(
tmpl.Fmt("{{cid}}/ą/ę/file-źł.txt", dirCID),
"I am a txt file on path with utf8\n",
),
),
},
{
Name: "GET TAR with explicit ?filename= succeeds with modified Content-Disposition header",
Spec: "https://specs.ipfs.tech/http-gateways/path-gateway/#content-disposition-response-header",
Request: Request().
Path("/ipfs/{{cid}}", dirCID).
Query("filename", "testтест.tar").
Query("format", "tar"),
Response: Expect().
Status(200).
Headers(
Header("Content-Disposition").Contains(`attachment; filename="test____.tar"; filename*=UTF-8''test%D1%82%D0%B5%D1%81%D1%82.tar`),
),
},
{
Name: "GET TAR with relative paths outside root fails",
Request: Request().
Path("/ipfs/{{cid}}", outsideRootCID).
Query("format", "tar"),
Response: Expect().
Body(
Contains("relative UnixFS paths outside the root are now allowed"),
),
},
{
Name: "GET TAR with relative paths inside root works",
Request: Request().
Path("/ipfs/{{cid}}", insideRootCID).
Query("format", "tar"),
Response: Expect().
Status(200).
Body(
IsTarFile().
HasFile(
"{{cid}}/foobar/file", insideRootCID,
),
),
},
}
RunWithSpecs(t, tests, specs.PathGatewayTAR)
}