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:
Wyatt Daviau 2018-05-02 09:44:51 -04:00 committed by Hector Sanjuan
parent 1c91a99492
commit 433928d3df
2 changed files with 32 additions and 11 deletions

View File

@ -508,12 +508,36 @@ func (api *API) addFileHandler(w http.ResponseWriter, r *http.Request) {
urlParams := r.URL.Query() urlParams := r.URL.Query()
layout := urlParams.Get("layout") layout := urlParams.Get("layout")
if layout != "" && layout != "trickle" && layout != "balanced" {
sendErrorResponse(w, 400, "parameter trickle invalid")
return
}
chunker := urlParams.Get("chunker") chunker := urlParams.Get("chunker")
raw, _ := strconv.ParseBool(urlParams.Get("raw")) raw, err := strconv.ParseBool(urlParams.Get("raw"))
hidden, _ := strconv.ParseBool(urlParams.Get("hidden")) if err != nil {
shard, _ := strconv.ParseBool(urlParams.Get("shard")) sendErrorResponse(w, 400, "parameter raw invalid")
replMin, _ := strconv.Atoi(urlParams.Get("repl_min")) return
replMax, _ := strconv.Atoi(urlParams.Get("repl_max")) }
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{ params := types.AddParams{
Layout: layout, Layout: layout,
Chunker: chunker, Chunker: chunker,

View File

@ -8,16 +8,14 @@ test_ipfs_init
test_cluster_init test_cluster_init
test_expect_success IPFS,CLUSTER "add small file to cluster with ctl" ' test_expect_success IPFS,CLUSTER "add small file to cluster with ctl" '
output=`ipfs-cluster-ctl add ../test_data/small_file | tail -1` && cid=`ipfs-cluster-ctl add --only-hashes ../test_data/small_file | tail -1` &&
cid=${output:7:47} &&
ipfs-cluster-ctl pin ls | grep -q "$cid" && ipfs-cluster-ctl pin ls | grep -q "$cid" &&
ipfs-cluster-ctl pin rm $cid && ipfs-cluster-ctl pin rm $cid &&
[[ -z "$(ipfs-cluster-ctl pin ls)" ]] [[ -z "$(ipfs-cluster-ctl pin ls)" ]]
' '
test_expect_success IPFS,CLUSTER "add sharded small file to cluster" ' test_expect_success IPFS,CLUSTER "add sharded small file to cluster" '
output=`ipfs-cluster-ctl add --shard ../test_data/small_file | tail -1` && cid=`ipfs-cluster-ctl add --only-hashes --shard ../test_data/small_file | tail -1` &&
cid=${output:7:47} &&
[[ -z "$(ipfs-cluster-ctl pin ls)" ]] && [[ -z "$(ipfs-cluster-ctl pin ls)" ]] &&
ipfs-cluster-ctl pin ls -a | grep -q "$cid" && ipfs-cluster-ctl pin ls -a | grep -q "$cid" &&
[[ $(ipfs-cluster-ctl pin ls -a | wc -l) -eq "3" ]] && [[ $(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" ' test_expect_success IPFS,CLUSTER "add same file sharded and unsharded" '
output=`ipfs-cluster-ctl add --shard ../test_data/small_file | tail -1` && cid=`ipfs-cluster-ctl add --only-hashes --shard ../test_data/small_file | tail -1` &&
cid=${output:7:47} &&
test_expect_code 2 ipfs-cluster-ctl add ../test_data/small_file && test_expect_code 2 ipfs-cluster-ctl add ../test_data/small_file &&
ipfs-cluster-ctl pin rm $cid && ipfs-cluster-ctl pin rm $cid &&
ipfs-cluster-ctl add ../test_data/small_file ipfs-cluster-ctl add ../test_data/small_file