update
This commit is contained in:
@@ -4,6 +4,7 @@ using GeneralUtils.garageS3
|
||||
using AWS
|
||||
using Random: randstring
|
||||
using UUIDs: uuid4
|
||||
using URIs
|
||||
|
||||
@testset "garageS3.jl" begin
|
||||
|
||||
@@ -460,4 +461,129 @@ using UUIDs: uuid4
|
||||
delete_lifecycle(storage)
|
||||
end
|
||||
|
||||
# --- Pre-signed URL tests ---
|
||||
|
||||
@testset "s3_sign_url returns a string" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
url = s3_sign_url(storage, "test.json", 3600)
|
||||
@test url isa String
|
||||
@test !isempty(url)
|
||||
end
|
||||
|
||||
@testset "s3_sign_url URL format contains correct endpoint, bucket, key" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
url = s3_sign_url(storage, "mykey.json", 1800)
|
||||
@test occursin("https://s3-api.yiem.cc", url)
|
||||
@test occursin("/testbucket/mykey.json?", url)
|
||||
end
|
||||
|
||||
@testset "s3_sign_url contains required query parameters" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
url = s3_sign_url(storage, "test.json", 3600)
|
||||
@test occursin("X-Amz-Algorithm=AWS4-HMAC-SHA256", url)
|
||||
@test occursin("X-Amz-Expires=3600", url)
|
||||
@test occursin("X-Amz-Credential=", url)
|
||||
@test occursin("X-Amz-Date=", url)
|
||||
@test occursin("X-Amz-SignedHeaders=", url)
|
||||
@test occursin("X-Amz-Signature=", url)
|
||||
end
|
||||
|
||||
@testset "s3_sign_url with custom expiry duration" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
url = s3_sign_url(storage, "test.json", 600)
|
||||
@test occursin("X-Amz-Expires=600", url)
|
||||
end
|
||||
|
||||
@testset "s3_sign_url with GET verb produces different signature than default" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
url_get = s3_sign_url(storage, "test.json", 3600; verb="GET")
|
||||
url_default = s3_sign_url(storage, "test.json", 3600)
|
||||
# GET verb should produce a valid signature
|
||||
@test occursin("X-Amz-Signature=", url_get)
|
||||
@test occursin("X-Amz-Signature=", url_default)
|
||||
# Both URLs should have the same structure but potentially different signatures
|
||||
@test occursin("X-Amz-Algorithm=AWS4-HMAC-SHA256", url_get)
|
||||
end
|
||||
|
||||
@testset "s3_sign_url with PUT verb and content_type" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
url_put = s3_sign_url(storage, "upload.json", 300; verb="PUT", content_type="application/json")
|
||||
url_get = s3_sign_url(storage, "upload.json", 300; verb="GET")
|
||||
# PUT and GET should produce different signatures (different canonical request)
|
||||
@test occursin("X-Amz-Signature=", url_put)
|
||||
@test occursin("X-Amz-Signature=", url_get)
|
||||
end
|
||||
|
||||
@testset "s3_sign_url with special characters in key" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
test_key = "folder/sub folder/file with spaces.json"
|
||||
url = s3_sign_url(storage, test_key, 3600)
|
||||
@test occursin("testbucket/", url)
|
||||
end
|
||||
|
||||
@testset "s3_sign_url with deeply nested key" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
test_key = "a/b/c/d/e/deep-file.json"
|
||||
url = s3_sign_url(storage, test_key, 3600)
|
||||
@test occursin("/testbucket/a/b/c/d/e/deep-file.json", url)
|
||||
end
|
||||
|
||||
@testset "integration: pre-signed URL can download existing file" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
|
||||
test_key = "testrunner-presign-$(randstring(8)).json"
|
||||
test_data = "{\"presign\": true, \"test\": \"$(randstring(12))\"}"
|
||||
put_file(storage, test_key, test_data)
|
||||
|
||||
url = s3_sign_url(storage, test_key, 300)
|
||||
@test occursin("https://s3-api.yiem.cc/testbucket/", url)
|
||||
|
||||
delete_file(storage, test_key)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user