mirror of
https://github.com/Forceu/Gokapi.git
synced 2026-01-17 14:29:32 -06:00
63 lines
2.1 KiB
Go
63 lines
2.1 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/forceu/gokapi/internal/test"
|
|
"testing"
|
|
)
|
|
|
|
func TestToJsonResult(t *testing.T) {
|
|
file := File{
|
|
Id: "testId",
|
|
Name: "testName",
|
|
Size: "10 B",
|
|
SizeBytes: 10,
|
|
SHA1: "sha256",
|
|
ExpireAt: 50,
|
|
ExpireAtString: "future",
|
|
DownloadsRemaining: 1,
|
|
PasswordHash: "pwhash",
|
|
HotlinkId: "hotlinkid",
|
|
ContentType: "text/html",
|
|
AwsBucket: "test",
|
|
DownloadCount: 3,
|
|
Encryption: EncryptionInfo{
|
|
IsEncrypted: true,
|
|
DecryptionKey: []byte{0x01},
|
|
Nonce: []byte{0x02},
|
|
},
|
|
UnlimitedDownloads: true,
|
|
UnlimitedTime: true,
|
|
}
|
|
test.IsEqualString(t, file.ToJsonResult("serverurl/"), `{"Result":"OK","FileInfo":{"Id":"testId","Name":"testName","Size":"10 B","HotlinkId":"hotlinkid","ContentType":"text/html","ExpireAt":50,"SizeBytes":10,"ExpireAtString":"future","DownloadsRemaining":1,"DownloadCount":3,"UnlimitedDownloads":true,"UnlimitedTime":true,"RequiresClientSideDecryption":true,"IsEncrypted":true,"IsPasswordProtected":true,"IsSavedOnLocalStorage":false},"Url":"serverurl/d?id=","HotlinkUrl":"serverurl/hotlink/","GenericHotlinkUrl":"serverurl/downloadFile?id="}`)
|
|
}
|
|
|
|
func TestIsLocalStorage(t *testing.T) {
|
|
file := File{AwsBucket: "123"}
|
|
test.IsEqualBool(t, file.IsLocalStorage(), false)
|
|
file.AwsBucket = ""
|
|
test.IsEqualBool(t, file.IsLocalStorage(), true)
|
|
}
|
|
|
|
func TestErrorAsJson(t *testing.T) {
|
|
result := errorAsJson(errors.New("testerror"))
|
|
test.IsEqualString(t, result, "{\"Result\":\"error\",\"ErrorMessage\":\"testerror\"}")
|
|
}
|
|
|
|
func TestRequiresClientDecryption(t *testing.T) {
|
|
file := File{
|
|
Id: "test",
|
|
AwsBucket: "bucket",
|
|
Encryption: EncryptionInfo{
|
|
IsEncrypted: true,
|
|
},
|
|
}
|
|
test.IsEqualBool(t, file.RequiresClientDecryption(), true)
|
|
file.Encryption.IsEncrypted = false
|
|
test.IsEqualBool(t, file.RequiresClientDecryption(), false)
|
|
file.AwsBucket = ""
|
|
test.IsEqualBool(t, file.RequiresClientDecryption(), false)
|
|
file.Encryption.IsEncrypted = true
|
|
test.IsEqualBool(t, file.RequiresClientDecryption(), false)
|
|
}
|