diff --git a/cmd/gokapi/Main.go b/cmd/gokapi/Main.go index 7a8f6ce..72de0d0 100644 --- a/cmd/gokapi/Main.go +++ b/cmd/gokapi/Main.go @@ -29,9 +29,9 @@ import ( // Version is the current version in readable form. // The go generate call below needs to be modified as well -const Version = "1.5.0-beta1" +const Version = "1.5.0" -//go:generate sh "../../build/setVersionTemplate.sh" "1.5.0-beta1" +//go:generate sh "../../build/setVersionTemplate.sh" "1.5.0" //go:generate sh -c "cp \"$(go env GOROOT)/misc/wasm/wasm_exec.js\" ../../internal/webserver/web/static/js/ && echo Copied wasm_exec.js" //go:generate sh -c "GOOS=js GOARCH=wasm go build -o ../../internal/webserver/web/main.wasm github.com/forceu/gokapi/cmd/wasmdownloader && echo Compiled WASM module" diff --git a/internal/storage/FileServing_test.go b/internal/storage/FileServing_test.go index 0e9adf0..c4f6c21 100644 --- a/internal/storage/FileServing_test.go +++ b/internal/storage/FileServing_test.go @@ -52,9 +52,50 @@ func TestGetFile(t *testing.T) { test.IsEqualInt(t, file.DownloadsRemaining, 1) _, result = GetFile("deletedfile1234") test.IsEqualBool(t, result, false) + _, result = GetFile("") + test.IsEqualBool(t, result, false) + file = models.File{ + Id: "testget", + Name: "testget", + SHA256: "testget", + UnlimitedDownloads: true, + UnlimitedTime: true, + } + datastorage.SaveMetaData(file) + _, result = GetFile(file.Id) + test.IsEqualBool(t, result, false) } +func TestGetEncInfoFromExistingFile(t *testing.T) { + configuration.Get().Encryption.Level = 0 + _, result := getEncInfoFromExistingFile("testhash") + test.IsEqualBool(t, result, true) + file := models.File{ + Id: "testhash", + Name: "testhash", + SHA256: "testhash", + Encryption: models.EncryptionInfo{ + IsEncrypted: true, + DecryptionKey: nil, + Nonce: nil, + }, + UnlimitedDownloads: true, + UnlimitedTime: true, + } + datastorage.SaveMetaData(file) + encinfo, result := getEncInfoFromExistingFile("testhash") + test.IsEqualBool(t, encinfo.IsEncrypted, false) + test.IsEqualBool(t, result, true) + configuration.Get().Encryption.Level = 1 + encinfo, result = getEncInfoFromExistingFile("testhash") + test.IsEqualBool(t, result, true) + test.IsEqualBool(t, encinfo.IsEncrypted, true) + _, result = getEncInfoFromExistingFile("testhashinvalid") + test.IsEqualBool(t, result, false) + configuration.Get().Encryption.Level = 0 +} + func TestGetFileByHotlink(t *testing.T) { _, result := GetFileByHotlink("invalid") test.IsEqualBool(t, result, false) @@ -210,11 +251,10 @@ func TestNewFile(t *testing.T) { MaxMemory: 10, DataDir: "test/data", } - _, err = NewFile(bigFile, &header, request) + file, err = NewFile(bigFile, &header, request) test.IsNotNil(t, err) retrievedFile, ok = datastorage.GetMetaDataById(file.Id) - test.IsEqualBool(t, ok, true) - test.IsEqualString(t, retrievedFile.Name, "bigfile") + test.IsEqualBool(t, ok, false) bigFile.Close() os.Remove("bigfile") @@ -233,6 +273,19 @@ func TestNewFile(t *testing.T) { retrievedFile, ok = datastorage.GetMetaDataById(newFile.File.Id) test.IsEqualBool(t, ok, true) test.IsEqualString(t, retrievedFile.SHA256, "5bbfa18805eb12c678cfd284c956718d57039e37") + + createBigFile("bigfile", 20) + header.Size = int64(20) * 1024 * 1024 + bigFile, _ = os.Open("bigfile") + file, err = NewFile(bigFile, &header, request) + test.IsNil(t, err) + retrievedFile, ok = datastorage.GetMetaDataById(file.Id) + test.IsEqualBool(t, ok, true) + test.IsEqualString(t, retrievedFile.Name, "bigfile") + test.IsEqualString(t, retrievedFile.SHA256, "c1c165c30d0def15ba2bc8f1bd243be13b8c8fe7") + + bigFile.Close() + os.Remove("bigfile") configuration.Get().Authentication.SaltFiles = previousSalt configuration.Get().Encryption.Level = 0 @@ -301,7 +354,7 @@ func TestServeFile(t *testing.T) { testconfiguration.DisableS3() } newFile, err := createTestFile() - test.IsNotNil(t, err) + test.IsNil(t, err) file = newFile.File datastorage.SaveMetaData(file) r = httptest.NewRequest("GET", "/upload", nil) diff --git a/internal/storage/cloudstorage/aws/AwsS3.go b/internal/storage/cloudstorage/aws/AwsS3.go index c7448a7..64628d5 100644 --- a/internal/storage/cloudstorage/aws/AwsS3.go +++ b/internal/storage/cloudstorage/aws/AwsS3.go @@ -43,6 +43,12 @@ func IsAvailable() bool { return isCorrectLogin } +// LogOut resets the credentials, only used for testing purposes +func LogOut() { + awsConfig = models.AwsConfig{} + isCorrectLogin = false +} + func isValidLogin() bool { if !awsConfig.IsAllProvided() { return false diff --git a/internal/storage/cloudstorage/aws/AwsS3_mock.go b/internal/storage/cloudstorage/aws/AwsS3_mock.go index cdc2229..66aa839 100644 --- a/internal/storage/cloudstorage/aws/AwsS3_mock.go +++ b/internal/storage/cloudstorage/aws/AwsS3_mock.go @@ -49,6 +49,11 @@ func IsAvailable() bool { return isCorrectLogin } +// LogOut resets the credentials, only used for testing purposes +func LogOut() { + isCorrectLogin = false +} + // AddBucketName adds the bucket name to the file to be stored func AddBucketName(file *models.File) { file.AwsBucket = bucketName diff --git a/internal/storage/cloudstorage/aws/AwsS3_slim.go b/internal/storage/cloudstorage/aws/AwsS3_slim.go index ab712a3..ec27279 100644 --- a/internal/storage/cloudstorage/aws/AwsS3_slim.go +++ b/internal/storage/cloudstorage/aws/AwsS3_slim.go @@ -43,6 +43,10 @@ func Download(writer io.WriterAt, file models.File) (int64, error) { return 0, errors.New(errorString) } +// LogOut resets the credentials, only used for testing purposes +func LogOut() { +} + // RedirectToDownload creates a presigned link that is valid for 15 seconds and redirects the // client to this url func RedirectToDownload(w http.ResponseWriter, r *http.Request, file models.File, forceDownload bool) error { diff --git a/internal/storage/cloudstorage/aws/AwsS3_test.go b/internal/storage/cloudstorage/aws/AwsS3_test.go index 74a1aa9..be3284d 100644 --- a/internal/storage/cloudstorage/aws/AwsS3_test.go +++ b/internal/storage/cloudstorage/aws/AwsS3_test.go @@ -132,3 +132,8 @@ func TestDeleteObject(t *testing.T) { test.IsEqualBool(t, result, true) test.IsNil(t, err) } +func TestLogOut(t *testing.T) { + test.IsEqualBool(t, isCorrectLogin, true) + LogOut() + test.IsEqualBool(t, isCorrectLogin, false) +} diff --git a/internal/test/testconfiguration/TestConfiguration.go b/internal/test/testconfiguration/TestConfiguration.go index caacc7d..d39d1cf 100644 --- a/internal/test/testconfiguration/TestConfiguration.go +++ b/internal/test/testconfiguration/TestConfiguration.go @@ -149,6 +149,7 @@ func StartS3TestServer() *httptest.Server { // DisableS3 unsets env variables for mock S3 func DisableS3() { + aws.LogOut() if !aws.IsMockApi { return } @@ -337,7 +338,7 @@ var configTestFile = []byte(`{ "ConfigVersion": 11, "LengthId": 20, "DataDir": "test/data", - "MaxMemory": 40, + "MaxMemory": 10, "UseSsl": false, "MaxFileSizeMB": 25 }`) diff --git a/internal/webserver/web/templates/string_constants.tmpl b/internal/webserver/web/templates/string_constants.tmpl index 944c9ba..07142bf 100644 --- a/internal/webserver/web/templates/string_constants.tmpl +++ b/internal/webserver/web/templates/string_constants.tmpl @@ -1,2 +1,2 @@ {{define "app_name"}}Gokapi{{end}} -{{define "version"}}1.5.0-beta1{{end}} +{{define "version"}}1.5.0{{end}}