Changeset - bf8898a112b2
[Not reviewed]
default
0 1 0
Konstantin Veretennicov - 10 years ago 2016-05-01 23:29:33
kveretennicov@gmail.com
tests: capture current behavior of user creation from LDAP when email is missing
1 file changed with 43 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/other/test_auth_ldap.py
Show inline comments
 
@@ -93,3 +93,46 @@ def test_init_user_attributes_from_ldap(
 
    assert new_user.firstname == 'spam ldap first name'
 
    assert new_user.lastname == 'spam ldap last name'
 
    assert new_user.email == 'spam ldap email'
 

	
 

	
 
class _AuthLdapNoEmailMock():
 

	
 
    def __init__(self, **kwargs):
 
        pass
 

	
 
    def authenticate_ldap(self, username, password):
 
        return 'spam dn', dict(test_ldap_firstname=['spam ldap first name'],
 
                               test_ldap_lastname=['spam ldap last name'],
 
                               test_ldap_email=[''])
 

	
 

	
 
def test_init_user_attributes_from_ldap_with_missing_email(monkeypatch,
 
                                                           arrange_ldap_auth):
 
    """Authenticate unknown user with mocked LDAP where email is missing.
 
    """
 

	
 
    # Arrange test user.
 
    uniqifier = uuid.uuid4()
 
    username = 'test-user-{}'.format(uniqifier)
 
    assert User.get_by_username(username) is None
 

	
 
    # Arrange LDAP auth.
 
    monkeypatch.setattr(auth_ldap, 'AuthLdap', _AuthLdapNoEmailMock)
 

	
 
    # Authenticate with LDAP.
 
    user_data = authenticate(username, 'password')
 

	
 
    # Verify that authenication succeeded and retrieved correct attributes
 
    # from LDAP, with empty email.
 
    assert user_data is not None
 
    assert user_data.get('firstname') == 'spam ldap first name'
 
    assert user_data.get('lastname') == 'spam ldap last name'
 
    assert user_data.get('email') == ''
 

	
 
    # Verify that authentication created new user with attributes
 
    # retrieved from LDAP, with email == None.
 
    new_user = User.get_by_username(username)
 
    assert new_user is not None
 
    assert new_user.firstname == 'spam ldap first name'
 
    assert new_user.lastname == 'spam ldap last name'
 
    assert new_user.email is None
0 comments (0 inline, 0 general)