addressing more feedback:
validation of url params in restapi fileadd handler use --only-hashes in sharness to simplify cid parse License: MIT Signed-off-by: Wyatt Daviau <wdaviau@cs.stanford.edu>
This commit is contained in:
parent
1c91a99492
commit
433928d3df
|
@ -508,12 +508,36 @@ func (api *API) addFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
urlParams := r.URL.Query()
|
||||
layout := urlParams.Get("layout")
|
||||
if layout != "" && layout != "trickle" && layout != "balanced" {
|
||||
sendErrorResponse(w, 400, "parameter trickle invalid")
|
||||
return
|
||||
}
|
||||
chunker := urlParams.Get("chunker")
|
||||
raw, _ := strconv.ParseBool(urlParams.Get("raw"))
|
||||
hidden, _ := strconv.ParseBool(urlParams.Get("hidden"))
|
||||
shard, _ := strconv.ParseBool(urlParams.Get("shard"))
|
||||
replMin, _ := strconv.Atoi(urlParams.Get("repl_min"))
|
||||
replMax, _ := strconv.Atoi(urlParams.Get("repl_max"))
|
||||
raw, err := strconv.ParseBool(urlParams.Get("raw"))
|
||||
if err != nil {
|
||||
sendErrorResponse(w, 400, "parameter raw invalid")
|
||||
return
|
||||
}
|
||||
hidden, err := strconv.ParseBool(urlParams.Get("hidden"))
|
||||
if err != nil {
|
||||
sendErrorResponse(w, 400, "parameter hidden invalid")
|
||||
return
|
||||
}
|
||||
shard, err := strconv.ParseBool(urlParams.Get("shard"))
|
||||
if err != nil {
|
||||
sendErrorResponse(w, 400, "parameter shard invalid")
|
||||
return
|
||||
}
|
||||
replMin, err := strconv.Atoi(urlParams.Get("repl_min"))
|
||||
if err != nil || replMin < -1 {
|
||||
sendErrorResponse(w, 400, "parameter replMin invalid")
|
||||
return
|
||||
}
|
||||
replMax, err := strconv.Atoi(urlParams.Get("repl_max"))
|
||||
if err != nil || replMax < -1 {
|
||||
sendErrorResponse(w, 400, "parameter replMax invalid")
|
||||
return
|
||||
}
|
||||
params := types.AddParams{
|
||||
Layout: layout,
|
||||
Chunker: chunker,
|
||||
|
|
|
@ -8,16 +8,14 @@ test_ipfs_init
|
|||
test_cluster_init
|
||||
|
||||
test_expect_success IPFS,CLUSTER "add small file to cluster with ctl" '
|
||||
output=`ipfs-cluster-ctl add ../test_data/small_file | tail -1` &&
|
||||
cid=${output:7:47} &&
|
||||
cid=`ipfs-cluster-ctl add --only-hashes ../test_data/small_file | tail -1` &&
|
||||
ipfs-cluster-ctl pin ls | grep -q "$cid" &&
|
||||
ipfs-cluster-ctl pin rm $cid &&
|
||||
[[ -z "$(ipfs-cluster-ctl pin ls)" ]]
|
||||
'
|
||||
|
||||
test_expect_success IPFS,CLUSTER "add sharded small file to cluster" '
|
||||
output=`ipfs-cluster-ctl add --shard ../test_data/small_file | tail -1` &&
|
||||
cid=${output:7:47} &&
|
||||
cid=`ipfs-cluster-ctl add --only-hashes --shard ../test_data/small_file | tail -1` &&
|
||||
[[ -z "$(ipfs-cluster-ctl pin ls)" ]] &&
|
||||
ipfs-cluster-ctl pin ls -a | grep -q "$cid" &&
|
||||
[[ $(ipfs-cluster-ctl pin ls -a | wc -l) -eq "3" ]] &&
|
||||
|
@ -26,8 +24,7 @@ test_expect_success IPFS,CLUSTER "add sharded small file to cluster" '
|
|||
'
|
||||
|
||||
test_expect_success IPFS,CLUSTER "add same file sharded and unsharded" '
|
||||
output=`ipfs-cluster-ctl add --shard ../test_data/small_file | tail -1` &&
|
||||
cid=${output:7:47} &&
|
||||
cid=`ipfs-cluster-ctl add --only-hashes --shard ../test_data/small_file | tail -1` &&
|
||||
test_expect_code 2 ipfs-cluster-ctl add ../test_data/small_file &&
|
||||
ipfs-cluster-ctl pin rm $cid &&
|
||||
ipfs-cluster-ctl add ../test_data/small_file
|
||||
|
|
Loading…
Reference in New Issue
Block a user