def test_login_form_send(self): """test if the login form data is received and the environment set correctly""" fields = [('repoze.whoplugins.openid.openid','foobar.com')] content_type, body = encode_multipart_formdata(fields) environ = self.environ environ['wsgi.input'] = StringIO(body) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_LENGTH'] = len(body) environ['CONTENT_TYPE'] = content_type environ['PATH_INFO'] = '/login' identity = self.plugin.identify(environ) self.assertEqual(environ.get('repoze.whoplugins.openid.openid',None), 'foobar.com')
def test_complete_openid_request(self): """test if the openid request completes""" environ = self.environ environ['PATH_INFO'] = '/login' fields = self.server_response.items() content_type, body = encode_multipart_formdata(fields) environ['wsgi.input'] = StringIO(body) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_LENGTH'] = len(body) environ['CONTENT_TYPE'] = content_type identity = self.plugin.identify(environ) self.assertEqual(identity['repoze.who.plugins.openid.userid'],'http://repoze.myopenid.com')
def test_login_form_send(self): """test if the login form data is received and the environment set correctly""" fields = [('repoze.whoplugins.openid.openid', 'foobar.com')] content_type, body = encode_multipart_formdata(fields) environ = self.environ environ['wsgi.input'] = StringIO(body) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_LENGTH'] = len(body) environ['CONTENT_TYPE'] = content_type environ['PATH_INFO'] = '/login' identity = self.plugin.identify(environ) self.assertEqual(environ.get('repoze.whoplugins.openid.openid', None), 'foobar.com')
def test_complete_openid_request(self): """test if the openid request completes""" environ = self.environ environ['PATH_INFO'] = '/login' fields = self.server_response.items() content_type, body = encode_multipart_formdata(fields) environ['wsgi.input'] = StringIO(body) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_LENGTH'] = len(body) environ['CONTENT_TYPE'] = content_type identity = self.plugin.identify(environ) self.assertEqual(identity['repoze.who.plugins.openid.userid'], 'http://repoze.myopenid.com')
def test_challenge_redirect(self): """check if the challenge plugin works if given an openid""" # create a form POST response as if we would post the openid fields = [('repoze.whoplugins.openid.openid','foobar.com')] content_type, body = encode_multipart_formdata(fields) environ = self.environ environ['wsgi.input'] = StringIO(body) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_LENGTH'] = len(body) environ['CONTENT_TYPE'] = content_type # in this case the plugin has to redirect to the openid provider # faked by MockConsumer in this case res = self.plugin.challenge(environ, '200 Ok', {}, {}) self.assertEqual(res.location,'http://someopenidprovider.com/somewhere') self.assertEqual(res.status,'302 Found')
def test_incomplete_openid_request(self): """test if the openid request fails with a wrong identity""" environ = self.environ environ['PATH_INFO'] = '/login' sresp = self.server_response sresp['openid.identity'] = '' fields = sresp.items() content_type, body = encode_multipart_formdata(fields) environ['wsgi.input'] = StringIO(body) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_LENGTH'] = len(body) environ['CONTENT_TYPE'] = content_type identity = self.plugin.identify(environ) self.assertEqual(identity.get('repoze.who.plugins.openid.userid',None),None)
def test_challenge_redirect(self): """check if the challenge plugin works if given an openid""" # create a form POST response as if we would post the openid fields = [('repoze.whoplugins.openid.openid', 'foobar.com')] content_type, body = encode_multipart_formdata(fields) environ = self.environ environ['wsgi.input'] = StringIO(body) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_LENGTH'] = len(body) environ['CONTENT_TYPE'] = content_type # in this case the plugin has to redirect to the openid provider # faked by MockConsumer in this case res = self.plugin.challenge(environ, '200 Ok', {}, {}) self.assertEqual(res.location, 'http://someopenidprovider.com/somewhere') self.assertEqual(res.status, '302 Found')
def test_incomplete_openid_request(self): """test if the openid request fails with a wrong identity""" environ = self.environ environ['PATH_INFO'] = '/login' sresp = self.server_response sresp['openid.identity'] = '' fields = sresp.items() content_type, body = encode_multipart_formdata(fields) environ['wsgi.input'] = StringIO(body) environ['REQUEST_METHOD'] = 'POST' environ['CONTENT_LENGTH'] = len(body) environ['CONTENT_TYPE'] = content_type identity = self.plugin.identify(environ) self.assertEqual( identity.get('repoze.who.plugins.openid.userid', None), None)