Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/storage/FileServing.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,10 @@ func ServeFile(file models.File, w http.ResponseWriter, r *http.Request, forceDo
// confirm that the file has been completely downloaded. It expires automatically after 24 hours.
statusId := downloadstatus.SetDownload(file)
isBlocking, err := aws.ServeFile(w, r, file, forceDownload, forceDecryption)
// TODO chances are high that an error is returned here, we should consider proper output
helper.Check(err)
if err != nil {
fmt.Println(err)
_, _ = w.Write([]byte("Error serving file"))
}
if isBlocking {
downloadstatus.SetComplete(statusId)
}
Expand Down
34 changes: 34 additions & 0 deletions internal/storage/FileServing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,40 @@ func TestServeFile(t *testing.T) {
test.ResponseBodyContains(t, w, "Error decrypting file")
}

func TestServeFileAwsErrorHandling(t *testing.T) {
if !aws.IsIncludedInBuild {
t.Skip("AWS support not included in build")
}
testconfiguration.EnableS3()
config, ok := cloudconfig.Load()
test.IsEqualBool(t, ok, true)
ok = aws.Init(config.Aws)
test.IsEqualBool(t, ok, true)

// A file with an AWS bucket set, but never actually uploaded, causes aws.ServeFile to
// return an error. ServeFile must handle that gracefully instead of panicking.
// forceDecryption is set to true so aws.ServeFile takes the serveDecryptedFile path,
// which calls s3.GetObject directly instead of just presigning a redirect URL - only
// that path actually contacts S3 and surfaces the missing-object error.
file := models.File{
Id: "awsErrorHandlingTest1",
Name: "aws error handling test",
AwsBucket: "gokapi-test",
SHA1: "nonexistentAwsObjectSha1",
ExpireAt: time.Now().Add(time.Hour).Unix(),
SizeBytes: 10,
}
database.SaveMetaData(file)

r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
ServeFile(file, w, r, false, true, true, false)
test.ResponseBodyContains(t, w, "Error serving file")

database.DeleteMetaData(file.Id)
testconfiguration.DisableS3()
}

func TestCleanUp(t *testing.T) {
files := database.GetAllMetadata()
downloadstatus.DeleteAll()
Expand Down
Loading