Skip to content
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b5d677d
Separate unit from integration tests
omus Jul 2, 2025
fcea2e5
fixup! Separate unit from integration tests
omus Jul 2, 2025
cbd1b31
fixup! Separate unit from integration tests
omus Jul 2, 2025
6b3ecec
Iterating
omus Jul 2, 2025
d4d8374
Update _aws_profile_config
omus Jul 2, 2025
622f513
fixup
omus Jul 2, 2025
9ecfe5a
Improve AWS config support for `source_profile`
omus Jul 2, 2025
a30b1b6
fixup
omus Jul 2, 2025
b21f568
Make tests specificially unit tests
omus Jul 2, 2025
06f947c
fixup
omus Jul 2, 2025
b8c5231
fixup
omus Jul 2, 2025
8f2bc48
Merge branch 'cv/aws-profile-config' into cv/test-reorg
omus Jul 2, 2025
ebea432
fixup! Merge branch 'cv/aws-profile-config' into cv/test-reorg
omus Jul 2, 2025
1330090
Make resursive profile merging optional
omus Jul 2, 2025
272b7b6
More unit tests
omus Jul 2, 2025
287e82b
Refactor integration tests
omus Jul 2, 2025
dbe72d8
Move integration tests
omus Jul 2, 2025
07824e1
Wrapping up
omus Jul 2, 2025
1ad838e
fixup
omus Jul 2, 2025
88bae50
fixup
omus Jul 2, 2025
04a4495
Rename other test dirs
omus Jul 2, 2025
fc95c3c
Add forgotten file
omus Jul 2, 2025
6c02713
fixup
omus Jul 2, 2025
695ecd4
fixup! fixup
omus Jul 2, 2025
fb1579f
Drop AWS_CONFIG ref
omus Jul 2, 2025
a1b772e
Revert AWS integration tests
omus Jul 2, 2025
b2a6268
Make resursive profile merging optional
omus Jul 2, 2025
35cdc37
Merge branch 'cv/aws-profile-config' into cv/test-reorg
omus Jul 2, 2025
464909b
Inheriting is not supported
omus Jul 2, 2025
ddd1c6a
Merge branch 'cv/aws-profile-config' into cv/test-reorg
omus Jul 2, 2025
41f678c
Comment on requirements for tests
omus Jul 3, 2025
4bc22ac
Make integration tests opt-in
omus Jul 3, 2025
c2722c8
Merge branch 'master' into cv/test-reorg
omus Jul 3, 2025
e93f07a
Reset default AWS configuration in integration tests
omus Jul 3, 2025
329fb2d
fixup! Reset default AWS configuration in integration tests
omus Jul 3, 2025
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
1,184 changes: 0 additions & 1,184 deletions test/AWS.jl

This file was deleted.

1,366 changes: 0 additions & 1,366 deletions test/AWSCredentials.jl

This file was deleted.

File renamed without changes.
File renamed without changes.
541 changes: 541 additions & 0 deletions test/integration/AWS.jl

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions test/integration/AWSCredentials.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@testset "Load Credentials" begin
config = global_aws_config()
user = aws_user_arn(config)
@test occursin(r"^arn:aws:(iam|sts)::[0-9]+:[^:]+$", user)
config.region = "us-east-1"

@test_ecode("InvalidAction", AWSServices.iam("GetFoo"))

@test_ecode(
["AccessDenied", "NoSuchEntity"],
AWSServices.iam("GetUser", Dict("UserName" => "notauser"))
)

@test_ecode("ValidationError", AWSServices.iam("GetUser", Dict("UserName" => "@#!%%!")))

# Please note: If testing in a managed Corporate AWS environment, this can set off alarms...
@test_ecode(
["AccessDenied", "EntityAlreadyExists"],
AWSServices.iam("CreateUser", Dict("UserName" => "root"))
)
end
76 changes: 0 additions & 76 deletions test/issues.jl → test/integration/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,82 +151,6 @@ try
S3.delete_object(BUCKET_NAME, file_name)
end
end

# https://github.com/JuliaCloud/AWS.jl/issues/515
@testset "issue 515" begin
function _incomplete_patch(; data, num_attempts_to_fail=4)
attempt_num = 0
n = length(data)

function _downloads_response(content_length)
headers = ["content-length" => string(content_length)]
return Downloads.Response("http", "", 200, "HTTP/1.1 200 OK", headers)
end

patch = if AWS.DEFAULT_BACKEND[] isa AWS.HTTPBackend
@patch function HTTP.request(args...; response_stream, kwargs...)
attempt_num += 1
if attempt_num <= num_attempts_to_fail
write(response_stream, data[1:(n - 1)]) # an incomplete stream that shouldn't be retained
throw(HTTP.RequestError(HTTP.Request(), EOFError()))
else
write(response_stream, data)
return HTTP.Response(200, "{\"Location\": \"us-east-1\"}")
end
end
elseif AWS.DEFAULT_BACKEND[] isa AWS.DownloadsBackend
@patch function Downloads.request(args...; output, kwargs...)
attempt_num += 1
if attempt_num <= num_attempts_to_fail
write(output, data[1:(n - 1)]) # an incomplete stream that shouldn't be retained
message = "transfer closed with 1 bytes remaining to read"
e = Downloads.RequestError("", 18, message, _downloads_response(n))
throw(e)
else
write(output, data)
return _downloads_response(n)
end
end
end

