diff options
author | hongyuzhao <zhao.hongyu@zte.com.cn> | 2020-02-20 15:18:36 +0800 |
---|---|---|
committer | hongyuzhao <zhao.hongyu@zte.com.cn> | 2020-02-20 15:25:23 +0800 |
commit | 1487db0615f16783fd01998a0f71fb2d8f97a434 (patch) | |
tree | fb2edf5a03dbec467e446f242ec0b68246a5b004 /catalog/packages | |
parent | 0eaa773364c415f946860fef6f69f1fcda414178 (diff) |
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 <zhao.hongyu@zte.com.cn>
Diffstat (limited to 'catalog/packages')
-rw-r--r-- | catalog/packages/biz/notificationsutil.py | 21 | ||||
-rw-r--r-- | catalog/packages/biz/nsdm_subscription.py | 2 | ||||
-rw-r--r-- | catalog/packages/biz/vnf_pkg_subscription.py | 5 | ||||
-rw-r--r-- | catalog/packages/tests/test_nsdm_subscription.py | 21 | ||||
-rw-r--r-- | 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) |