Repository navigation
Fix | SSO token expiry compared in UTC, MFA recognizes STS errors + auth.py tests with Stubber - #354
Conversation
- check_sso_token compared the token's UTC expiresAt with the local time: in UTC-3 an expired token was taken as valid for 3 more hours, and in UTC+ zones valid tokens were rejected. - refresh_layer_credentials_mfa expected AccessDeniedException and ExpiredToken, but STS returns AccessDenied and ExpiredTokenException. A user without permission was asked for the MFA code 3 times without any message. Now AccessDenied exits with 40 and any other error exits with 50 at once, instead of asking for another code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…3 clients Rewrites tests/test_modules/test_auth.py: a real PathsHandler over a project in tmp_path, real config/credentials/token files, an isolated HOME, and real sso/sts clients under botocore Stubber. Adds the first MFA tests and a timezone case for check_sso_token. Drops the tests that duplicated aws.py functions, already covered end to end in test_aws.py. auth.py coverage goes from 60% to 93%. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. WalkthroughThe change updates SSO token expiration checks to use UTC and adjusts MFA role-assumption error handling. The auth tests now use isolated project files and Stubber-backed AWS clients to cover SSO and MFA credential flows. ChangesAuthentication flows
Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
Coverage Report for CI Build 43647474237Coverage increased (+4.1%) to 77.112%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions6 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
What?
Two bugs in
auth.py, which refreshes the SSO/MFA credentials before everytofu/terraformcommand, plus a rewrite of its tests.AccessDenied)40after one code: "User does not have permission to assume role ..."ExpiredTokenExceptionon the source profile)50at once with the errorWrong codes (
invalid MFA one time pass code) and a wrong code length still re-prompt, as before.Two commits:
check_sso_tokencomparesexpiresAt(UTC) with the current UTC time instead of the local time.ExpiredTokenretry branch could never match and is gone.tests/test_modules/test_auth.pyis rewritten.PathsHandlerover a project intmp_path, with real config, credentials, token and cache files and an isolatedHOME.sso/stsclients run underbotocore.stub.Stubber. No more mocks ofopen,Path.read_textorupdate_config_section.refresh_all_accountsaws.pyfunctions (get_account_roles,add_sso_profile,configure_sso_profiles,aws sso refresh).test_aws.pyalready covers them end to end.Why?
H6 in #346:
auth.pyruns before every command, and its tests mocked the file system so heavily that both bugs went unnoticed.Results
auth.pycoverage: 60% → 93%. Total: 73% → 77%.aws.pystays at 97%.Not touched here: with python-hcl2 7.x,
profile = var.profileparses as"${var.profile}", so the"var.profile"branch inget_layer_profileis dead code. That belongs to #326.Relates to #346
🤖 Generated with Claude Code
Summary by CodeRabbit