From a8bc393464f9d0c2b5bd0c40c3e0244a87f21cd7 Mon Sep 17 00:00:00 2001 From: "David D. Riddle" Date: Fri, 4 Oct 2024 16:33:31 -0500 Subject: [PATCH] Add integration tests --- .../tests/login_configure.bats | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/integration_tests/tests/login_configure.bats b/src/integration_tests/tests/login_configure.bats index f53ba964..45abc235 100644 --- a/src/integration_tests/tests/login_configure.bats +++ b/src/integration_tests/tests/login_configure.bats @@ -16,7 +16,12 @@ load 'base' assert_output "$ERROR_MESG" } -@test "Configure default profile" { +@test "Configure nonexistent default profile" { + configure_default_profile + test_default_profile +} + +configure_default_profile() { run aws login configure <<- EOF # NOTA BENE: <<- strips tabs https://shibboleth.illinois.edu/idp/profile/SAML2/SOAP/ECP$CR netid$CR @@ -25,7 +30,9 @@ load 'base' EOF assert_output "ECP Endpoint URL [None]: Username [None]: Enable Keyring [False]: Duo Factor [None]: Role ARN [None]: " +} +test_default_profile() { assert_exists "$AWSCLI_LOGIN_ROOT/.aws-login/config" ! read -r -d '' CONFIG_FILE <<- EOF # NOTA BENE: <<- strips tabs [default]$CR @@ -35,3 +42,51 @@ load 'base' EOF assert_equal "$(<$AWSCLI_LOGIN_ROOT/.aws-login/config)" "$CONFIG_FILE" } + +# Regression test for issue #212 +@test "Configure empty default profile" { + cat <<- EOF > $AWS_SHARED_CREDENTIALS_FILE + [default] + aws_access_key_id = + aws_secret_access_key = + aws_session_token = + aws_security_token = + EOF + + configure_default_profile + test_default_profile +} + +create_nonempty_default_profile() { + cat <<- EOF > $AWS_SHARED_CREDENTIALS_FILE + [default] + aws_access_key_id = foo + aws_secret_access_key = bar + EOF +} + +@test "Configure nonempty default profile" { + create_nonempty_default_profile + + run aws login configure <<- EOF # NOTA BENE: <<- strips tabs + YES + https://shibboleth.illinois.edu/idp/profile/SAML2/SOAP/ECP$CR + netid$CR + $CR + push$CR + + EOF + assert_output "WARNING: Profile 'default' contains credentials. +Overwrite profile 'default' to enable login? ECP Endpoint URL [None]: Username [None]: Enable Keyring [False]: Duo Factor [None]: Role ARN [None]: " + test_default_profile +} + +@test "Do not configure nonempty default profile" { + create_nonempty_default_profile + run aws login configure <<- EOF # NOTA BENE: <<- strips tabs + No + EOF + assert_output "WARNING: Profile 'default' contains credentials. +Overwrite profile 'default' to enable login? " + assert_not_exists "$AWSCLI_LOGIN_ROOT/.aws-login/config" +}