mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-09-05 08:37:45 -04:00
archive download
This commit is contained in:
committed by
Pierre Dubouilh
parent
dd6cb90e9d
commit
c1eeb9820a
+22
-1
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -24,11 +25,16 @@ func trimSpaces(str string) string {
|
||||
return space.ReplaceAllString(str, " ")
|
||||
}
|
||||
|
||||
func get(t *testing.T, url string) string {
|
||||
func getRaw(t *testing.T, url string) []byte {
|
||||
resp, err := http.Get(url)
|
||||
dieMaybe(t, err)
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
dieMaybe(t, err)
|
||||
return body
|
||||
}
|
||||
|
||||
func get(t *testing.T, url string) string {
|
||||
body := getRaw(t, url)
|
||||
return trimSpaces(string(body))
|
||||
}
|
||||
|
||||
@@ -115,6 +121,21 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
|
||||
fetchAndTestDefault(t, url+path) // extra path will just redirect to root dir
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
fmt.Println("\r\n~~~~~~~~~~ test zip")
|
||||
bodyRaw := getRaw(t, url+"zip?zipPath=%2F%E4%B8%AD%E6%96%87%2F&zipName=%E4%B8%AD%E6%96%87")
|
||||
hashStr := fmt.Sprintf("%x", sha256.Sum256(bodyRaw))
|
||||
if hashStr != "b02436a76b149e6c4458bbbe622ab7c5e789bb0d26b87f604cf0f989cfaf669f" {
|
||||
t.Fatal("invalid zip checksum", hashStr)
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
fmt.Println("\r\n~~~~~~~~~~ test zip invalid path")
|
||||
body0 = get(t, url+"zip?zipPath=%2Ftmp&zipName=subdir")
|
||||
if body0 == `ok` {
|
||||
t.Fatal("zip passed for invalid path")
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
fmt.Println("\r\n~~~~~~~~~~ test mkdir rpc")
|
||||
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`)
|
||||
|
||||
Reference in New Issue
Block a user