示例#1
0
def mock_user_repository(mock_auth_provider, parser) -> UserRepository:
    mock_user_repository = MemoryUserRepository(parser, mock_auth_provider)
    mock_user_repository.load({
        "default": {
            "1":
            User(id='1',
                 name="Valentina",
                 username='******',
                 email='*****@*****.**',
                 external_source='erp.users',
                 external_id='1',
                 active=False),
            "2":
            User(id='2',
                 name="Esteban",
                 username='******',
                 email='*****@*****.**',
                 external_source='erp.users'),
            "3":
            User(id='3',
                 name="Gabriel",
                 username='******',
                 email='*****@*****.**',
                 external_source='erp.users',
                 external_id='3',
                 active=False)
        }
    })
    return mock_user_repository
示例#2
0
def mock_import_service() -> ImportService:  # duda
    mock_import_service = MemoryImportService()
    user_1 = User(
        **{
            'id': "1",
            'external_source': "erp.users",
            'external_id': "1",
            'username': "******",
            'email': "*****@*****.**",
            'name': "Pablo Mendoza",
            'gender': "male",
            'attributes': {
                'site_ids': ["84"]
            }
        })
    user_2 = User(
        **{
            'external_source': "erp.users",
            'external_id': "2",
            'username': "******",
            'email': "*****@*****.**",
            'name': "Mario Duarte",
            'gender': "male",
            'attributes': {
                'site_ids': ["12"]
            }
        })
    user_4 = User(
        **{
            'external_source': "erp.users",
            'external_id': "2",
            'username': "******",
            'email': "*****@*****.**",
            'name': "Mario Duarte",
            'gender': "male",
            'attributes': {
                'site_ids': ["12"]
            }
        })
    credential_1 = Credential(value="HASHED: PASS1")
    credential_2 = Credential(value="HASHED: PASS2")
    dominion_1 = Dominion(name="default")
    dominion_2 = Dominion(name="platformxyz")
    role_1 = [[Role(name="admin"), dominion_1],
              [Role(name="user"), dominion_2]]
    users_list = [[user_1, credential_1, role_1], [user_2, None, None],
                  [user_4, credential_2, role_1]]
    mock_import_service.users = users_list
    return mock_import_service
async def test_enrollment_servicer_register_duplicated_username_error(
        enrollment_service):
    user = User(**{
        "username": "******",
        "email": "*****@*****.**",
    })

    await enrollment_service.user_repository.add(user)

    new_user = User(**{
        "username": "******",
        "email": "*****@*****.**",
    })

    with raises(UserCreationError):
        await enrollment_service._validate_duplicates([user])
示例#4
0
def user_repository(auth_provider, parser) -> UserRepository:
    user_repository = MemoryUserRepository(parser, auth_provider)
    user_repository.load({
        "default": {
            "valenep": User(id='1',
                            username='******',
                            email='*****@*****.**'),
            "tebanep": User(id='2',
                            username='******',
                            email='*****@*****.**'),
            "gabeche": User(id='3',
                            username='******',
                            email='*****@*****.**')
        }
    })
    return user_repository
示例#5
0
async def test_access_service_generate_token(access_service) -> None:
    tenant = Tenant(id='T1', name='Default')
    user = User(id='U1', username='******', email='johndoe')
    dominion = Dominion(id='D1', name='Data Server')

    token = await access_service.generate_token(tenant, user, dominion)

    assert isinstance(token, Token)
async def test_enrollment_service_username_special_characters_error(
        enrollment_service):
    with raises(UserCreationError):
        user= User(**{
            "username": "******",
            "email": "*****@*****.**",
            "password": "******"
        })
        enrollment_service._validate_usernames([user])
def test_verification_service_generate_token(verification_service) -> None:
    tenant = Tenant(id='1', name='Default', email='*****@*****.**')
    user = User(id='1', username='******', email='johndoe')

    token = verification_service.generate_token(tenant, user, 'activation')

    assert isinstance(token, Token)
    assert token.value == (
        '{"type": "activation", "tenant": "default", '
        '"tid": "1", "uid": "1", "temail": "*****@*****.**"}')
示例#8
0
async def test_access_service_generate_token_roles(access_service) -> None:
    tenant = Tenant(id='1', name='Default')
    user = User(id='1', username='******', email='johndoe')
    dominion = Dominion(id='1', name='Data Server')

    user = User(id='1', username='******', email='johndoe')
    dominion = Dominion(id='1', name='Data Server')

    token = await access_service.generate_token(tenant, user, dominion)

    assert token.value == json.dumps({
        "tid": "1",
        "tenant": "default",
        "organization": "Default",
        "uid": "1",
        "username": "******",
        "name": "",
        "email": "johndoe",
        "attributes": {},
        "roles": ['admin|1']
    })
async def test_enrollment_service_set_credentials(enrollment_service) -> None:
    users = [User(id='1', username='******', email='johndoe')]
    credentials = [Credential(value='PLAIN_TEXT_PASSWORD')]

    await enrollment_service.set_credentials(users, credentials)

    credential_repository = enrollment_service.credential_repository

    assert len(credential_repository.data['default']) == 4

    [new_credential] = await credential_repository.search(
        [('user_id', '=', '1')])

    assert len(new_credential.value)
    assert new_credential.value == 'HASHED: PLAIN_TEXT_PASSWORD'
示例#10
0
async def test_enrollment_service_register(enrollment_service) -> None:
    user = User(id='1', username='******', email='johndoe')
    credential = Credential(value='PLAIN_TEXT_PASSWORD')

    registration_tuples = [(user, credential)]

    [new_user] = await enrollment_service.register(registration_tuples)

    user_repository = enrollment_service.user_repository

    assert len(user_repository.data['default']) == 3
    assert user_repository.data['default'][new_user.id].username == 'johndoe'

    credential_repository = enrollment_service.credential_repository
    [new_credential] = await credential_repository.search(
        [('user_id', '=', '1')])
    assert new_credential.value == 'HASHED: PLAIN_TEXT_PASSWORD'
示例#11
0
async def test_procedure_manager_identity_provider_register(procedure_manager):
    user_dicts = {
        "organization": "Wonderland",
        "email": "*****@*****.**",
        "username": "",
        "password": "******"
    }
    procedure_manager.identity_service.user = User(email="*****@*****.**",
                                                   name="Alice Wonder")

    await procedure_manager.register({"meta": {}, "data": user_dicts})
    credential_repository = (
        procedure_manager.enrollment_service.credential_repository)
    user_repository = procedure_manager.user_repository

    assert len(user_repository.data['wonderland']) == 2
    [new_user] = await user_repository.search([('name', '=', 'Alice Wonder')])
    assert new_user.email == '*****@*****.**'
    assert new_user.active is False
示例#12
0
async def test_memory_identity_service_identify() -> None:
    user = User(email="*****@*****.**")
    identity_service = MemoryIdentityService(user)
    user = await identity_service.identify(
        'google', 'secret1234')
    assert user.email == '*****@*****.**'
示例#13
0
async def test_import_manager_create_ranking_no_role(import_manager):
    user = User(username='******', email='*****@*****.**')
    await import_manager._create_ranking(None, user)
    assert len(getattr(import_manager.ranking_repository,
                       'data')['default']) == 2
示例#14
0
def mock_identity_service() -> IdentityService:
    user = User(id="3", email="*****@*****.**")
    mock_identity_service = MemoryIdentityService(user)
    return mock_identity_service