Exemplo n.º 1
0
def test_authenticate_updates_user_password_if_stalker_fails_but_ldap_successes(ldap_server, create_db, monkeypatch):
    """testing if the anima.utils.authenticate() will update the user password
    if stalker fails but ldap doesn't fail and the user exists
    """
    from ldap3.extend import StandardExtendedOperations

    def mock_return(*arg, **kwargs):
        return "pipeline"

    monkeypatch.setattr(StandardExtendedOperations, "who_am_i", mock_return)

    # This is not working with mock server
    login = '******'
    ldap_password = '******'
    stalker_password = '******'
    # create a user in Stalker with a different password
    from stalker import User
    from stalker.db.session import DBSession
    new_user = User(login=login, password=stalker_password, email='*****@*****.**', name='Pipeline')
    DBSession.add(new_user)
    DBSession.commit()
    assert new_user.check_password(ldap_password) is False
    assert new_user.check_password(stalker_password) is True

    # now authenticate with the new password
    from anima.utils import authenticate
    result = authenticate(login, ldap_password)
    # result should be True
    assert result is True
    # and the password should be updated
    pipeline_user = User.query.filter(User.login==login).first()
    assert pipeline_user is not None
    assert new_user.check_password(ldap_password) is True
    assert new_user.check_password(stalker_password) is False
Exemplo n.º 2
0
def test_authenticate_with_stalker_and_ldap_will_always_authenticate_with_ldap(ldap_server, create_db):
    """testing if the anima.utils.authenticate() function will authenticate
    fail even if the user exist in stalker when the enable_ldap_authentication
    is True
    """
    login = '******'
    password = '******'
    from anima.utils import authenticate
    result = authenticate(login, password)
    assert result is False
Exemplo n.º 3
0
    def login(self):
        """does the nasty details for user to login
        """
        from anima.utils import authenticate

        # get the user first
        login = self.login_or_email_lineEdit.text()
        password = self.password_lineEdit.text()

        if authenticate(login, password):
            self.accept()
        else:
            QtWidgets.QMessageBox.critical(self, "Error",
                                           "login or password is incorrect")
Exemplo n.º 4
0
def test_authenticate_with_stalker_and_ldap_authenticates_an_existing_ldap_user(ldap_server, create_db, monkeypatch):
    """testing if the anima.utils.authenticate() function will authenticate a
    ldap user without a problem
    """
    from ldap3.extend import StandardExtendedOperations

    def mock_return(*arg, **kwargs):
        return "pipeline"

    monkeypatch.setattr(StandardExtendedOperations, "who_am_i", mock_return)

    login = '******'
    password = '******'
    from anima.utils import authenticate
    result = authenticate(login, password)
    assert result is True
Exemplo n.º 5
0
def test_authenticate_with_stalker_and_ldap_authenticates_a_existing_ldap_user_creates_a_stalker_user(ldap_server, create_db, monkeypatch):
    """testing if the anima.utils.authenticate() function will authenticate a
    non-existing ldap user properly
    """
    from ldap3.extend import StandardExtendedOperations

    def mock_return(*arg, **kwargs):
        return "pipeline"

    monkeypatch.setattr(StandardExtendedOperations, "who_am_i", mock_return)

    login = '******'
    password = '******'
    from anima.utils import authenticate
    result = authenticate(login, password)
    assert result is True
    # check the user in Stalker DB
    from stalker import User
    pipeline_user = User.query.filter(User.login==login).first()
    assert pipeline_user is not None