示例#1
0
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)
示例#2
0
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())
示例#3
0
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())
示例#4
0
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()
示例#5
0
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
示例#6
0
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()
示例#7
0
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()
示例#8
0
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()
示例#9
0
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')
示例#10
0
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)
示例#11
0
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"
示例#12
0
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
示例#13
0
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)
示例#14
0
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)
示例#15
0
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')
示例#16
0
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
示例#17
0
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"
示例#18
0
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))
示例#19
0
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)