def test_krb_auth_use_keytab(mock_popen):
    krb_princ = "*****@*****.**"
    service = "https://pyxis.engineering.redhat.com/"
    ktfile = "/root/file.keytab"

    krb_auth = pyxis_authentication.PyxisKrbAuth(krb_princ, service, ktfile,
                                                 "/tmp/tempfile")
    mock_wait = mock.MagicMock()
    mock_wait.side_effect = [0, 0, 0]
    mock_popen.return_value.wait = mock_wait

    krb_auth._krb_auth()
    assert mock_popen.call_count == 2
    assert mock_popen.call_args_list == [
        mock.call(["klist", "-s"], stdout=-1, stderr=-1),
        mock.call(
            [
                "kinit",
                "*****@*****.**",
                "-k",
                "-t",
                "/root/file.keytab",
                "-c",
                "/tmp/tempfile",
            ],
            stdout=-1,
            stderr=-1,
        ),
    ]
    assert os.environ["KRB5CCNAME"] == "/tmp/tempfile"
def test_krb_auth_init():
    krb_princ = "*****@*****.**"
    service = "https://pyxis.engineering.redhat.com/"
    ktfile = "/root/file.keytab"

    krb_auth = pyxis_authentication.PyxisKrbAuth(krb_princ, service, ktfile)
    assert krb_auth.krb_princ == krb_princ
    assert krb_auth.service == service
    assert krb_auth.ktfile == ktfile
示例#3
0
def test_krb_auth_init(hostname):
    krb_princ = "*****@*****.**"
    service = hostname
    ktfile = "/root/file.keytab"

    krb_auth = pyxis_authentication.PyxisKrbAuth(krb_princ, service, ktfile)
    assert krb_auth.krb_princ == krb_princ
    assert krb_auth.service == service
    assert krb_auth.ktfile == ktfile
示例#4
0
def test_krb_apply_to_session(mock_krb_auth, hostname):
    krb_princ = "*****@*****.**"
    service = hostname
    ktfile = "/root/file.keytab"

    krb_auth = pyxis_authentication.PyxisKrbAuth(krb_princ, service, ktfile)
    my_pyxis_session = pyxis_session.PyxisSession(hostname)
    krb_auth.apply_to_session(my_pyxis_session)
    assert isinstance(my_pyxis_session.session.auth, mock.MagicMock)
def test_krb_apply_to_session(mock_krb_auth):
    krb_princ = "*****@*****.**"
    service = "https://pyxis.engineering.redhat.com/"
    ktfile = "/root/file.keytab"

    krb_auth = pyxis_authentication.PyxisKrbAuth(krb_princ, service, ktfile)
    my_pyxis_session = pyxis_session.PyxisSession(
        "https://pyxis.engineering.redhat.com/")
    krb_auth.apply_to_session(my_pyxis_session)
    assert isinstance(my_pyxis_session.session.auth, mock.MagicMock)
def test_krb_auth_skip_init(mock_popen):
    krb_princ = "*****@*****.**"
    service = "https://pyxis.engineering.redhat.com/"

    krb_auth = pyxis_authentication.PyxisKrbAuth(krb_princ, service)
    mock_wait = mock.MagicMock()
    mock_wait.return_value = 0
    mock_popen.return_value.wait = mock_wait

    krb_auth._krb_auth()
    assert mock_popen.call_count == 1
    assert mock_popen.call_args_list == [
        mock.call(["klist", "-s"], stdout=-1, stderr=-1)
    ]
    assert "KRB5CCNAME" not in os.environ
示例#7
0
def test_krb_auth_use_default_keytab(mock_popen, hostname):
    krb_princ = "*****@*****.**"
    service = hostname

    krb_auth = pyxis_authentication.PyxisKrbAuth(krb_princ,
                                                 service,
                                                 ccache_file="/tmp/tempfile")
    mock_wait = mock.MagicMock()
    mock_wait.side_effect = [1, 0, 0]
    mock_popen.return_value.wait = mock_wait

    krb_auth._krb_auth()
    assert mock_popen.call_count == 2
    assert mock_popen.call_args_list == [
        mock.call(["klist", "-s"], stdout=-1, stderr=-1),
        mock.call(
            ["kinit", "*****@*****.**", "-k", "-c", "/tmp/tempfile"],
            stdout=-1,
            stderr=-1,
        ),
    ]
    assert os.environ["KRB5CCNAME"] == "/tmp/tempfile"