return patch
end

n = 100
data = rand(UInt8, n)
bucket = "julialang2" # use public bucket as dummy
key = "bin/versions.json"
config = AWSConfig(; creds=nothing)

@testset "Fail 2 attempts then succeed" begin
apply(_incomplete_patch(; data=data, num_attempts_to_fail=2)) do
retrieved = S3.get_object(bucket, key; aws_config=config)

@test length(retrieved) == n
@test retrieved == data
end
end

@testset "Fail all 4 attempts then throw" begin
err_t = if AWS.DEFAULT_BACKEND[] isa AWS.HTTPBackend
HTTP.RequestError
else
Downloads.RequestError
end
io = IOBuffer()

apply(_incomplete_patch(; data=data, num_attempts_to_fail=4)) do
params = Dict("response_stream" => io)
@test_throws err_t S3.get_object(bucket, key, params; aws_config=config)

seekstart(io)
retrieved = read(io)
@test length(retrieved) == n - 1
@test retrieved == data[1:(n - 1)]
end
end
end

finally
S3.delete_bucket(BUCKET_NAME)
end
File renamed without changes.
2 changes: 1 addition & 1 deletion test/role.jl → test/integration/role.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ end
@testset "assume_role / assume_role_creds" begin
# In order to mitigate the effects of using `assume_role` in order to test itself we'll
# use the lowest-level call with as many defaults as possible.
base_config = AWS_CONFIG[]
base_config = global_aws_config()
creds = assume_role_creds(base_config, testset_role("AssumeRoleTestset"))
config = AWSConfig(; creds)
@test get_assumed_role(config) == testset_role("AssumeRoleTestset")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
57 changes: 31 additions & 26 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ using StableRNGs
Mocking.activate()

include("patch.jl")
include("resources/totp.jl")

const TEST_MINIO = begin
all(k -> haskey(ENV, k), ("MINIO_ACCESS_KEY", "MINIO_SECRET_KEY", "MINIO_REGION_NAME"))
end
include("resource/totp.jl")

function _now_formatted()
return lowercase(Dates.format(now(Dates.UTC), dateformat"yyyymmdd\THHMMSSsss\Z"))
Expand All @@ -52,48 +48,57 @@ end
testset_role(role_name) = "AWS.jl-$role_name"

const RUN_UNIT_TESTS = get(ENV, "RUN_UNIT_TESTS", "true") == "true"
const RUN_INTEGRATION_TESTS = get(ENV, "RUN_INTEGRATION_TESTS", "true") == "true"
const RUN_INTEGRATION_TESTS = get(ENV, "RUN_INTEGRATION_TESTS", "false") == "true"
const RUN_MINIO_INTEGRATION_TESTS = begin
all(k -> haskey(ENV, k), ("MINIO_ACCESS_KEY", "MINIO_SECRET_KEY", "MINIO_REGION_NAME"))
end

# Avoid the situation where we all tests are silently skipped. Most likely due to the wrong
# environmental variables being used.
if !RUN_UNIT_TESTS && !RUN_INTEGRATION_TESTS
error("All tests have been disabled")
end

const AWS_CONFIG = Ref{AbstractAWSConfig}()

@testset "AWS.jl" begin
# Unit tests do not requires access to an AWS account
@testset "Unit Tests" begin
if RUN_UNIT_TESTS
include("unit/AWS.jl")
include("unit/AWSCredentials.jl")
# Force unit tests to run without a valid AWS configuration being present
withenv(
[k => nothing for k in filter(startswith("AWS_"), keys(ENV))]...,
"AWS_CONFIG_FILE" => "/dev/null",
"AWS_SHARED_CREDENTIALS_FILE" => "/dev/null",
) do
include("unit/AWS.jl")
include("unit/AWSExceptions.jl")
include("unit/AWSMetadataUtilities.jl")
include("unit/test_pkg.jl")
include("unit/utilities.jl")
include("unit/AWSConfig.jl")
include("unit/IMDS.jl")
include("unit/AWSCredentials.jl")
include("unit/issues.jl")
end
else
@warn "Skipping unit tests"
end
end

# TODO: Some of these tests are actually unit tests and need to be refactored
# Integration tests require access to an AWS account
@testset "Integration Tests" begin
if RUN_INTEGRATION_TESTS
AWS_CONFIG[] = AWSConfig()

include("AWSExceptions.jl")
include("AWSMetadataUtilities.jl")
include("test_pkg.jl")
include("utilities.jl")
include("AWSConfig.jl")

backends = [AWS.HTTPBackend, AWS.DownloadsBackend]
@testset "Backend: $(nameof(backend))" for backend in backends
AWS.DEFAULT_BACKEND[] = backend()
include("AWS.jl")
include("IMDS.jl")
include("AWSCredentials.jl")
include("role.jl")
include("issues.jl")
include("integration/AWS.jl")
include("integration/AWSCredentials.jl")
include("integration/role.jl")
include("integration/issues.jl")

if TEST_MINIO
include("minio.jl")
if RUN_MINIO_INTEGRATION_TESTS
include("integration/minio.jl")
else
@warn "Skipping MinIO integration tests"
end
end
else
Expand Down
Loading