Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion leverage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

MINIMUM_VERSIONS = {
"TERRAFORM": "1.3.5",
"TOOLBOX": "0.2.0",
"TOOLBOX": "0.2.4",
}

import sys
Expand Down
4 changes: 2 additions & 2 deletions leverage/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class SSOContainer(LeverageContainer):
AWS_SSO_LOGOUT_SCRIPT = "/home/leverage/scripts/aws-sso/aws-sso-logout.sh"

# SSO constants
AWS_SSO_LOGIN_URL = "https://device.sso.{region}.amazonaws.com/?user_code={user_code}"
AWS_SSO_LOGIN_URL = "{sso_url}/#/device?user_code={user_code}"
AWS_SSO_CODE_WAIT_SECONDS = 2
AWS_SSO_CODE_ATTEMPTS = 10
FALLBACK_LINK_MSG = "Opening the browser... if it fails, open this link in your browser:\n{link}"
Expand Down Expand Up @@ -365,7 +365,7 @@ def sso_login(self) -> int:
# now let's grab the user code from the logs
user_code = self.get_sso_code(container)
# with the user code, we can now autocomplete the url
link = self.AWS_SSO_LOGIN_URL.format(region=region.strip(), user_code=user_code)
link = self.AWS_SSO_LOGIN_URL.format(sso_url=self.paths.common_conf["sso_start_url"], user_code=user_code)
webbrowser.open_new_tab(link)
# The SSO code is only valid once: if the browser was able to open it, the fallback link will be invalid
logger.info(self.FALLBACK_LINK_MSG.format(link=link))
Expand Down
16 changes: 8 additions & 8 deletions tests/bats/leverage.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ teardown(){

run leverage run -l

assert_line --index 0 "Tasks in build file \`build.py\`:"
assert_line --index 1 --regexp "^ hello\s+Say hello.$"
assert_line --index 2 --regexp "^Powered by Leverage [0-9]+.[0-9]+.[0-9]+$"
assert_line --partial "Tasks in build file \`build.py\`:"
assert_line --regexp "hello\s+Say hello."
assert_line --regexp "Powered by Leverage [0-9]+.[0-9]+.[0-9]+"
}

@test "Lists tasks with build script in parent directory" {
Expand All @@ -51,9 +51,9 @@ teardown(){

run leverage run -l

assert_line --index 0 "Tasks in build file \`build.py\`:"
assert_line --index 1 --regexp "^ hello\s+Say hello.$"
assert_line --index 2 --regexp "^Powered by Leverage [0-9]+.[0-9]+.[0-9]+$"
assert_line --partial "Tasks in build file \`build.py\`:"
assert_line --regexp "hello\s+Say hello."
assert_line --regexp "Powered by Leverage [0-9]+.[0-9]+.[0-9]+"
}

@test "Simple task runs correctly" {
Expand All @@ -66,8 +66,8 @@ teardown(){
run leverage run hello

assert_output --partial "Hello"
assert_line --index 0 --regexp "\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\] \[ build\.py - ➜ Starting task hello \]"
assert_line --index 2 --regexp "\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\] \[ build\.py - ✔ Completed task hello \]"
assert_line --regexp "\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\] \[ build\.py - ➜ Starting task hello \]"
assert_line --regexp "\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\] \[ build\.py - ✔ Completed task hello \]"
}

@test "Values are loaded from .env file in current directory" {
Expand Down
8 changes: 5 additions & 3 deletions tests/test_containers/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ def test_sso_login(mocked_new_tab, aws_container, fake_os_user, propagate_logs,
"""
Test that we call the correct script and open the correct url.
"""
test_link = "https://device.sso.us-east-1.amazonaws.com/?user_code=TEST-CODE"
aws_container.sso_login()
sso_start_url = "https://test.sso.us-east-1.amazonaws.com"
test_link = "https://test.sso.us-east-1.amazonaws.com/#/device?user_code=TEST-CODE"
with patch.dict(aws_container.paths.common_conf, {"sso_start_url": sso_start_url}):
aws_container.sso_login()

container_args = aws_container.client.api.create_container.call_args_list[0][1]
# make sure we: point to the correct script
assert container_args["command"] == "/home/leverage/scripts/aws-sso/aws-sso-login.sh"
# the browser tab points to the correct code and the correct region
assert mocked_new_tab.call_args[0][0] == "https://device.sso.us-east-1.amazonaws.com/?user_code=TEST-CODE"
assert mocked_new_tab.call_args[0][0] == test_link
# and the fallback method is printed
assert caplog.messages[0] == aws_container.FALLBACK_LINK_MSG.format(link=test_link)
Loading