Esempio n. 1
0
    def test_login_fail_validation(self):
        repo = ProfileRepository(config())
        sec_repo = SecurityRepository(config())
        sec_adapter = LoginAdapter(repo, sec_repo, config())

        with self.assertRaises(ValidationError):
            state = sec_adapter.login(None, 'test_password_invalid')
Esempio n. 2
0
    def test_login_failed_no_profile(self):
        repo = ProfileRepository(config())
        sec_repo = SecurityRepository(config())

        sec_adapter = LoginAdapter(repo, sec_repo, config())
        state = sec_adapter.login('unknown name', 'test_password')
        self.assertIsInstance(state, State)
        self.assertEqual(sec_adapter.usecase.STATE_NAME, state.name)
        self.assertEqual(sec_adapter.usecase.STATE_FAILED_NO_PROFILE,
                         state.status)
Esempio n. 3
0
    def test_login_failed_mismatch_password(self):
        repo = ProfileRepository(config())
        adapter = RegisterAdapter(repo)
        profile = adapter.register('test_name', 'test_password')

        sec_repo = SecurityRepository(config())
        sec_adapter = LoginAdapter(repo, sec_repo, config())
        state = sec_adapter.login(profile.name, 'test_password_invalid')
        self.assertIsInstance(state, State)
        self.assertEqual(sec_adapter.usecase.STATE_NAME, state.name)
        self.assertEqual(sec_adapter.usecase.STATE_FAILED_PASSWORD_MISMTACH,
                         state.status)
Esempio n. 4
0
	def test_should_be_success_after_login(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)

		adapter = FakeAdapterWithAuth(msg='auth')
		self.assertEqual('Hello auth', adapter.hello())
Esempio n. 5
0
    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())
Esempio n. 6
0
    def test_get_current_profile_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)

        current_profile_adapter = CurrentProfileAdapter(repo, sec_repo)
        name = current_profile_adapter.show()
        self.assertIsNotNone(name)
        self.assertEqual(name, profile.name)
Esempio n. 7
0
    def _main():
        repo = ProfileRepository(config())
        repo_sec = SecurityRepository(config())

        # try to run registering process
        security = LoginAdapter(repo, repo_sec, config())
        session = security.login(name, password)

        if isinstance(session, State):
            click.secho('Wrong password or profile name', fg='red')
        else:
            click.secho(
                f'Login successfull, your token is: {session.token.build().decode()}',
                fg='green')

        click.echo('=========================')
Esempio n. 8
0
	def test_should_be_fail_after_logout(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)

		logout_adapter = LogoutAdapter(sec_repo, repo)
		logout_adapter.logout()

		with self.assertRaises(AuthError):
			adapter = FakeAdapterWithAuth(msg='auth')
			adapter.hello()
Esempio n. 9
0
    def test_login_success(self):
        repo = ProfileRepository(config())
        adapter = RegisterAdapter(repo)
        profile = adapter.register('test_name', 'test_password')

        self.assertIsInstance(profile, Profile)
        self.assertIsInstance(profile.id, ObjectId)
        self.assertEqual('test_name', profile.name)
        self.assertIsNotNone(profile.password)
        self.assertIsNotNone(profile.id)

        sec_repo = SecurityRepository(config())
        sec_adapter = LoginAdapter(repo, sec_repo, config())
        session = sec_adapter.login(profile.name, 'test_password')
        self.assertIsInstance(session, Session)
        self.assertIsNotNone(session.profile_id)
        self.assertFalse(session.locked)
        self.assertIsNotNone(session.token)