forked from ipfs/gateway-conformance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubdomain_gateway_proxy_test.go
141 lines (133 loc) · 4.86 KB
/
subdomain_gateway_proxy_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package tests
import (
"testing"
"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"
)
var (
fixture = car.MustOpenUnixfsCar("subdomain_gateway/fixtures.car")
CIDVal = string(fixture.MustGetRawData("hello-CIDv1")) // hello
DirCID = fixture.MustGetCid("testdirlisting")
CIDv1 = fixture.MustGetCid("hello-CIDv1")
CIDv0 = fixture.MustGetCid("hello-CIDv0")
CIDv0to1 = fixture.MustGetCid("hello-CIDv0to1")
//CIDv1_TOO_LONG = fixture.MustGetCid("hello-CIDv1_TOO_LONG")
// the gateway endpoint is used as HTTP proxy
gatewayAsProxyURL = GatewayURL().String()
// run against origins explicitly passed via --subdomain-url
s = SubdomainGatewayURL()
)
func TestProxyGatewaySubdomains(t *testing.T) {
tests := SugarTests{
{
Name: "request for {CID}.ipfs.example.com should return expected payload",
Hint: "HTTP proxy gateway accepts requests for GETs of full URLs as Paths",
Request: Request().
Proxy(gatewayAsProxyURL).
Path("{{scheme}}://{{cid}}.ipfs.{{host}}", s.Scheme, CIDv1, s.Host),
Response: Expect().
Status(200).
Body(Contains(CIDVal)),
},
{
Name: "request for example.com/ipfs/{CIDv0} redirects to {CIDv1}.ipfs.example.com",
Hint: "HTTP proxy gateway accepts requests for GETs of full URLs as Paths",
Request: Request().
Proxy(gatewayAsProxyURL).
Path("{{scheme}}://{{host}}/ipfs/{{cid}}/", s.Scheme, s.Host, CIDv0),
Response: Expect().
Status(301).
Headers(
Header("Location").
Hint("request for example.com/ipfs/{CIDv0to1} returns Location HTTP header for subdomain redirect in browsers").
Contains("{{scheme}}://{{cid}}.ipfs.{{host}}/", s.Scheme, CIDv0to1, s.Host),
),
},
{
Name: "request for {CID}.ipfs.example.com/ipfs/file.txt should return data from a file in CID content root",
Hint: "ensure subdomain gateway takes priority over processing /ipfs/* paths",
Request: Request().
Proxy(gatewayAsProxyURL).
Path("{{scheme}}://{{cid}}.ipfs.{{host}}/ipfs/file.txt", s.Scheme, DirCID, s.Host),
Response: Expect().
Status(200).
Body(Contains("I am a txt file")),
},
/* TODO: value added
{
Name: "request for a too long CID at {CIDv1}.ipfs.example.com returns expected payload",
Hint: "HTTP proxy mode allows responding to requests with 'DNS labels' longer than 63 characters",
Request: Request().
Proxy(gatewayAsProxyURL).
TODO turn to Path: Header("Host", Fmt("{{cid}}.ipfs.{{host}}", CIDv1_TOO_LONG, s.Host)).
Path("/"),
Response: Expect().
Status(400).
Body(Contains("TODO")),
},
*/
}
RunWithSpecs(t, tests, specs.ProxyGateway, specs.SubdomainGatewayIPFS)
}
func TestProxyTunnelGatewaySubdomains(t *testing.T) {
tests := SugarTests{
{
Name: "request for {CID}.ipfs.example.com should return expected payload",
Hint: "HTTP CONNECT is how some proxy setups convert an HTTP connection into a tunnel to a remote host https://tools.ietf.org/html/rfc7231#section-4.3.6",
Request: Request().
WithProxyTunnel().
Proxy(gatewayAsProxyURL).
Header("Host", Fmt("{{cid}}.ipfs.{{host}}", CIDv1, s.Host)).
Path("/"),
Response: Expect().
Status(200).
Body(Contains(CIDVal)),
},
{
Name: "request for example.com/ipfs/{CIDv0} redirects to {CIDv1}.ipfs.example.com",
Hint: "proxy tunnel follows ",
Request: Request().
WithProxyTunnel().
Proxy(gatewayAsProxyURL).
Header("Host", s.Host).
Path("/ipfs/{{cid}}/", CIDv0),
Response: Expect().
Status(301).
Headers(
Header("Location").
Hint("request for example.com/ipfs/{CIDv0to1} returns Location HTTP header for subdomain redirect in browsers").
Contains("{{scheme}}://{{cid}}.ipfs.{{host}}/", s.Scheme, CIDv0to1, s.Host),
),
},
{
Name: "request for {CID}.ipfs.example.com/ipfs/file.txt should return data from a file in CID content root",
Hint: "ensure subdomain gateway takes priority over processing /ipfs/* paths",
Request: Request().
WithProxyTunnel().
Proxy(gatewayAsProxyURL).
Header("Host", Fmt("{{cid}}.ipfs.{{host}}", DirCID, s.Host)).
Path("/ipfs/file.txt"),
Response: Expect().
Status(200).
Body(Contains("I am a txt file")),
},
/* TODO: value added
{
Name: "request for a too long CID at {CIDv1}.ipfs.example.com returns expected payload",
Hint: "HTTP proxy mode allows responding to requests with 'DNS labels' longer than 63 characters",
Request: Request().
WithProxyTunnel().
Proxy(gatewayAsProxyURL).
TODO turn to Path: Header("Host", Fmt("{{cid}}.ipfs.{{host}}", CIDv1_TOO_LONG, s.Host)).
Path("/"),
Response: Expect().
Status(400).
Body(Contains("TODO")),
},
*/
}
RunWithSpecs(t, tests, specs.ProxyGateway, specs.SubdomainGatewayIPFS)
}