Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
d904e888
提交
d904e888
authored
7月 24, 2018
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Possible Invalid Checkpoint.
Appox Date June 24.
上级
70949b0f
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
118 行增加
和
17 行删除
+118
-17
blocks_test.go
blockservice/test/blocks_test.go
+1
-1
pathresolver_test.go
core/pathresolver_test.go
+1
-1
bench_test.go
exchange/bitswap/decision/bench_test.go
+1
-1
peer_request_queue_test.go
exchange/bitswap/decision/peer_request_queue_test.go
+5
-5
message_test.go
exchange/bitswap/message/message_test.go
+2
-1
path.go
path/path.go
+16
-6
bitswap_wo_routing_test.go
test/integration/bitswap_wo_routing_test.go
+4
-2
AFKSEBCGPUJZE.data
test/sharness/t0275-cid-security-data/AFKSEBCGPUJZE.data
+1
-0
t0275-cid-security.sh
test/sharness/t0275-cid-security.sh
+87
-0
没有找到文件。
blockservice/test/blocks_test.go
浏览文件 @
d904e888
...
...
@@ -28,7 +28,7 @@ func TestBlocks(t *testing.T) {
defer
bs
.
Close
()
o
:=
newObject
([]
byte
(
"beep boop"
))
h
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
"beep boop"
)))
h
,
_
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
"beep boop"
)))
if
!
o
.
Cid
()
.
Equals
(
h
)
{
t
.
Error
(
"Block key and data multihash key not equal"
)
}
...
...
core/pathresolver_test.go
浏览文件 @
d904e888
...
...
@@ -25,7 +25,7 @@ func TestResolveNoComponents(t *testing.T) {
}
_
,
err
=
core
.
Resolve
(
n
.
Context
(),
n
.
Namesys
,
n
.
Resolver
,
path
.
Path
(
"/../.."
))
if
err
!=
path
.
ErrBadPath
{
if
_
,
ok
:=
err
.
(
path
.
ErrBadPath
);
!
ok
{
t
.
Fatal
(
"Should error with invalid path."
,
err
)
}
}
exchange/bitswap/decision/bench_test.go
浏览文件 @
d904e888
...
...
@@ -23,7 +23,7 @@ func BenchmarkTaskQueuePush(b *testing.B) {
}
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
c
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
fmt
.
Sprint
(
i
))))
c
,
_
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
fmt
.
Sprint
(
i
))))
q
.
Push
(
&
wantlist
.
Entry
{
Cid
:
c
,
Priority
:
math
.
MaxInt32
},
peers
[
i
%
len
(
peers
)])
}
...
...
exchange/bitswap/decision/peer_request_queue_test.go
浏览文件 @
d904e888
...
...
@@ -44,11 +44,11 @@ func TestPushPop(t *testing.T) {
letter
:=
alphabet
[
index
]
t
.
Log
(
partner
.
String
())
c
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
letter
)))
c
,
_
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
letter
)))
prq
.
Push
(
&
wantlist
.
Entry
{
Cid
:
c
,
Priority
:
math
.
MaxInt32
-
index
},
partner
)
}
for
_
,
consonant
:=
range
consonants
{
c
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
consonant
)))
c
,
_
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
consonant
)))
prq
.
Remove
(
c
,
partner
)
}
...
...
@@ -66,8 +66,8 @@ func TestPushPop(t *testing.T) {
// Entries popped should already be in correct order
for
i
,
expected
:=
range
vowels
{
exp
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
expected
)))
.
String
(
)
if
out
[
i
]
!=
exp
{
exp
,
_
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
expected
))
)
if
out
[
i
]
!=
exp
.
String
()
{
t
.
Fatal
(
"received"
,
out
[
i
],
"expected"
,
expected
)
}
}
...
...
@@ -84,7 +84,7 @@ func TestPeerRepeats(t *testing.T) {
// Have each push some blocks
for
i
:=
0
;
i
<
5
;
i
++
{
elcid
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
fmt
.
Sprint
(
i
))))
elcid
,
_
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
fmt
.
Sprint
(
i
))))
prq
.
Push
(
&
wantlist
.
Entry
{
Cid
:
elcid
},
a
)
prq
.
Push
(
&
wantlist
.
Entry
{
Cid
:
elcid
},
b
)
prq
.
Push
(
&
wantlist
.
Entry
{
Cid
:
elcid
},
c
)
...
...
exchange/bitswap/message/message_test.go
浏览文件 @
d904e888
...
...
@@ -13,7 +13,8 @@ import (
)
func
mkFakeCid
(
s
string
)
*
cid
.
Cid
{
return
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
s
)))
c
,
_
:=
cid
.
NewCidV0
(
u
.
Hash
([]
byte
(
s
)))
return
c
}
func
TestAppendWanted
(
t
*
testing
.
T
)
{
...
...
path/path.go
浏览文件 @
d904e888
...
...
@@ -10,15 +10,25 @@ import (
)
var
(
// ErrBadPath is returned when a given path is incorrectly formatted
ErrBadPath
=
errors
.
New
(
"invalid 'ipfs ref' path"
)
// ErrNoComponents is used when Paths after a protocol
// do not contain at least one component
ErrNoComponents
=
errors
.
New
(
"path must contain at least one component"
)
)
// ErrBadPath is returned when a given path is incorrectly formatted
type
ErrBadPath
struct
{
Err
error
}
func
(
e
ErrBadPath
)
Error
()
string
{
errStr
:=
"invalid 'ipfs ref' path"
if
e
.
Err
!=
nil
{
errStr
+=
": "
+
e
.
Err
.
Error
()
}
return
errStr
}
// A Path represents an ipfs content path:
// * /<cid>/path/to/file
// * /ipfs/<cid>
...
...
@@ -106,14 +116,14 @@ func ParsePath(txt string) (Path, error) {
// we expect this to start with a hash, and be an 'ipfs' path
if
parts
[
0
]
!=
""
{
if
_
,
err
:=
ParseCidToPath
(
parts
[
0
]);
err
!=
nil
{
return
""
,
ErrBadPath
return
""
,
ErrBadPath
{
err
}
}
// The case when the path starts with hash without a protocol prefix
return
Path
(
"/ipfs/"
+
txt
),
nil
}
if
len
(
parts
)
<
3
{
return
""
,
ErrBadPath
return
""
,
ErrBadPath
{}
}
if
parts
[
1
]
==
"ipfs"
{
...
...
@@ -121,7 +131,7 @@ func ParsePath(txt string) (Path, error) {
return
""
,
err
}
}
else
if
parts
[
1
]
!=
"ipns"
{
return
""
,
ErrBadPath
return
""
,
ErrBadPath
{}
}
return
Path
(
txt
),
nil
...
...
test/integration/bitswap_wo_routing_test.go
浏览文件 @
d904e888
...
...
@@ -70,7 +70,8 @@ func TestBitswapWithoutRouting(t *testing.T) {
}
log
.
Debugf
(
"%d %s get block."
,
i
,
n
.
Identity
)
b
,
err
:=
n
.
Blocks
.
GetBlock
(
ctx
,
cid
.
NewCidV0
(
block0
.
Multihash
()))
c
,
_
:=
cid
.
NewCidV0
(
block0
.
Multihash
())
b
,
err
:=
n
.
Blocks
.
GetBlock
(
ctx
,
c
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
else
if
!
bytes
.
Equal
(
b
.
RawData
(),
block0
.
RawData
())
{
...
...
@@ -87,7 +88,8 @@ func TestBitswapWithoutRouting(t *testing.T) {
// get it out.
for
_
,
n
:=
range
nodes
{
b
,
err
:=
n
.
Blocks
.
GetBlock
(
ctx
,
cid
.
NewCidV0
(
block1
.
Multihash
()))
c
,
_
:=
cid
.
NewCidV0
(
block1
.
Multihash
())
b
,
err
:=
n
.
Blocks
.
GetBlock
(
ctx
,
c
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
else
if
!
bytes
.
Equal
(
b
.
RawData
(),
block1
.
RawData
())
{
...
...
test/sharness/t0275-cid-security-data/AFKSEBCGPUJZE.data
0 → 100644
浏览文件 @
d904e888
testing
test/sharness/t0275-cid-security.sh
0 → 100755
浏览文件 @
d904e888
#!/usr/bin/env bash
#
# Copyright (c) 2017 Jakub Sztandera
# MIT Licensed; see the LICENSE file in this repository.
#
test_description
=
"Cid Security"
.
lib/test-lib.sh
test_init_ipfs
test_expect_success
"adding using unsafe function fails with error"
'
echo foo | test_must_fail ipfs add --hash murmur3 2>add_out
'
test_expect_success
"error reason is pointed out"
'
grep "insecure hash functions not allowed" add_out
'
test_expect_success
"adding using too short of a hash function gives out an error"
'
echo foo | test_must_fail ipfs block put --format protobuf --mhlen 19 2>block_out
'
test_expect_success
"error reason is pointed out"
'
grep "hashes must be at least 20 bytes long" block_out
'
test_cat_get
()
{
test_expect_success
"ipfs cat fails with unsafe hash function"
'
test_must_fail ipfs cat zDvnoLcPKWR 2>ipfs_cat
'
test_expect_success
"error reason is pointed out"
'
grep "insecure hash functions not allowed" ipfs_cat
'
test_expect_success
"ipfs get fails with too short function"
'
test_must_fail ipfs get z2ba5YhCCFNFxLtxMygQwjBjYSD8nUeN 2>ipfs_get
'
test_expect_success
"error reason is pointed out"
'
grep "hashes must be at least 20 bytes long" ipfs_get
'
}
test_gc
()
{
test_expect_success
"injecting insecure block"
'
mkdir -p "$IPFS_PATH/blocks/JZ" &&
cp -f ../t0275-cid-security-data/AFKSEBCGPUJZE.data "$IPFS_PATH/blocks/JZ" &&
ipfs refs local
'
test_expect_success
"gc works"
'ipfs repo gc > gc_out'
test_expect_success
"gc removed bad block"
'
grep zDvnoGUyhEq gc_out
'
}
# should work offline
test_cat_get
test_gc
# should work online
test_launch_ipfs_daemon
test_cat_get
test_gc
test_expect_success
"add block linking to insecure"
'
mkdir -p "$IPFS_PATH/blocks/5X" &&
cp -f "../t0275-cid-security-data/CIQG6PGTD2VV34S33BE4MNCQITBRFYUPYQLDXYARR3DQW37MOT7K5XI.data" "$IPFS_PATH/blocks/5X"
'
test_expect_success
"ipfs cat fails with code 1 and not timeout"
'
test_expect_code 1 go-timeout 1s ipfs cat QmVpsktzNeJdfWEpyeix93QJdQaBSgRNxebSbYSo9SQPGx
'
test_kill_ipfs_daemon
test_done
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论