def tearDown(self): self.strategy = None User.reset_cache() TestUserSocialAuth.reset_cache() TestNonce.reset_cache() TestAssociation.reset_cache() HTTPretty.disable()
def test_multiple_accounts_with_same_email(self): user1 = User(username='******') user2 = User(username='******') user1.email = '*****@*****.**' user2.email = '*****@*****.**' with self.assertRaises(AuthException): self.do_login(after_complete_checks=False)
def test_inactive_user(self): self.strategy.set_settings({ 'SOCIAL_AUTH_INACTIVE_USER_URL': '/inactive' }) User.set_active(False) redirect = self.do_login(after_complete_checks=False) expect(redirect.url).to.equal('/inactive')
def test_multiple_accounts_with_same_email(self): user1 = User(username='******') user2 = User(username='******') user1.email = '*****@*****.**' user2.email = '*****@*****.**' self.do_login.when.called_with(after_complete_checks=False)\ .should.throw(AuthException)
def setUp(self): HTTPretty.enable() User.reset_cache() TestUserSocialAuth.reset_cache() TestNonce.reset_cache() TestAssociation.reset_cache() self.backend = module_member('social.backends.github.GithubOAuth2') self.strategy = TestStrategy(self.backend, TestStorage) self.user = None
def setUp(self): HTTPretty.enable() User.reset_cache() TestUserSocialAuth.reset_cache() TestNonce.reset_cache() TestAssociation.reset_cache() Backend = module_member('social.backends.github.GithubOAuth2') self.strategy = self.strategy or TestStrategy(TestStorage) self.backend = Backend(self.strategy, redirect_uri='/complete/github') self.user = None
def tearDown(self): self.backend = None self.strategy = None self.user = None User.reset_cache() User.set_active(True) TestUserSocialAuth.reset_cache() TestNonce.reset_cache() TestAssociation.reset_cache() HTTPretty.disable()
def setUp(self): HTTPretty.enable() User.reset_cache() TestUserSocialAuth.reset_cache() TestNonce.reset_cache() TestAssociation.reset_cache() Backend = module_member("social.backends.github.GithubOAuth2") self.strategy = self.strategy or TestStrategy(TestStorage) self.backend = Backend(self.strategy, redirect_uri="/complete/github") self.user = None
def tearDown(self): HTTPretty.disable() self.backend = None self.strategy = None self.name = None self.complete_url = None User.reset_cache() TestUserSocialAuth.reset_cache() TestNonce.reset_cache() TestAssociation.reset_cache() TestCode.reset_cache()
def test_disconnect_with_partial_pipeline(self): self.strategy.set_settings({ 'SOCIAL_AUTH_DISCONNECT_PIPELINE': ( 'social.pipeline.partial.save_status_to_session', 'social.tests.pipeline.ask_for_password', 'social.tests.pipeline.set_password', 'social.pipeline.disconnect.allowed_to_disconnect', 'social.pipeline.disconnect.get_entries', 'social.pipeline.disconnect.revoke_tokens', 'social.pipeline.disconnect.disconnect' ) }) self.do_login() user = User.get(self.expected_username) redirect = do_disconnect(self.backend, user) url = self.strategy.build_absolute_uri('/password') expect(redirect.url).to.equal(url) HTTPretty.register_uri(HTTPretty.GET, redirect.url, status=200, body='foobar') HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200) password = '******' requests.get(url) requests.post(url, data={'password': password}) data = parse_qs(HTTPretty.last_request.body) expect(data['password']).to.equal(password) self.strategy.session_set('password', data['password']) redirect = do_disconnect(self.backend, user) expect(len(user.social)).to.equal(0)
def setUp(self): HTTPretty.enable() self.backend = module_member(self.backend_path) self.strategy = TestStrategy(self.backend, TestStorage) self.name = self.backend.name.upper().replace("-", "_") self.complete_url = self.strategy.build_absolute_uri(self.raw_complete_url.format(self.backend.name)) backends = (self.backend_path, "social.tests.backends.test_broken.BrokenBackendAuth") self.strategy.set_settings({"SOCIAL_AUTH_AUTHENTICATION_BACKENDS": backends}) self.strategy.set_settings(self.extra_settings()) # Force backends loading to trash PSA cache load_backends(backends, force_load=True) User.reset_cache() TestUserSocialAuth.reset_cache() TestNonce.reset_cache() TestAssociation.reset_cache() TestCode.reset_cache()
def test_disconnect_with_association_id(self): self.do_login() user = User.get(self.expected_username) user.password = '******' association_id = user.social[0].id second_usa = TestUserSocialAuth(user, user.social[0].provider, "uid2") self.assertEqual(len(user.social), 2) do_disconnect(self.backend, user, association_id) self.assertEqual(len(user.social), 1) self.assertEqual(user.social[0], second_usa)
def setUp(self): HTTPretty.enable() self.backend = module_member(self.backend_path) self.strategy = TestStrategy(self.backend, TestStorage) self.name = self.backend.name.upper().replace('-', '_') self.complete_url = self.strategy.build_absolute_uri( self.raw_complete_url.format(self.backend.name)) backends = (self.backend_path, 'social.tests.backends.test_broken.BrokenBackendAuth') self.strategy.set_settings( {'SOCIAL_AUTH_AUTHENTICATION_BACKENDS': backends}) self.strategy.set_settings(self.extra_settings()) # Force backends loading to trash PSA cache load_backends(backends, force_load=True) User.reset_cache() TestUserSocialAuth.reset_cache() TestNonce.reset_cache() TestAssociation.reset_cache() TestCode.reset_cache()
def test_revoke_token(self): self.strategy.set_settings({ 'SOCIAL_AUTH_REVOKE_TOKENS_ON_DISCONNECT': True }) self.do_login() user = User.get(self.expected_username) user.password = '******' HTTPretty.register_uri(self._method(self.backend.REVOKE_TOKEN_METHOD), self.backend.REVOKE_TOKEN_URL, status=200) do_disconnect(self.backend, user)
def test_user_persists_in_partial_pipeline(self): user = User(username='******') user.email = '*****@*****.**' self.strategy.set_settings({ 'SOCIAL_AUTH_PIPELINE': ('social.pipeline.social_auth.social_details', 'social.pipeline.social_auth.social_uid', 'social.pipeline.social_auth.associate_by_email', 'social.tests.pipeline.set_user_from_args') }) redirect = self.do_login(after_complete_checks=False) # Handle the partial pipeline self.strategy.session_set('attribute', 'testing') data = self.strategy.session_pop('partial_pipeline') idx, backend, xargs, xkwargs = self.strategy.partial_from_session(data) self.backend.continue_pipeline(pipeline_index=idx, *xargs, **xkwargs)
def test_user_persists_in_partial_pipeline(self): user = User(username='******') user.email = '*****@*****.**' self.strategy.set_settings({ 'SOCIAL_AUTH_PIPELINE': ( 'social.pipeline.social_auth.social_details', 'social.pipeline.social_auth.social_uid', 'social.pipeline.social_auth.associate_by_email', 'social.tests.pipeline.set_user_from_args' ) }) redirect = self.do_login(after_complete_checks=False) # Handle the partial pipeline self.strategy.session_set('attribute', 'testing') data = self.strategy.session_pop('partial_pipeline') idx, backend, xargs, xkwargs = self.strategy.partial_from_session(data) self.backend.continue_pipeline(pipeline_index=idx, *xargs, **xkwargs)
def test_get_social_auth_for_user(self): with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG): self.user.get_social_auth_for_user(User('foobar'))
def test_random_username(self): User(username='******') self.do_login(after_complete_checks=False) expect(self.strategy.session_get('username').startswith('foobar')) \ .to.equal(True)
def test_not_allowed_to_disconnect(self): self.do_login() user = User.get(self.expected_username) do_disconnect.when.called_with(self.backend, user).should.throw( NotAllowedToDisconnect )
def test_disconnect(self): self.do_login() user = User.get(self.expected_username) user.password = '******' do_disconnect(self.backend, user) expect(len(user.social)).to.equal(0)
def test_disconnect(self): self.do_login() user = User.get(self.expected_username) user.password = '******' do_disconnect(self.strategy, user) expect(len(user.social)).to.equal(0)
def test_multiple_accounts_with_same_email(self): user = User(username='******') user.email = '*****@*****.**' self.do_login(after_complete_checks=False) expect(self.strategy.session_get('username').startswith('foobar')) \ .to.equal(True)
def test_get_username(self): self.user.get_username.when.called_with(User('foobar')).should.throw( NotImplementedError, 'Implement in subclass')
def test_not_allowed_to_disconnect(self): self.do_login() user = User.get(self.expected_username) with self.assertRaises(NotAllowedToDisconnect): do_disconnect(self.backend, user)
def test_get_social_auth_for_user(self): self.user.get_social_auth_for_user.when.called_with(User('foobar')) \ .should.throw(NotImplementedError, 'Implement in subclass')
def setUp(self): super(AssociateActionTest, self).setUp() self.user = User(username='******', email='*****@*****.**')
def test_get_username(self): with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG): self.user.get_username(User('foobar'))
def test_inactive_user(self): self.strategy.set_settings( {'SOCIAL_AUTH_INACTIVE_USER_URL': '/inactive'}) User.set_active(False) redirect = self.do_login(after_complete_checks=False) expect(redirect.url).to.equal('/inactive')
def test_create_social_auth(self): with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG): self.user.create_social_auth(User('foobar'), 1, 'foo')
def test_create_social_auth(self): self.user.create_social_auth.when \ .called_with(User('foobar'), 1, 'foo') \ .should.throw(NotImplementedError, 'Implement in subclass')