2020-02-02 18:41:18 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2022-10-13 22:11:02 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-11-21 18:08:41 +01:00
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
2022-10-13 22:11:02 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2020-02-02 18:41:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetDownload(t *testing.T) {
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("NotFound", func(t *testing.T) {
|
2020-02-02 18:41:18 +01:00
|
|
|
app, router, conf := NewApiTest()
|
2020-06-25 14:54:04 +02:00
|
|
|
GetDownload(router)
|
2020-05-27 19:38:40 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/dl/123xxx?t="+conf.DownloadToken())
|
2020-05-04 14:40:58 +02:00
|
|
|
val := gjson.Get(r.Body.String(), "error")
|
|
|
|
assert.Equal(t, "record not found", val.String())
|
|
|
|
assert.Equal(t, http.StatusNotFound, r.Code)
|
2020-02-02 18:41:18 +01:00
|
|
|
})
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("MissingOriginal", func(t *testing.T) {
|
2020-02-02 18:41:18 +01:00
|
|
|
app, router, conf := NewApiTest()
|
2020-06-25 14:54:04 +02:00
|
|
|
GetDownload(router)
|
2020-05-27 19:38:40 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/dl/3cad9168fa6acc5c5c2965ddf6ec465ca42fd818?t="+conf.DownloadToken())
|
2020-05-04 14:40:58 +02:00
|
|
|
assert.Equal(t, http.StatusNotFound, r.Code)
|
2020-02-02 18:41:18 +01:00
|
|
|
})
|
2022-10-13 22:11:02 +02:00
|
|
|
t.Run("InvalidDownloadToken", func(t *testing.T) {
|
|
|
|
app, router, conf := NewApiTest()
|
|
|
|
conf.SetAuthMode(config.AuthModePasswd)
|
|
|
|
defer conf.SetAuthMode(config.AuthModePublic)
|
2020-07-14 11:24:00 +02:00
|
|
|
GetDownload(router)
|
|
|
|
r := PerformRequest(app, "GET", "/api/v1/dl/3cad9168fa6acc5c5c2965ddf6ec465ca42fd818?t=xxx")
|
|
|
|
assert.Equal(t, http.StatusForbidden, r.Code)
|
|
|
|
})
|
2020-02-02 18:41:18 +01:00
|
|
|
}
|