示例#1
0
	def test_unlock_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)
		session = repo_sec.get(session_id)

		self.assertIsInstance(session, Session)
		self.assertEqual(session.token, token.build().decode())
		self.assertEqual(session.profile_id, str(saved.id))
		self.assertFalse(session.locked)

		repo_sec.lock(id=session_id)
		session = repo_sec.get(session_id)
		self.assertTrue(session.locked)
		
		repo_sec.unlock(id=session_id)
		session = repo_sec.get(session_id)
		self.assertFalse(session.locked)
示例#2
0
	def test_get_session_none(self):
		repo_sec = SecurityRepository(config())
		session = repo_sec.get(str(ObjectId()))
		self.assertIsNone(session)