|
@@ -12651,6 +12651,8 @@ func TestWebGetFiles(t *testing.T) {
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusPartialContent, rr)
|
|
|
assert.Equal(t, testFileContents[2:], rr.Body.Bytes())
|
|
|
+ lastModified, err := http.ParseTime(rr.Header().Get("Last-Modified"))
|
|
|
+ assert.NoError(t, err)
|
|
|
|
|
|
req, _ = http.NewRequest(http.MethodGet, userFilesPath+"?path="+testFileName, nil)
|
|
|
req.Header.Set("Range", "bytes=2-")
|
|
@@ -12686,44 +12688,44 @@ func TestWebGetFiles(t *testing.T) {
|
|
|
|
|
|
req, _ = http.NewRequest(http.MethodHead, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
req.Header.Set("Range", "bytes=2-")
|
|
|
- req.Header.Set("If-Range", time.Now().UTC().Add(120*time.Second).Format(http.TimeFormat))
|
|
|
+ req.Header.Set("If-Range", lastModified.UTC().Format(http.TimeFormat))
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusPartialContent, rr)
|
|
|
|
|
|
req, _ = http.NewRequest(http.MethodHead, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
req.Header.Set("Range", "bytes=2-")
|
|
|
- req.Header.Set("If-Range", time.Now().UTC().Add(-120*time.Second).Format(http.TimeFormat))
|
|
|
+ req.Header.Set("If-Range", lastModified.UTC().Add(-120*time.Second).Format(http.TimeFormat))
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
|
|
|
req, _ = http.NewRequest(http.MethodHead, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
- req.Header.Set("If-Modified-Since", time.Now().UTC().Add(-120*time.Second).Format(http.TimeFormat))
|
|
|
+ req.Header.Set("If-Modified-Since", lastModified.UTC().Add(-120*time.Second).Format(http.TimeFormat))
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
|
|
|
|
req, _ = http.NewRequest(http.MethodHead, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
- req.Header.Set("If-Modified-Since", time.Now().UTC().Add(120*time.Second).Format(http.TimeFormat))
|
|
|
+ req.Header.Set("If-Modified-Since", lastModified.UTC().Add(120*time.Second).Format(http.TimeFormat))
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusNotModified, rr)
|
|
|
|
|
|
req, _ = http.NewRequest(http.MethodHead, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
- req.Header.Set("If-Unmodified-Since", time.Now().UTC().Add(-120*time.Second).Format(http.TimeFormat))
|
|
|
+ req.Header.Set("If-Unmodified-Since", lastModified.UTC().Add(-120*time.Second).Format(http.TimeFormat))
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusPreconditionFailed, rr)
|
|
|
|
|
|
req, _ = http.NewRequest(http.MethodHead, userFilesPath+"?path="+testFileName, nil)
|
|
|
- req.Header.Set("If-Unmodified-Since", time.Now().UTC().Add(-120*time.Second).Format(http.TimeFormat))
|
|
|
+ req.Header.Set("If-Unmodified-Since", lastModified.UTC().Add(-120*time.Second).Format(http.TimeFormat))
|
|
|
setBearerForReq(req, webAPIToken)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusPreconditionFailed, rr)
|
|
|
|
|
|
req, _ = http.NewRequest(http.MethodHead, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
- req.Header.Set("If-Unmodified-Since", time.Now().UTC().Add(120*time.Second).Format(http.TimeFormat))
|
|
|
+ req.Header.Set("If-Unmodified-Since", lastModified.UTC().Add(120*time.Second).Format(http.TimeFormat))
|
|
|
setJWTCookieForReq(req, webToken)
|
|
|
rr = executeRequest(req)
|
|
|
checkResponseCode(t, http.StatusOK, rr)
|
|
@@ -14115,6 +14117,7 @@ func TestGetFilesSFTPBackend(t *testing.T) {
|
|
|
user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated)
|
|
|
assert.NoError(t, err)
|
|
|
u := getTestSFTPUser()
|
|
|
+ u.HomeDir = filepath.Clean(os.TempDir())
|
|
|
u.FsConfig.SFTPConfig.BufferSize = 2
|
|
|
u.Permissions["/adir"] = nil
|
|
|
u.Permissions["/adir1"] = []string{dataprovider.PermListItems}
|
|
@@ -14124,7 +14127,11 @@ func TestGetFilesSFTPBackend(t *testing.T) {
|
|
|
DeniedPatterns: []string{"*.txt"},
|
|
|
},
|
|
|
}
|
|
|
- sftpUser, _, err := httpdtest.AddUser(u, http.StatusCreated)
|
|
|
+ sftpUserBuffered, _, err := httpdtest.AddUser(u, http.StatusCreated)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ u.Username += "_unbuffered"
|
|
|
+ u.FsConfig.SFTPConfig.BufferSize = 0
|
|
|
+ sftpUserUnbuffered, _, err := httpdtest.AddUser(u, http.StatusCreated)
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
testFileName := "testsftpfile"
|
|
@@ -14142,58 +14149,58 @@ func TestGetFilesSFTPBackend(t *testing.T) {
|
|
|
assert.NoError(t, err)
|
|
|
err = os.WriteFile(filepath.Join(user.GetHomeDir(), "adir2", "afile.txt"), testFileContents, os.ModePerm)
|
|
|
assert.NoError(t, err)
|
|
|
- webToken, err := getJWTWebClientTokenFromTestServer(sftpUser.Username, defaultPassword)
|
|
|
- assert.NoError(t, err)
|
|
|
- req, _ := http.NewRequest(http.MethodGet, webClientFilesPath, nil)
|
|
|
- setJWTCookieForReq(req, webToken)
|
|
|
- rr := executeRequest(req)
|
|
|
- checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ for _, sftpUser := range []dataprovider.User{sftpUserBuffered, sftpUserUnbuffered} {
|
|
|
+ webToken, err := getJWTWebClientTokenFromTestServer(sftpUser.Username, defaultPassword)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ req, _ := http.NewRequest(http.MethodGet, webClientFilesPath, nil)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ rr := executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
|
|
|
- req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+path.Join(testDir, "sub"), nil)
|
|
|
- setJWTCookieForReq(req, webToken)
|
|
|
- rr = executeRequest(req)
|
|
|
- checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+path.Join(testDir, "sub"), nil)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
|
|
|
- req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+path.Join(testDir, "missing"), nil)
|
|
|
- setJWTCookieForReq(req, webToken)
|
|
|
- rr = executeRequest(req)
|
|
|
- checkResponseCode(t, http.StatusOK, rr)
|
|
|
- assert.Contains(t, rr.Body.String(), "card-body text-form-error")
|
|
|
- req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path=adir/sub", nil)
|
|
|
- setJWTCookieForReq(req, webToken)
|
|
|
- rr = executeRequest(req)
|
|
|
- checkResponseCode(t, http.StatusOK, rr)
|
|
|
- assert.Contains(t, rr.Body.String(), "card-body text-form-error")
|
|
|
+ req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+path.Join(testDir, "missing"), nil)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), "card-body text-form-error")
|
|
|
+ req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path=adir/sub", nil)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), "card-body text-form-error")
|
|
|
|
|
|
- req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path=adir1/afile", nil)
|
|
|
- setJWTCookieForReq(req, webToken)
|
|
|
- rr = executeRequest(req)
|
|
|
- checkResponseCode(t, http.StatusOK, rr)
|
|
|
- assert.Contains(t, rr.Body.String(), "card-body text-form-error")
|
|
|
+ req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path=adir1/afile", nil)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), "card-body text-form-error")
|
|
|
|
|
|
- req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path=adir2/afile.txt", nil)
|
|
|
- setJWTCookieForReq(req, webToken)
|
|
|
- rr = executeRequest(req)
|
|
|
- checkResponseCode(t, http.StatusOK, rr)
|
|
|
- assert.Contains(t, rr.Body.String(), "card-body text-form-error")
|
|
|
+ req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path=adir2/afile.txt", nil)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Contains(t, rr.Body.String(), "card-body text-form-error")
|
|
|
|
|
|
- req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
- setJWTCookieForReq(req, webToken)
|
|
|
- rr = executeRequest(req)
|
|
|
- checkResponseCode(t, http.StatusOK, rr)
|
|
|
- assert.Equal(t, testFileContents, rr.Body.Bytes())
|
|
|
+ req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusOK, rr)
|
|
|
+ assert.Equal(t, testFileContents, rr.Body.Bytes())
|
|
|
|
|
|
- req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
- req.Header.Set("Range", "bytes=2-")
|
|
|
- setJWTCookieForReq(req, webToken)
|
|
|
- rr = executeRequest(req)
|
|
|
- checkResponseCode(t, http.StatusPartialContent, rr)
|
|
|
- assert.Equal(t, testFileContents[2:], rr.Body.Bytes())
|
|
|
+ req, _ = http.NewRequest(http.MethodGet, webClientFilesPath+"?path="+testFileName, nil)
|
|
|
+ req.Header.Set("Range", "bytes=2-")
|
|
|
+ setJWTCookieForReq(req, webToken)
|
|
|
+ rr = executeRequest(req)
|
|
|
+ checkResponseCode(t, http.StatusPartialContent, rr)
|
|
|
+ assert.Equal(t, testFileContents[2:], rr.Body.Bytes())
|
|
|
|
|
|
- _, err = httpdtest.RemoveUser(sftpUser, http.StatusOK)
|
|
|
- assert.NoError(t, err)
|
|
|
- err = os.RemoveAll(sftpUser.GetHomeDir())
|
|
|
- assert.NoError(t, err)
|
|
|
+ _, err = httpdtest.RemoveUser(sftpUser, http.StatusOK)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ }
|
|
|
_, err = httpdtest.RemoveUser(user, http.StatusOK)
|
|
|
assert.NoError(t, err)
|
|
|
err = os.RemoveAll(user.GetHomeDir())
|