def testGetTokenInJSON(self): import emission.net.api.bottle as enab import io user_data = io.StringIO() user_data.write(json.dumps({'user': "******"})) test_environ = etc.createDummyRequestEnviron(self, addl_headers=None, request_body=user_data) request = enab.LocalRequest(environ=test_environ) logging.debug("Found request body = %s" % request.body.getvalue()) logging.debug("Found request headers = %s" % list(request.headers.keys())) self.assertEqual(enaa.__getToken__(request, inHeader=False), "test_token") with self.assertRaises(AttributeError): self.assertEqual(enaa.__getToken__(request, inHeader=True), "test_token")
def testGetEmail(self): import emission.net.api.bottle as enab import io user_data = io.StringIO() test_email = "correct_horse_battery_staple" user_data.write(json.dumps({'user': test_email})) test_environ = etc.createDummyRequestEnviron(self, addl_headers=None, request_body=user_data) request = enab.LocalRequest(environ=test_environ) logging.debug("Found request body = %s" % request.body.getvalue()) logging.debug("Found request headers = %s" % list(request.headers.keys())) self.assertEqual(enaa._getEmail(request, "skip", inHeader=False), test_email) self.assertEqual(enaa._getEmail(request, "token_list", inHeader=False), test_email)
def testGetTokenInHeader(self): import emission.net.api.bottle as enab import io user_data = io.StringIO() addl_headers = {'HTTP_USER': '******'} test_environ = etc.createDummyRequestEnviron(self, addl_headers=addl_headers, request_body=user_data) request = enab.LocalRequest(environ=test_environ) logging.debug("Found request body = %s" % request.body.getvalue()) logging.debug("Found request headers = %s" % list(request.headers.keys())) self.assertEqual(enaa.__getToken__(request, inHeader=True), "test_header_token") with self.assertRaises(TypeError): self.assertEqual(enaa.__getToken__(request, inHeader=False), "test_header_token")
def testGetUUIDTokenAuthSuccess(self): import emission.net.api.bottle as enab import emission.core.wrapper.user as ecwu import io self.test_email = "correct_horse_battery_staple" user_data = io.StringIO() user_data.write(json.dumps({'user': self.test_email})) test_environ = etc.createDummyRequestEnviron(self, addl_headers=None, request_body=user_data) request = enab.LocalRequest(environ=test_environ) logging.debug("Found request body = %s" % request.body.getvalue()) logging.debug("Found request headers = %s" % list(request.headers.keys())) user = ecwu.User.register(self.test_email) self.assertEqual(enaa.getUUID(request, "token_list", inHeader=False), user.uuid) ecwu.User.unregister(self.test_email)