Exemplo n.º 1
0
def test_AuthselectScannerLibrary_step_detect_if_confirmation_is_required__badlink(
        mock_getmtime, mock_isfile, mock_islink, mock_readlink):
    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(''), '')
    mock_isfile.return_value = True
    mock_islink.return_value = True
    mock_readlink.return_value = ''
    assert obj.step_detect_if_confirmation_is_required()
Exemplo n.º 2
0
def test_AuthselectScannerLibrary_process__features(mock_confirm,
                                                    mock_service):
    pam = get_config('''
    auth required pam_faillock.so preauth silent deny=4 unlock_time=1200
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    ''')

    nsswitch = get_config('''
    passwd:     files sss systemd
    group:      files sss systemd
    sudoers:    files sss
    ''')

    obj = AuthselectScannerLibrary(
        ['pam_unix', 'pam_sss', 'pam_deny', 'pam_faillock'], Authconfig(''),
        DConf(''), PAM(pam), nsswitch)
    mock_confirm.return_value = True
    mock_service.return_value = False
    authselect = obj.process()
    assert authselect.profile == 'sssd'
    assert len(authselect.features) == 2
    assert 'with-faillock' in authselect.features
    assert 'with-sudo' in authselect.features
    assert authselect.confirm
Exemplo n.º 3
0
def test_AuthselectScannerLibrary_step_detect_winbind_features__krb5():
    ac = get_config('''
    WINBINDKRB5=yes
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(ac), DConf(''), PAM(''), '')
    features = obj.step_detect_winbind_features('winbind')
    assert features == ['with-krb5']
Exemplo n.º 4
0
def test_Authconfig_get_string__ok():
    obj = Authconfig(get_config('''
    test_a="str"
    test_b=str
    '''))

    assert obj.get_string('test_a') == 'str'
    assert obj.get_string('test_b') == 'str'
Exemplo n.º 5
0
def test_AuthselectScannerLibrary_step_detect_winbind_features__wrong_profile(
):
    ac = get_config('''
    WINBINDKRB5=yes
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(ac), DConf(''), PAM(''), '')
    features = obj.step_detect_winbind_features('sssd')
    assert not features
Exemplo n.º 6
0
def test_AuthselectScannerLibrary_step_detect_profile__nis(mock_service):
    pam = get_config('''
    auth sufficient pam_unix.so
    auth required pam_deny.so
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(pam), '')
    mock_service.return_value = True
    assert obj.step_detect_profile() == 'nis'
Exemplo n.º 7
0
def test_AuthselectScannerLibrary_step_detect_features__mkhomedir_oddjob():
    pam = get_config('''
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    session optional pam_oddjob_mkhomedir.so umask=0077
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(pam), '')
    assert obj.step_detect_features() == ['with-mkhomedir']
Exemplo n.º 8
0
def test_AuthselectScannerLibrary_step_detect_features__access():
    pam = get_config('''
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    account required pam_access.so
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(pam), '')
    assert obj.step_detect_features() == ['with-pamaccess']
Exemplo n.º 9
0
def test_AuthselectScannerLibrary_step_detect_features__fingerprint():
    pam = get_config('''
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth sufficient pam_fprintd.so
    auth required pam_deny.so
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(pam), '')
    assert obj.step_detect_features() == ['with-fingerprint']
Exemplo n.º 10
0
def test_AuthselectScannerLibrary_step_detect_features__faillock():
    pam = get_config('''
    auth required pam_faillock.so preauth silent deny=4 unlock_time=1200
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(pam), '')
    assert obj.step_detect_features() == ['with-faillock']
Exemplo n.º 11
0
def test_AuthselectScannerLibrary_step_detect_sssd_features__sudo():
    nsswitch = get_config('''
    passwd:     files sss systemd
    group:      files sss systemd
    sudoers:    files sss
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(''),
                                   nsswitch)
    features = obj.step_detect_sssd_features('sssd')
    assert features == ['with-sudo']
Exemplo n.º 12
0
    def process(self):
        # Load configuration
        ac = Authconfig(read_file('/etc/sysconfig/authconfig'))
        dconf = DConf(read_file('/etc/dconf/db/distro.d/10-authconfig'))
        pam = PAM.from_system_configuration()
        nsswitch = read_file("/etc/nsswitch.conf")

        scanner = AuthselectScannerLibrary(self.known_modules, ac, dconf, pam,
                                           nsswitch)

        self.produce(scanner.process())
Exemplo n.º 13
0
def test_AuthselectScannerLibrary_step_detect_sssd_features__wrong_profile():
    nsswitch = get_config('''
    passwd:     files sss systemd
    group:      files sss systemd
    sudoers:    files sss
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(''),
                                   nsswitch)
    features = obj.step_detect_sssd_features('winbind')
    assert not features
Exemplo n.º 14
0
def test_AuthselectScannerLibrary_step_detect_profile__sssd_winbind(
        mock_service):
    pam = get_config('''
    auth sufficient pam_unix.so
    auth sufficient pam_winbind.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(pam), '')
    mock_service.return_value = False
    assert obj.step_detect_profile() is None
