def test_app_configuration_with_valid_call(self): """If the call is authenticated then the call will get passed""" key_text = load_key('priv') self.app.config['MAUTH_APP_UUID'] = '671785CD-15CE-458A-9779-8132C8F60F04' self.app.config['MAUTH_KEY_DATA'] = key_text self.app.config['MAUTH_BASE_URL'] = "https://mauth-sandbox.imedidata.net" self.app.config['MAUTH_VERSION'] = "v2" self.app.config['MAUTH_MODE'] = "local" @self.app.route("/", methods=['GET']) @requires_authentication def test_url_closed(): return "Ping" client = self.app.test_client() with mock.patch("flask_mauth.auth.LocalAuthenticator") as local_auth: m_auth = local_auth.return_value m_auth.is_authentic.return_value = True, 200, "" authenticator = MAuthAuthenticator() authenticator.init_app(self.app) # protected URL rv = client.get("/") self.assertEqual(200, rv.status_code) self.assertEqual(b'Ping', rv.data)
def test_app_configuration_and_call_open_url(self): """An open route will pass""" key_text = load_key('priv') self.app.config['MAUTH_APP_UUID'] = '671785CD-15CE-458A-9779-8132C8F60F04' self.app.config['MAUTH_KEY_DATA'] = key_text self.app.config['MAUTH_BASE_URL'] = "https://mauth-sandbox.imedidata.net" self.app.config['MAUTH_VERSION'] = "v2" self.app.config['MAUTH_MODE'] = "local" authenticator = MAuthAuthenticator() authenticator.init_app(self.app) @self.app.route("/lemon", methods=['GET']) def test_url_open(): return "Ping" client = self.app.test_client() # open URL rv = client.get("/lemon") self.assertEqual(200, rv.status_code) self.assertEqual(b'Ping', rv.data)
def test_app_configuration_and_call_protected_url(self): """A protected route will raise if the call is inauthentic""" key_text = load_key('priv') self.app.config['MAUTH_APP_UUID'] = '671785CD-15CE-458A-9779-8132C8F60F04' self.app.config['MAUTH_KEY_DATA'] = key_text self.app.config['MAUTH_BASE_URL'] = "https://mauth-sandbox.imedidata.net" self.app.config['MAUTH_VERSION'] = "v2" self.app.config['MAUTH_MODE'] = "local" authenticator = MAuthAuthenticator() authenticator.init_app(self.app) @self.app.route("/", methods=['GET']) @requires_authentication def test_url_closed(): return "Ping" client = self.app.test_client() # protected URL rv = client.get("/") self.assertEqual(401, rv.status_code) self.assertEqual(dict(errors=dict(mauth=["Authentication Failed. No mAuth signature present; " "X-MWS-Authentication header is blank."])), json.loads(rv.data.decode('utf-8')))