From 1487db0615f16783fd01998a0f71fb2d8f97a434 Mon Sep 17 00:00:00 2001 From: hongyuzhao Date: Thu, 20 Feb 2020 15:18:36 +0800 Subject: [PATCH] Fix for ETSI Catalog Manager does not support HTTPS for Test Notification Endpoint and Notification Change-Id: I5c0133ea163b98c74fb668f2b77aaa95ec1cc3ec Issue-ID: MODELING-315 Signed-off-by: hongyuzhao --- catalog/packages/biz/notificationsutil.py | 21 ++++++++++++++++----- catalog/packages/biz/nsdm_subscription.py | 2 +- catalog/packages/biz/vnf_pkg_subscription.py | 5 +++-- catalog/packages/tests/test_nsdm_subscription.py | 21 ++++++++++++++++----- catalog/packages/tests/test_vnf_pkg_subscription.py | 11 +++++++++-- 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/catalog/packages/biz/notificationsutil.py b/catalog/packages/biz/notificationsutil.py index a18c4b3..3a1c60c 100644 --- a/catalog/packages/biz/notificationsutil.py +++ b/catalog/packages/biz/notificationsutil.py @@ -87,8 +87,13 @@ class NotificationsUtil(object): params = auth_info.get("paramsBasic", {}) username = params.get("userName") password = params.get("password") - resp = requests.post(callbackuri, data=notification, headers={'Connection': 'close'}, - auth=HTTPBasicAuth(username, password)) + resp = requests.post(callbackuri, + data=notification, + headers={'Connection': 'close', + 'content-type': 'application/json', + 'accept': 'application/json'}, + auth=HTTPBasicAuth(username, password), + verify=False) elif const.OAUTH2_CLIENT_CREDENTIALS in auth_info.get("authType", ''): # todo pass @@ -96,9 +101,15 @@ class NotificationsUtil(object): # todo pass else: - resp = requests.post(callbackuri, data=notification, headers={'Connection': 'close'}) - if resp.status_code != status.HTTP_204_NO_CONTENT: - logger.error("Sending notification to %s failed: %s" % (callbackuri, resp.text)) + resp = requests.post(callbackuri, + data=notification, + headers={'Connection': 'close', + 'content-type': 'application/json', + 'accept': 'application/json'}, + verify=False) + + if resp.status_code == status.HTTP_204_NO_CONTENT: + logger.error("Sending notification to %s failed: %s" % (callbackuri, resp)) else: logger.info("Sending notification to %s successfully.", callbackuri) except: diff --git a/catalog/packages/biz/nsdm_subscription.py b/catalog/packages/biz/nsdm_subscription.py index 1673d5f..d111bc2 100644 --- a/catalog/packages/biz/nsdm_subscription.py +++ b/catalog/packages/biz/nsdm_subscription.py @@ -89,7 +89,7 @@ class NsdmSubscription: logger.debug("Create Subscription --> Test Callback URI --" "Sending GET request to %s" % self.callback_uri) try: - response = requests.get(self.callback_uri, timeout=2) + response = requests.get(self.callback_uri, timeout=2, verify=False) if response.status_code != status.HTTP_204_NO_CONTENT: raise CatalogException("callbackUri %s returns %s status " "code." % (self.callback_uri, diff --git a/catalog/packages/biz/vnf_pkg_subscription.py b/catalog/packages/biz/vnf_pkg_subscription.py index ea57420..a98fe12 100644 --- a/catalog/packages/biz/vnf_pkg_subscription.py +++ b/catalog/packages/biz/vnf_pkg_subscription.py @@ -67,7 +67,8 @@ class CreateSubscription(object): params = self.authentication.get("paramsBasic", {}) username = params.get("userName") password = params.get("password") - response = requests.get(self.callback_uri, auth=HTTPBasicAuth(username, password), timeout=2) + response = requests.get(self.callback_uri, auth=HTTPBasicAuth(username, password), timeout=2, + verify=False) elif const.OAUTH2_CLIENT_CREDENTIALS in self.authentication.get("authType", ''): # todo pass @@ -75,7 +76,7 @@ class CreateSubscription(object): # todo pass else: - response = requests.get(self.callback_uri, timeout=2) + response = requests.get(self.callback_uri, timeout=2, verify=False) if response.status_code != status.HTTP_204_NO_CONTENT: raise VnfPkgSubscriptionException( "callbackUri %s returns %s status code." % ( diff --git a/catalog/packages/tests/test_nsdm_subscription.py b/catalog/packages/tests/test_nsdm_subscription.py index e5e2b83..2d95a1c 100644 --- a/catalog/packages/tests/test_nsdm_subscription.py +++ b/catalog/packages/tests/test_nsdm_subscription.py @@ -34,7 +34,6 @@ from catalog.pub.utils import toscaparser class TestNsdmSubscription(TestCase): - def setUp(self): self.client = APIClient() NsdmSubscriptionModel.objects.all().delete() @@ -466,7 +465,7 @@ class TestNsdmSubscription(TestCase): expected_data = { "status": 404, "detail": "Subscription(" + self.subscription_id + ") " - "doesn't exist" + "doesn't exist" } response = self.client.get('/api/nsd/v1/' 'subscriptions/' + self.subscription_id, @@ -625,7 +624,10 @@ class TestNsdmSubscription(TestCase): } mock_requests_post.assert_called_with(expect_callbackuri, data=expect_notification, auth=HTTPBasicAuth("username", "password"), - headers={'Connection': 'close'}) + headers={'Connection': 'close', + 'content-type': 'application/json', + 'accept': 'application/json'}, + verify=False) class NotificationTest(TestCase): @@ -676,7 +678,13 @@ class NotificationTest(TestCase): } } } - mock_requests_post.assert_called_with(expect_callbackuri, data=expect_notification, headers={'Connection': 'close'}) + mock_requests_post.assert_called_with(expect_callbackuri, + data=expect_notification, + headers={'Connection': 'close', + 'content-type': 'application/json', + 'accept': 'application/json'}, + verify=False + ) @mock.patch("requests.post") @mock.patch("uuid.uuid4") @@ -712,4 +720,7 @@ class NotificationTest(TestCase): } } mock_requests_post.assert_called_with(expect_callbackuri, data=expect_notification, - headers={'Connection': 'close'}) + headers={'Connection': 'close', + 'content-type': 'application/json', + 'accept': 'application/json'}, + verify=False) diff --git a/catalog/packages/tests/test_vnf_pkg_subscription.py b/catalog/packages/tests/test_vnf_pkg_subscription.py index ab90299..17de7cf 100644 --- a/catalog/packages/tests/test_vnf_pkg_subscription.py +++ b/catalog/packages/tests/test_vnf_pkg_subscription.py @@ -243,7 +243,11 @@ class TestNfPackageSubscription(TestCase): } } mock_requests_post.assert_called_with(vnf_subscription_data["callbackUri"], data=expect_notification, - headers={'Connection': 'close'}, auth=HTTPBasicAuth("admin", "pwd1234")) + headers={'Connection': 'close', + 'content-type': 'application/json', + 'accept': 'application/json'}, + auth=HTTPBasicAuth("admin", "pwd1234"), + verify=False) def test_service_query_single_subscription_not_found(self): try: @@ -314,4 +318,7 @@ class NotificationTest(TestCase): } } mock_requests_post.assert_called_with(expect_callbackuri, data=expect_notification, - headers={'Connection': 'close'}) + headers={'Connection': 'close', + 'content-type': 'application/json', + 'accept': 'application/json'}, + verify=False) -- 2.16.6