Test deletion key
This commit is contained in:
parent
c7e679039a
commit
738bf25f44
|
@ -226,7 +226,7 @@ func TestPutJSONUpload(t *testing.T) {
|
||||||
type RespJSON struct {
|
type RespJSON struct {
|
||||||
Filename string
|
Filename string
|
||||||
Url string
|
Url string
|
||||||
DeleteKey string
|
Delete_Key string
|
||||||
Expiry string
|
Expiry string
|
||||||
Size string
|
Size string
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ func TestPutRandomizedJSONUpload(t *testing.T) {
|
||||||
type RespJSON struct {
|
type RespJSON struct {
|
||||||
Filename string
|
Filename string
|
||||||
Url string
|
Url string
|
||||||
DeleteKey string
|
Delete_Key string
|
||||||
Expiry string
|
Expiry string
|
||||||
Size string
|
Size string
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ func TestPutExpireJSONUpload(t *testing.T) {
|
||||||
type RespJSON struct {
|
type RespJSON struct {
|
||||||
Filename string
|
Filename string
|
||||||
Url string
|
Url string
|
||||||
DeleteKey string
|
Delete_Key string
|
||||||
Expiry string
|
Expiry string
|
||||||
Size string
|
Size string
|
||||||
}
|
}
|
||||||
|
@ -327,6 +327,99 @@ func TestPutExpireJSONUpload(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPutAndDelete(t *testing.T) {
|
||||||
|
type RespJSON struct {
|
||||||
|
Filename string
|
||||||
|
Url string
|
||||||
|
Delete_Key string
|
||||||
|
Expiry string
|
||||||
|
Size string
|
||||||
|
}
|
||||||
|
var myjson RespJSON
|
||||||
|
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("PUT", "/upload", strings.NewReader("File content"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
goji.DefaultMux.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(w.Body.String()), &myjson)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete it
|
||||||
|
w = httptest.NewRecorder()
|
||||||
|
req, err = http.NewRequest("DELETE", "/"+myjson.Filename, nil)
|
||||||
|
req.Header.Set("X-Delete-Key", myjson.Delete_Key)
|
||||||
|
goji.DefaultMux.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if w.Code != 404 {
|
||||||
|
t.Fatal("Status code was not 404, but " + strconv.Itoa(w.Code))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure it's actually gone
|
||||||
|
w = httptest.NewRecorder()
|
||||||
|
req, err = http.NewRequest("GET", "/"+myjson.Filename, nil)
|
||||||
|
goji.DefaultMux.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if w.Code != 404 {
|
||||||
|
t.Fatal("Status code was not 404, but " + strconv.Itoa(w.Code))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPutAndSpecificDelete(t *testing.T) {
|
||||||
|
type RespJSON struct {
|
||||||
|
Filename string
|
||||||
|
Url string
|
||||||
|
Delete_Key string
|
||||||
|
Expiry string
|
||||||
|
Size string
|
||||||
|
}
|
||||||
|
var myjson RespJSON
|
||||||
|
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("PUT", "/upload", strings.NewReader("File content"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
req.Header.Set("X-Delete-Key", "supersecret")
|
||||||
|
|
||||||
|
goji.DefaultMux.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(w.Body.String()), &myjson)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete it
|
||||||
|
w = httptest.NewRecorder()
|
||||||
|
req, err = http.NewRequest("DELETE", "/"+myjson.Filename, nil)
|
||||||
|
req.Header.Set("X-Delete-Key", "supersecret")
|
||||||
|
goji.DefaultMux.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if w.Code != 404 {
|
||||||
|
t.Fatal("Status code was not 404, but " + strconv.Itoa(w.Code))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure it's actually gone
|
||||||
|
w = httptest.NewRecorder()
|
||||||
|
req, err = http.NewRequest("GET", "/"+myjson.Filename, nil)
|
||||||
|
goji.DefaultMux.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if w.Code != 404 {
|
||||||
|
t.Fatal("Status code was not 404, but " + strconv.Itoa(w.Code))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestShutdown(t *testing.T) {
|
func TestShutdown(t *testing.T) {
|
||||||
os.RemoveAll(Config.filesDir)
|
os.RemoveAll(Config.filesDir)
|
||||||
os.RemoveAll(Config.metaDir)
|
os.RemoveAll(Config.metaDir)
|
||||||
|
|
Loading…
Reference in New Issue