Esempio n. 1
0
def test_cannot_create_dot_variant_of_user(db_session):
    fred = models.User(username='******',
                       email='*****@*****.**',
                       password='******')
    fred2 = models.User(username='******',
                        email='*****@*****.**',
                        password='******')

    db_session.add(fred)
    db_session.add(fred2)
    with pytest.raises(exc.IntegrityError):
        db_session.flush()
Esempio n. 2
0
def test_cannot_create_case_variant_of_user(db_session):
    bob = models.User(username='******',
                      email='*****@*****.**',
                      password='******')
    bob2 = models.User(username='******',
                       email='*****@*****.**',
                       password='******')

    db_session.add(bob)
    db_session.add(bob2)
    with pytest.raises(exc.IntegrityError):
        db_session.flush()
Esempio n. 3
0
def test_check_password_upgrades_new_style_passwords():
    user = models.User(username='******')
    # Generated with passlib.hash.bcrypt.encrypt('foobar', rounds=4, ident='2b')
    user._password = '******'

    user.check_password('foobar')

    assert not password_context.needs_update(user._password)
Esempio n. 4
0
def test_check_password_validates_old_style_passwords():
    user = models.User(username='******')
    user.salt = 'somesalt'
    # Generated with passlib.hash.bcrypt.encrypt('foobar' + 'somesalt', rounds=10)
    user._password = '******'

    assert user.check_password('foobar')
    assert not user.check_password('somethingelse')
Esempio n. 5
0
def test_setting_password_unsets_salt():
    user = models.User(username='******')
    user.salt = 'somesalt'
    user._password = '******'

    user.password = '******'

    assert user.salt is None
    assert user.check_password('flibble')
Esempio n. 6
0
def test_check_password_works_after_upgrade():
    user = models.User(username='******')
    user.salt = 'somesalt'
    # Generated with passlib.hash.bcrypt.encrypt('foobar' + 'somesalt', rounds=10)
    user._password = '******'

    user.check_password('foobar')

    assert user.check_password('foobar')
Esempio n. 7
0
def test_check_password_only_upgrades_when_password_is_correct():
    user = models.User(username='******')
    user.salt = 'somesalt'
    # Generated with passlib.hash.bcrypt.encrypt('foobar' + 'somesalt', rounds=10)
    user._password = '******'

    user.check_password('donkeys')

    assert user.salt is not None
    assert password_context.needs_update(user._password)
Esempio n. 8
0
def test_userid_as_class_property(db_session):
    fred = models.User(authority='example.net',
                       username='******',
                       email='*****@*****.**')
    db_session.add(fred)
    db_session.flush()

    result = (db_session.query(
        models.User).filter_by(userid='acct:[email protected]').one())

    assert result == fred
Esempio n. 9
0
def test_User_activate_activates_user():
    user = models.User(username='******',
                       email='*****@*****.**',
                       password='******')
    activation = models.Activation()
    user.activation = activation
    db.Session.add(user)
    db.Session.flush()

    user.activate()
    db.Session.commit()

    assert user.is_activated
Esempio n. 10
0
def test_User_activate_activates_user(db_session):
    user = models.User(authority='example.com',
                       username='******',
                       email='*****@*****.**')
    activation = models.Activation()
    user.activation = activation
    db_session.add(user)
    db_session.flush()

    user.activate()
    db_session.commit()

    assert user.is_activated
Esempio n. 11
0
def test_cannot_create_user_with_too_long_username():
    with pytest.raises(ValueError):
        models.User(username='******')
Esempio n. 12
0
def test_cannot_create_user_with_too_short_username():
    with pytest.raises(ValueError):
        models.User(username='******')
Esempio n. 13
0
def test_cannot_create_user_with_invalid_chars():
    with pytest.raises(ValueError):
        models.User(username='******')
Esempio n. 14
0
def test_userid_derived_from_username_and_authority():
    fred = models.User(authority='example.net',
                       username='******',
                       email='*****@*****.**')

    assert fred.userid == 'acct:[email protected]'
Esempio n. 15
0
def test_check_password_false_with_null_password():
    user = models.User(username='******')

    assert not user.check_password('anything')
Esempio n. 16
0
 def get_by_username(request, username):
     if username == valid_user['username']:
         return models.User(**valid_user)
         return None
Esempio n. 17
0
def test_check_password_false_with_incorrect_password():
    user = models.User(username='******', password='******')

    assert not user.check_password('somethingelse')
Esempio n. 18
0
def test_check_password_true_with_matching_password():
    user = models.User(username='******', password='******')

    assert user.check_password('s3cr37')
Esempio n. 19
0
def test_cannot_create_user_with_too_long_email():
    with pytest.raises(ValueError):
        models.User(email='bob@b' + 'o' * 100 + 'b.com')
Esempio n. 20
0
def test_cannot_create_user_with_too_short_password():
    with pytest.raises(ValueError):
        models.User(password='******')
Esempio n. 21
0
 def get_by_email(request, email):
     if email == valid_user['email']:
         return models.User(**valid_user)
         return None