Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 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"
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 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
Exemplo n.º 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"
Exemplo n.º 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))
Exemplo n.º 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)