def test_logout_success(self): repo = ProfileRepository(config()) adapter = RegisterAdapter(repo) profile = adapter.register('test_name', 'test_password') self.assertIsInstance(profile, Profile) sec_repo = SecurityRepository(config()) sec_adapter = LoginAdapter(repo, sec_repo, config()) session = sec_adapter.login(profile.name, 'test_password') self.assertIsInstance(session, Session) self.assertTrue(sec_repo.is_exist()) logout_adapter = LogoutAdapter(sec_repo, repo) logout_adapter.logout() self.assertFalse(sec_repo.is_exist())
def test_logout_no_session(self): repo = ProfileRepository(config()) sec_repo = SecurityRepository(config()) logout_adapter = LogoutAdapter(sec_repo, repo) logout_adapter.logout() self.assertFalse(sec_repo.is_exist())
def wrapper_cls(*args, **kwargs): # check if session exist or not repo = SecurityRepository(config()) if not repo.is_exist(): raise AuthError() # create original adapter obj = cls(*args, **kwargs) return obj
def test_remove_success(self): password = Password(raw='test_password', hasher=Sha256Hasher) profile = Profile(name='test_name', password=password) repo = ProfileRepository(config()) saved = repo.create(profile) self.assertTrue(saved) payload = {'name': profile.name} token = Token(salt='test_salt', payload=payload, builder=JWTToken) session = Session(token=token, locked=False, profile_id=saved.id) repo_sec = SecurityRepository(config()) session_id = repo_sec.register(session) self.assertIsInstance(session_id, str) self.assertTrue(repo_sec.remove(session_id)) self.assertFalse(repo_sec.is_exist())
def test_is_exist_invalid_id(self): repo_sec = SecurityRepository(config()) with self.assertRaises(StorageError): repo_sec.is_exist(id='invalid_id')
def test_is_exist_false_with_invalid_id(self): repo_sec = SecurityRepository(config()) self.assertFalse(repo_sec.is_exist(id=str(ObjectId())))