def test_standard_auth_provider_verify(auth_provider): # Given a user user = User(name="asb123") # When a user is given auth_provider.setup(user) # Then the user will be set assert auth_provider.user is not None
def test_standard_auth_validate_roles_incorrect_roles(auth_provider): # Given a list of roles, a list of required roles and a # authenticated user auth_provider.setup(User(name='john', roles=['monitor'])) required_roles = ["admin"] # When a list of roles is set # Then an authorizationerror is raised with raises(AuthorizationError): auth_provider.validate_roles(required_roles)
def test_standard_auth_validate_roles_correct_roles(auth_provider): # Given a list of roles, a list of required roles and a # authenticated user auth_provider.setup(User(name='john', roles=['monitor'])) required_roles = ["monitor", "admin"] # When a list of roles is set # Then the roles are validated auth_provider.validate_roles(required_roles) assert 'monitor' in auth_provider.roles
def sample_repository(connector, tenant_provider) -> SqlRepository: parser = SqlParser(SafeEval()) auth_provider = StandardAuthProvider() auth_provider.setup(User(id='001', name='johndoe')) sql_repository: SqlRepository = SqlRepository( 'samples', SampleEntity, connector, parser, tenant_provider, auth_provider) return sql_repository
def auth_provider() -> StandardAuthProvider: auth_provider = StandardAuthProvider() auth_provider.setup(User(id='001', name='johndoe')) return auth_provider
def test_standard_auth_roles_authenticated(auth_provider): # When the get_roles method is called and there is # a valid authentication auth_provider.setup(User(name='john', roles=['admin'])) roles = auth_provider.roles assert roles == ['admin']
def auth_provider() -> StandardAuthProvider: # Given a memory auth_provider has been created auth_provider = StandardAuthProvider() auth_provider.setup(User(name="eecheverry")) return auth_provider