|
511 | 511 | end
|
512 | 512 | end
|
513 | 513 |
|
| 514 | + @testset "~/.aws/config - Credential Process" begin |
| 515 | + mktempdir() do dir |
| 516 | + config_file = joinpath(dir, "config") |
| 517 | + credential_process_file = joinpath(dir, "cred_process") |
| 518 | + open(credential_process_file, "w") do io |
| 519 | + println(io, "#!/bin/sh") |
| 520 | + println(io, "cat <<EOF") |
| 521 | + json = Dict( |
| 522 | + "Version" => 1, |
| 523 | + "AccessKeyId" => test_values["Test-AccessKeyId"], |
| 524 | + "SecretAccessKey" => test_values["Test-SecretAccessKey"], |
| 525 | + ) |
| 526 | + JSON.print(io, json) |
| 527 | + println(io, "\nEOF") |
| 528 | + end |
| 529 | + chmod(credential_process_file, 0o700) |
| 530 | + |
| 531 | + withenv("AWS_CONFIG_FILE" => config_file) do |
| 532 | + @testset "support" begin |
| 533 | + open(config_file, "w") do io |
| 534 | + write( |
| 535 | + io, |
| 536 | + """ |
| 537 | + [profile $(test_values["Test-Config-Profile"])] |
| 538 | + credential_process = $(abspath(credential_process_file)) |
| 539 | + """, |
| 540 | + ) |
| 541 | + end |
| 542 | + |
| 543 | + result = dot_aws_config(test_values["Test-Config-Profile"]) |
| 544 | + |
| 545 | + @test result.access_key_id == test_values["Test-AccessKeyId"] |
| 546 | + @test result.secret_key == test_values["Test-SecretAccessKey"] |
| 547 | + @test isempty(result.token) |
| 548 | + @test result.expiry == typemax(DateTime) |
| 549 | + end |
| 550 | + |
| 551 | + # The AWS CLI uses the config file `credential_process` setting over |
| 552 | + # specifying the config file `aws_access_key_id`/`aws_secret_access_key`. |
| 553 | + @testset "precedence" begin |
| 554 | + open(config_file, "w") do io |
| 555 | + write( |
| 556 | + io, |
| 557 | + """ |
| 558 | + [profile $(test_values["Test-Config-Profile"])] |
| 559 | + aws_access_key_id = invalid |
| 560 | + aws_secret_access_key = invalid |
| 561 | + credential_process = $(abspath(credential_process_file)) |
| 562 | + """, |
| 563 | + ) |
| 564 | + end |
| 565 | + |
| 566 | + result = dot_aws_config(test_values["Test-Config-Profile"]) |
| 567 | + |
| 568 | + @test result.access_key_id == test_values["Test-AccessKeyId"] |
| 569 | + @test result.secret_key == test_values["Test-SecretAccessKey"] |
| 570 | + @test isempty(result.token) |
| 571 | + @test result.expiry == typemax(DateTime) |
| 572 | + end |
| 573 | + end |
| 574 | + end |
| 575 | + end |
| 576 | + |
514 | 577 | @testset "~/.aws/creds - Default Profile" begin
|
515 | 578 | mktemp() do creds_file, creds_io
|
516 | 579 | write(
|
|
696 | 759 | end
|
697 | 760 | end
|
698 | 761 |
|
| 762 | + @testset "Credential Process" begin |
| 763 | + gen_process(json) = Cmd(["echo", JSON.json(json)]) |
| 764 | + |
| 765 | + long_term_resp = Dict( |
| 766 | + "Version" => 1, |
| 767 | + "AccessKeyId" => "access-key", |
| 768 | + "SecretAccessKey" => "secret-key", |
| 769 | + # format trick: using this comment to force use of multiple lines |
| 770 | + ) |
| 771 | + creds = external_process_credentials(gen_process(long_term_resp)) |
| 772 | + @test creds.access_key_id == long_term_resp["AccessKeyId"] |
| 773 | + @test creds.secret_key == long_term_resp["SecretAccessKey"] |
| 774 | + @test isempty(creds.token) |
| 775 | + @test creds.expiry == typemax(DateTime) |
| 776 | + |
| 777 | + expiration = floor(now(UTC), Second) |
| 778 | + temporary_resp = Dict( |
| 779 | + "Version" => 1, |
| 780 | + "AccessKeyId" => "access-key", |
| 781 | + "SecretAccessKey" => "secret-key", |
| 782 | + "SessionToken" => "session-token", |
| 783 | + "Expiration" => Dates.format(expiration, dateformat"yyyy-mm-dd\THH:MM:SS\Z"), |
| 784 | + ) |
| 785 | + creds = external_process_credentials(gen_process(temporary_resp)) |
| 786 | + @test creds.access_key_id == temporary_resp["AccessKeyId"] |
| 787 | + @test creds.secret_key == temporary_resp["SecretAccessKey"] |
| 788 | + @test creds.token == temporary_resp["SessionToken"] |
| 789 | + @test creds.expiry == expiration |
| 790 | + |
| 791 | + unhandled_version_resp = Dict("Version" => 2) |
| 792 | + json = sprint(JSON.print, unhandled_version_resp, 2) |
| 793 | + ex = ErrorException("Credential process returned unhandled version 2:\n$json") |
| 794 | + @test_throws ex external_process_credentials(gen_process(unhandled_version_resp)) |
| 795 | + |
| 796 | + missing_token_resp = Dict( |
| 797 | + "Version" => 1, |
| 798 | + "AccessKeyId" => "access-key", |
| 799 | + "SecretAccessKey" => "secret-key", |
| 800 | + "Expiration" => Dates.format(expiration, dateformat"yyyy-mm-dd\THH:MM:SS\Z"), |
| 801 | + ) |
| 802 | + ex = KeyError("SessionToken") |
| 803 | + @test_throws ex external_process_credentials(gen_process(missing_token_resp)) |
| 804 | + |
| 805 | + missing_expiration_resp = Dict( |
| 806 | + "Version" => 1, |
| 807 | + "AccessKeyId" => "access-key", |
| 808 | + "SecretAccessKey" => "secret-key", |
| 809 | + "SessionToken" => "session-token", |
| 810 | + ) |
| 811 | + ex = KeyError("Expiration") |
| 812 | + @test_throws ex external_process_credentials(gen_process(missing_expiration_resp)) |
| 813 | + end |
| 814 | + |
699 | 815 | @testset "Credentials Not Found" begin
|
700 | 816 | patches = [
|
701 | 817 | @patch HTTP.request(method::String, url; kwargs...) = nothing
|
|
0 commit comments