Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
b15cf019
提交
b15cf019
authored
1月 04, 2019
作者:
Steven Allen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gateway: fix cors headers tests
License: MIT Signed-off-by:
Steven Allen
<
steven@stebalien.com
>
上级
4bbf4cc9
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
42 行增加
和
13 行删除
+42
-13
t0112-gateway-cors.sh
test/sharness/t0112-gateway-cors.sh
+42
-13
没有找到文件。
test/sharness/t0112-gateway-cors.sh
浏览文件 @
b15cf019
...
@@ -18,41 +18,70 @@ test_init_ipfs
...
@@ -18,41 +18,70 @@ test_init_ipfs
test_config_ipfs_cors_headers
test_config_ipfs_cors_headers
test_launch_ipfs_daemon
test_launch_ipfs_daemon
gwport
=
$GWAY_PORT
apiport
=
$API_PORT
thash
=
'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
thash
=
'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
# Gateway
# Gateway
# HTTP GET Request
# HTTP GET Request
test_expect_success
"GET to Gateway succeeds"
'
test_expect_success
"GET to Gateway succeeds"
'
curl -svX GET "http://127.0.0.1:$gwport/ipfs/$thash" 2>curl_output
curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" >/dev/null 2>curl_output &&
cat curl_output
'
'
cat
curl_output
# GET Response from Gateway should contain CORS headers
# GET Response from Gateway should contain CORS headers
test_expect_success
"GET response for Gateway resource looks good"
'
test_expect_success
"GET response for Gateway resource looks good"
'
grep "Access-Control-Allow-Origin:" curl_output | grep "\*" &&
grep "< Access-Control-Allow-Origin: \*" curl_output &&
grep "Access-Control-Allow-Methods:" curl_output | grep " GET\b" &&
grep "< Access-Control-Allow-Methods: GET" curl_output &&
grep "Access-Control-Allow-Headers:" curl_output
grep "< Access-Control-Allow-Headers: Range" curl_output &&
grep "< Access-Control-Expose-Headers: Content-Range" curl_output
'
'
# HTTP OPTIONS Request
# HTTP OPTIONS Request
test_expect_success
"OPTIONS to Gateway succeeds"
'
test_expect_success
"OPTIONS to Gateway succeeds"
'
curl -svX OPTIONS "http://127.0.0.1:$gwport/ipfs/$thash" 2>curl_output
curl -svX OPTIONS "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" 2>curl_output &&
cat curl_output
'
'
# OPTION Response from Gateway should contain CORS headers
# OPTION Response from Gateway should contain CORS headers
test_expect_success
"OPTIONS response for Gateway resource looks good"
'
test_expect_success
"OPTIONS response for Gateway resource looks good"
'
grep "Access-Control-Allow-Origin:" curl_output | grep "\*" &&
grep "< Access-Control-Allow-Origin: \*" curl_output &&
grep "Access-Control-Allow-Methods:" curl_output | grep " GET\b" &&
grep "< Access-Control-Allow-Methods: GET" curl_output &&
grep "Access-Control-Allow-Headers:" curl_output
grep "< Access-Control-Allow-Headers: Range" curl_output &&
grep "< Access-Control-Expose-Headers: Content-Range" curl_output
'
test_kill_ipfs_daemon
# Change headers
test_expect_success
"Can configure gateway headers"
'
ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Headers "[\"X-Custom1\"]" &&
ipfs config --json Gateway.HTTPHeaders.Access-Control-Expose-Headers "[\"X-Custom2\"]" &&
ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Origin "[\"localhost\"]"
'
test_launch_ipfs_daemon
test_expect_success
"OPTIONS to Gateway succeeds"
'
curl -svX OPTIONS "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" 2>curl_output &&
cat curl_output
'
test_expect_success
"Access-Control-Allow-Headers extends"
'
grep "< Access-Control-Allow-Headers: Range" curl_output &&
grep "< Access-Control-Allow-Headers: X-Custom1" curl_output &&
grep "< Access-Control-Expose-Headers: Content-Range" curl_output &&
grep "< Access-Control-Expose-Headers: X-Custom2" curl_output
'
test_expect_success
"Access-Control-Allow-Origin replaces"
'
grep "< Access-Control-Allow-Origin: localhost" curl_output
'
'
# Read-Only API (at the Gateway Port)
# Read-Only API (at the Gateway Port)
# HTTP GET Request
# HTTP GET Request
test_expect_success
"GET to API succeeds"
'
test_expect_success
"GET to API succeeds"
'
curl -svX GET "http://127.0.0.1:$
gwport/api/v0/cat?arg=$thash"
2>curl_output
curl -svX GET "http://127.0.0.1:$
GWAY_PORT/api/v0/cat?arg=$thash" >/dev/null
2>curl_output
'
'
# GET Response from the API should NOT contain CORS headers
# GET Response from the API should NOT contain CORS headers
# Blacklisting: https://git.io/vzaj2
# Blacklisting: https://git.io/vzaj2
...
@@ -63,7 +92,7 @@ test_expect_success "OPTIONS response for API looks good" '
...
@@ -63,7 +92,7 @@ test_expect_success "OPTIONS response for API looks good" '
# HTTP OPTIONS Request
# HTTP OPTIONS Request
test_expect_success
"OPTIONS to API succeeds"
'
test_expect_success
"OPTIONS to API succeeds"
'
curl -svX OPTIONS "http://127.0.0.1:$
gwport
/api/v0/cat?arg=$thash" 2>curl_output
curl -svX OPTIONS "http://127.0.0.1:$
GWAY_PORT
/api/v0/cat?arg=$thash" 2>curl_output
'
'
# OPTIONS Response from the API should NOT contain CORS headers
# OPTIONS Response from the API should NOT contain CORS headers
test_expect_success
"OPTIONS response for API looks good"
'
test_expect_success
"OPTIONS response for API looks good"
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论