Пример #1
0
def login(dbsession, user):
    from autonomie.models.user.login import Login
    login = Login(login=u"login", user_id=user.id)
    login.set_password('pwd')
    dbsession.add(login)
    dbsession.flush()
    login.user = user
    user.login = login
    return login
Пример #2
0
def login(dbsession, user):
    from autonomie.models.user.login import Login
    login = Login(login=u"login", user_id=user.id)
    login.set_password('pwd')
    dbsession.add(login)
    dbsession.flush()
    login.user = user
    user.login = login
    return login
Пример #3
0
def test_auth(dbsession):
    """
    Test user authentication
    """
    a = Login(login="******")
    a.set_password('pwd')
    assert a.auth("pwd") is True
    strange = "#;\'\\\" $25; é ö ô è à ù"
    a.set_password(strange)
    assert not a.auth("pwd")
    assert a.auth(strange) is True

    a.active = False
    assert not a.auth(strange)
Пример #4
0
def test_auth(dbsession):
    """
    Test user authentication
    """
    a = Login(login="******")
    a.set_password('pwd')
    assert a.auth("pwd") is True
    strange = "#;\'\\\" $25; é ö ô è à ù"
    a.set_password(strange)
    assert not a.auth("pwd")
    assert a.auth(strange) is True

    a.active = False
    assert not a.auth(strange)
Пример #5
0
def test_edit_schema_login_context(
    dbsession, pyramid_request, login, user, groups
):
    import colander
    from autonomie.forms.user.login import get_add_edit_schema
    from autonomie.models.user.login import Login
    from autonomie.models.user.user import User

    user2 = User(email='*****@*****.**', lastname='lastname2', firstname='firstname2')
    dbsession.add(user2)
    dbsession.flush()

    item = Login(user_id=user2.id, login="******")
    item.set_password('pwd2')
    dbsession.add(item)
    dbsession.flush()

    pyramid_request.context = item

    schema = get_add_edit_schema(edit=True)
    schema = schema.bind(request=pyramid_request)
    result = schema.deserialize(
        {
            'login': '******',
            'pwd_hash': '',
            'primary_group': "manager",
                'groups': ['trainer'],
            'user_id': user2.id,
        }
    )

    assert 'pwd_hash' not in result

    result = schema.deserialize(
        {
            'login': '******',
            'pwd_hash': 'notpwd2',
            'primary_group': "manager",
            'groups': ['trainer'],
            'user_id': user2.id,
        }
    )

    assert 'pwd_hash' in result

    # Login already used
    with pytest.raises(colander.Invalid):
        schema.deserialize(
            {
                'login': '******',
                'pwd_hash': '',
                'primary_group': "manager",
                'groups': ['trainer'],
                'user_id': user2.id,
            }
        )

    # User already linked to Login class
    with pytest.raises(colander.Invalid):
        schema.deserialize(
            {
                'login': '******',
                'pwd_hash': 'ooo',
                'primary_group': "manager",
                'groups': ['trainer'],
                'user_id': user.id
            }
        )

    # wrong primary group
    with pytest.raises(colander.Invalid):
        schema.deserialize(
            {
                'login': '******',
                'pwd_hash': 'ooo',
                "primary_group": "falseone",
                'groups': ['trainer'],
                'user_id': user2.id,
            }
        )
    # wrong group
    with pytest.raises(colander.Invalid):
        schema.deserialize(
            {
                'login': '******',
                'pwd_hash': 'ooo',
                "primary_group": "contractor",
                'user_id': user2.id,
                "groups": ["falseone"],
            }
        )
Пример #6
0
def test_edit_schema_login_context(dbsession, pyramid_request, login, user,
                                   groups):
    import colander
    from autonomie.forms.user.login import get_add_edit_schema
    from autonomie.models.user.login import Login
    from autonomie.models.user.user import User

    user2 = User(email='*****@*****.**', lastname='lastname2', firstname='firstname2')
    dbsession.add(user2)
    dbsession.flush()

    item = Login(user_id=user2.id, login="******")
    item.set_password('pwd2')
    dbsession.add(item)
    dbsession.flush()

    pyramid_request.context = item

    schema = get_add_edit_schema(edit=True)
    schema = schema.bind(request=pyramid_request)
    result = schema.deserialize({
        'login': '******',
        'pwd_hash': '',
        'primary_group': "manager",
        'groups': ['trainer'],
        'user_id': user2.id,
    })

    assert 'pwd_hash' not in result

    result = schema.deserialize({
        'login': '******',
        'pwd_hash': 'notpwd2',
        'primary_group': "manager",
        'groups': ['trainer'],
        'user_id': user2.id,
    })

    assert 'pwd_hash' in result

    # Login already used
    with pytest.raises(colander.Invalid):
        schema.deserialize({
            'login': '******',
            'pwd_hash': '',
            'primary_group': "manager",
            'groups': ['trainer'],
            'user_id': user2.id,
        })

    # User already linked to Login class
    with pytest.raises(colander.Invalid):
        schema.deserialize({
            'login': '******',
            'pwd_hash': 'ooo',
            'primary_group': "manager",
            'groups': ['trainer'],
            'user_id': user.id
        })

    # wrong primary group
    with pytest.raises(colander.Invalid):
        schema.deserialize({
            'login': '******',
            'pwd_hash': 'ooo',
            "primary_group": "falseone",
            'groups': ['trainer'],
            'user_id': user2.id,
        })
    # wrong group
    with pytest.raises(colander.Invalid):
        schema.deserialize({
            'login': '******',
            'pwd_hash': 'ooo',
            "primary_group": "contractor",
            'user_id': user2.id,
            "groups": ["falseone"],
        })