def test_get_token_from_ykey(monkeypatch, tmp_path): monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'expired') from awsmfav2.cli import CLI with mock.patch.object(CLI, '_get_ykey_token', return_value=123456): with mock.patch.object(CLI, '_ykey_is_present', return_value=True): cli = CLI() assert (cli._get_token() == 123456)
def test_ykman_is_installed(monkeypatch, tmp_path): ''' Test check if ykman is installed ''' monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'expired') from awsmfav2.cli import CLI cli = CLI() assert (cli._ykman_is_installed())
def test_ykey_is_present(monkeypatch, tmp_path): ''' Test check if a YubiKey is current connected to the host ''' monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'expired') from awsmfav2.cli import CLI cli = CLI() assert (cli._ykey_is_present())
def test_main_expired_creds(monkeypatch, tmp_path): ''' Test that we can actually call mock STS and get back creds ''' monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'expired') from awsmfav2.cli import CLI cli = CLI() cli.main()
def test_get_token_from_ykey(monkeypatch, tmp_path): monkeypatch.setenv("HOME", str(tmp_path)) init_tmpdir(tmp_path, "expired") from awsmfav2.cli import CLI with mock.patch.object(CLI, "_get_ykey_token", return_value=123456): with mock.patch.object(CLI, "_ykey_is_present", return_value=True): cli = CLI() assert cli._get_token() == 123456
def test_ykman_is_installed(monkeypatch, tmp_path): """ Test check if ykman is installed """ monkeypatch.setenv("HOME", str(tmp_path)) init_tmpdir(tmp_path, "expired") from awsmfav2.cli import CLI cli = CLI() assert cli._ykman_is_installed()
def test_main_expired_creds(monkeypatch, tmp_path): """ Test that we can actually call mock STS and get back creds """ monkeypatch.setenv("HOME", str(tmp_path)) init_tmpdir(tmp_path, "expired") from awsmfav2.cli import CLI cli = CLI() cli.main()
def test_ykey_is_present(monkeypatch, tmp_path): """ Test check if a YubiKey is current connected to the host """ monkeypatch.setenv("HOME", str(tmp_path)) init_tmpdir(tmp_path, "expired") from awsmfav2.cli import CLI cli = CLI() assert cli._ykey_is_present()
def test_get_config_argument(monkeypatch, tmp_path): ''' Test loading a config param from config profile ''' monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'expired') from awsmfav2.cli import CLI cli = CLI() oath_credential = cli._get_argument('yk_oath_credential') assert (oath_credential == 'test_oath_cred')
def test_get_cli_argument(monkeypatch, tmp_path): ''' Test loading a config param from CLI ''' monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'expired') from awsmfav2.cli import CLI cli = CLI() duration = cli._get_argument('duration') assert (duration == 666)
def test_get_config_argument(monkeypatch, tmp_path): """ Test loading a config param from config profile """ monkeypatch.setenv("HOME", str(tmp_path)) init_tmpdir(tmp_path, "expired") from awsmfav2.cli import CLI cli = CLI() oath_credential = cli._get_argument("yk_oath_credential") assert oath_credential == "test_oath_cred"
def test_get_cli_argument(monkeypatch, tmp_path): """ Test loading a config param from CLI """ monkeypatch.setenv("HOME", str(tmp_path)) init_tmpdir(tmp_path, "expired") from awsmfav2.cli import CLI cli = CLI() duration = cli._get_argument("duration") assert duration == 666
def test_ykey_is_not_present_cli_arg(monkeypatch, tmp_path): ''' Test to try logic if a YubiKey is not connected with OATH cred passed from CLI ''' monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'expired') from awsmfav2.cli import CLI with mock.patch.object(CLI, '_ykman_is_installed', return_value=False): cli = CLI() with pytest.raises(RuntimeError): assert (cli._ykey_is_present(ykey_count=0) == False)
def test_recursive_get_config_param(monkeypatch, tmp_path): ''' Test loading a config param present in a parent profile ''' monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'expired') from awsmfav2.cli import CLI cli = CLI() mfa_serial = CLI.recursive_get_config_param(cli.config, 'profile role', 'mfa_serial') assert (mfa_serial == EXPECTED_MFA_DEV_ARN)
def test_main_unexpired_creds(monkeypatch, tmp_path): ''' Test that we can actually call mock STS and get back creds ''' monkeypatch.setenv('HOME', str(tmp_path)) monkeypatch.setenv('AWS_MFA_DURATION', '900') init_tmpdir(tmp_path, 'unexpired') from awsmfav2.cli import CLI cli = CLI() cli.main() assert (cli._get_argument('duration') == '900')
def test_recursive_get_config_param(monkeypatch, tmp_path): """ Test loading a config param present in a parent profile """ monkeypatch.setenv("HOME", str(tmp_path)) init_tmpdir(tmp_path, "expired") from awsmfav2.cli import CLI cli = CLI() mfa_serial = CLI.recursive_get_config_param(cli.config, "profile role", "mfa_serial") assert mfa_serial == EXPECTED_MFA_DEV_ARN
def test_main_unexpired_creds(monkeypatch, tmp_path): """ Test that we can actually call mock STS and get back creds """ monkeypatch.setenv("HOME", str(tmp_path)) monkeypatch.setenv("AWS_MFA_DURATION", "900") init_tmpdir(tmp_path, "unexpired") from awsmfav2.cli import CLI cli = CLI() cli.main() assert cli._get_argument("duration") == "900"
def test_get_mfa_creds_unexpired(monkeypatch, tmp_path): ''' Test that we can actually call mock STS and get back creds ''' monkeypatch.setenv('HOME', str(tmp_path)) init_tmpdir(tmp_path, 'unexpired') from awsmfav2.cli import CLI cli = CLI() updated, creds = cli._get_mfa_creds() assert (updated == False) assert (isinstance(creds['aws_access_key_id'], str)) assert (isinstance(creds['aws_secret_access_key'], str)) assert (isinstance(creds['aws_session_token'], str)) assert (isinstance(creds['expiration'], str))
def test_get_mfa_creds_unexpired(monkeypatch, tmp_path): """ Test that we can actually call mock STS and get back creds """ monkeypatch.setenv("HOME", str(tmp_path)) init_tmpdir(tmp_path, "unexpired") from awsmfav2.cli import CLI cli = CLI() updated, creds = cli._get_mfa_creds() assert updated == False assert isinstance(creds["aws_access_key_id"], str) assert isinstance(creds["aws_secret_access_key"], str) assert isinstance(creds["aws_session_token"], str) assert isinstance(creds["expiration"], str)