def test_account_login_browserid(self): from floof.views.account import account_login_browserid as view def verify(request, next_url, flash_msg): response = view(request.context, request) flashes = request.session['_f_'] assert len(flashes) == 1 assert flash_msg in flashes[0] assert response['next_url'] == next_url audience = 'https://mysite.example.org' self.config.add_settings({'auth.browserid.audience': audience}) request = self._make_request() request.method = 'POST' request.user = sim.sim_user(credentials=[('browserid', OLD_ASSERTION_ADDR)]) for a in (None, '', self._randstr(), OLD_ASSERTION): request.POST = MultiDict({'assertion': a}) verify(request, next_url=request.route_url('account.login'), flash_msg='signature was invalid') request.session.clear() email = self._randstr() + '@example.com' verifier = DummyVerifier() a = verifier.make_assertion(email, audience) request.POST = MultiDict({'assertion': a}) request.user = sim.sim_user(credentials=[('browserid', email)]) request.environ['paste.testing'] = True request.environ['tests.auth.browserid.verifier'] = verifier request.environ['tests.auth.browserid.audience'] = audience verify(request, next_url=request.route_url('root'), flash_msg='Re-authentication successful')
def test_account_login_persona(self): from floof.views.account import account_login_persona as view def verify(request, next_url, flash_msg): response = view(request.context, request) flashes = request.session['_f_'] assert len(flashes) == 1 assert flash_msg in flashes[0] assert response['redirect-to'] == next_url audience = 'https://localhost' self.config.add_settings({'auth.persona.audience': audience}) request = self._make_request() request.method = 'POST' request.user = sim.sim_user(credentials=[('persona', OLD_ASSERTION_ADDR)]) # Test failures trials = ( (None, 'unspecified error'), ('', 'unspecified error'), (self._randstr(), 'unspecified error'), (OLD_ASSERTION, 'signature was invalid') ) for a, f in trials: request.POST = MultiDict({'assertion': a}) verify(request, next_url=request.route_url('account.login'), flash_msg=f) request.session.clear() # Test success email = self._randstr() + '@example.com' verifier = LocalVerifier([audience], warning=False) a = make_assertion(email, audience) request.POST = MultiDict({'assertion': a}) request.user = sim.sim_user(credentials=[('persona', email)]) request.environ['paste.testing'] = True request.environ['tests.auth.persona.verifier'] = verifier request.environ['tests.auth.persona.audience'] = audience with patched_supportdoc_fetching(): verify(request, next_url=request.route_url('root'), flash_msg='Re-authentication successful')
def setUp(self): """Creates a user to be used as a fake login.""" super(TestFloofAuthnPolicy, self).setUp() self.user = sim.sim_user() self.env = partial(sim.sim_user_env, self.user) self.policy = FloofAuthnPolicy()
def setUp(self): """Creates a user to be used as a fake login.""" super(TestControls, self).setUp() self.user = sim.sim_user(credentials=[]) model.session.flush() self.default_environ = {'tests.user_id': self.user.id}
def test_account_login_persona(self): from floof.views.account import account_login_persona as view def verify(request, next_url, flash_msg): response = view(request.context, request) flashes = request.session['_f_'] assert len(flashes) == 1 assert flash_msg in flashes[0] assert response['redirect-to'] == next_url audience = 'https://localhost' self.config.add_settings({'auth.persona.audience': audience}) request = self._make_request() request.method = 'POST' request.user = sim.sim_user(credentials=[('persona', OLD_ASSERTION_ADDR)]) # Test failures trials = ((None, 'unspecified error'), ('', 'unspecified error'), (self._randstr(), 'unspecified error'), (OLD_ASSERTION, 'signature was invalid')) for a, f in trials: request.POST = MultiDict({'assertion': a}) verify(request, next_url=request.route_url('account.login'), flash_msg=f) request.session.clear() # Test success email = self._randstr() + '@example.com' verifier = LocalVerifier([audience], warning=False) a = make_assertion(email, audience) request.POST = MultiDict({'assertion': a}) request.user = sim.sim_user(credentials=[('persona', email)]) request.environ['paste.testing'] = True request.environ['tests.auth.persona.verifier'] = verifier request.environ['tests.auth.persona.audience'] = audience with patched_supportdoc_fetching(): verify(request, next_url=request.route_url('root'), flash_msg='Re-authentication successful')
def setUp(self): """Creates a user to be used as a fake login.""" super(TestAccount, self).setUp() self.user = sim.sim_user() model.session.flush() self.default_environ = { 'tests.user_id': self.user.id, 'tests.auth_openid_uid': self.user.id, 'tests.auth_openid_time': time.time(), }
def test_artwork(self): """Test tagging an artwork.""" # Create some art with a known tag user = sim.sim_user() artwork = sim.sim_artwork(user=user) tag = sim.sim_tag() artwork.tag_objs.append(tag) model.session.flush() # Ensure it shows in the tag's gallery res = self.app.get(self.url('tags.artwork', tag=tag)) assert artwork.title in res
def setUp(self): """Creates a user to be used as a fake login.""" super(TestArt, self).setUp() self.user = sim.sim_user() model.session.flush()