Exemplo n.º 15
0
def test_Authconfig_get_bool__false():
    obj = Authconfig(
        get_config('''
    test_a=False
    test_b=false
    test_c=No
    test_d=no
    '''))

    assert not obj.get_bool('test_a')
    assert not obj.get_bool('test_b')
    assert not obj.get_bool('test_c')
    assert not obj.get_bool('test_d')
Exemplo n.º 16
0
def test_Authconfig_get_bool__true():
    obj = Authconfig(
        get_config('''
    test_a=True
    test_b=true
    test_c=Yes
    test_d=yes
    '''))

    assert obj.get_bool('test_a')
    assert obj.get_bool('test_b')
    assert obj.get_bool('test_c')
    assert obj.get_bool('test_d')
Exemplo n.º 17
0
def test_AuthselectScannerLibrary_step_detect_sssd_features__smartcard():
    pam = get_config('''
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    ''')

    ac = get_config('''
    USESMARTCARD=yes
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(ac), DConf(''), PAM(pam), '')
    features = obj.step_detect_sssd_features('sssd')
    assert features == ['with-smartcard']
Exemplo n.º 18
0
def test_AuthselectScannerLibrary_process__simple(mock_confirm, mock_service):
    pam = get_config('''
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    ''')

    obj = AuthselectScannerLibrary(['pam_unix', 'pam_sss', 'pam_deny'],
                                   Authconfig(''), DConf(''), PAM(pam), '')
    mock_confirm.return_value = True
    mock_service.return_value = False
    authselect = obj.process()
    assert authselect.profile == 'sssd'
    assert not authselect.features
    assert authselect.confirm
Exemplo n.º 19
0
def test_AuthselectScannerLibrary_step_detect_if_confirmation_is_required__pass(
        mock_getmtime, mock_isfile, mock_islink, mock_readlink):
    def my_getmtime(path):
        # Make sysconfig file younger then other files.
        if path == '/etc/sysconfig/authconfig':
            return 200

        return 100

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(''), '')
    mock_isfile.return_value = True
    mock_islink.return_value = True
    mock_readlink.side_effect = '{}-ac'.format
    mock_getmtime.side_effect = my_getmtime
    assert not obj.step_detect_if_confirmation_is_required()
Exemplo n.º 20
0
def test_AuthselectScannerLibrary_step_detect_sssd_features__smartcard_lock():
    pam = get_config('''
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    ''')

    dconf = get_config('''
    [org/gnome/settings-daemon/peripherals/smartcard]
    removal-action='lock-screen'
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(dconf), PAM(pam),
                                   '')
    features = obj.step_detect_sssd_features('sssd')
    assert features == ['with-smartcard-lock-on-removal']
Exemplo n.º 21
0
def test_AuthselectScannerLibrary_process__unknown_module(
        mock_confirm, mock_service):
    pam = get_config('''
    auth required pam_faillock.so preauth silent deny=4 unlock_time=1200
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    ''')

    obj = AuthselectScannerLibrary(['pam_unix', 'pam_sss', 'pam_deny'],
                                   Authconfig(''), DConf(''), PAM(pam), '')
    mock_confirm.return_value = True
    mock_service.return_value = False
    authselect = obj.process()
    assert authselect.profile is None
    assert not authselect.features
    assert authselect.confirm
Exemplo n.º 22
0
def test_AuthselectScannerLibrary_step_detect_features__all():
    pam = get_config('''
    auth required pam_faillock.so preauth silent deny=4 unlock_time=1200
    auth sufficient pam_unix.so
    auth sufficient pam_sss.so
    auth sufficient pam_fprintd.so
    auth required pam_deny.so
    account required pam_access.so
    session optional pam_oddjob_mkhomedir.so umask=0077
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(pam), '')
    features = obj.step_detect_features()
    assert len(features) == 4
    assert 'with-faillock' in features
    assert 'with-fingerprint' in features
    assert 'with-pamaccess' in features
    assert 'with-mkhomedir' in features
Exemplo n.º 23
0
def test_AuthselectScannerLibrary_step_detect_sssd_features__pkcs11():
    pam = get_config('''
    auth sufficient pam_unix.so
    auth sufficient pam_pkcs11.so
    auth sufficient pam_sss.so
    auth required pam_deny.so
    ''')

    ac = get_config('''
    USESMARTCARD=yes
    FORCESMARTCARD=yes
    ''')

    dconf = get_config('''
    [org/gnome/settings-daemon/peripherals/smartcard]
    removal-action='lock-screen'
    ''')

    obj = AuthselectScannerLibrary([], Authconfig(ac), DConf(dconf), PAM(pam),
                                   '')
    features = obj.step_detect_sssd_features('sssd')
    assert not features
Exemplo n.º 24
0
def test_Authconfig_get_bool__non_existent():
    obj = Authconfig('')
    assert not obj.get_bool('non-existent-option')
Exemplo n.º 25
0
def test_AuthselectScannerLibrary_step_detect_profile__None(mock_service):
    obj = AuthselectScannerLibrary([], Authconfig(''), DConf(''), PAM(''), '')
    mock_service.return_value = False
    assert obj.step_detect_profile() is None
Exemplo n.º 26
0
def test_Authconfig_get_string__non_existent():
    obj = Authconfig('')
    assert obj.get_string('non-existent-option') is None