Fix for ETSI Catalog Manager does not support HTTPS for Test Notification Endpoint... 48/102048/2
authorhongyuzhao <zhao.hongyu@zte.com.cn>
Thu, 20 Feb 2020 07:18:36 +0000 (15:18 +0800)
committerhongyuzhao <zhao.hongyu@zte.com.cn>
Thu, 20 Feb 2020 07:25:23 +0000 (15:25 +0800)
Change-Id: I5c0133ea163b98c74fb668f2b77aaa95ec1cc3ec
Issue-ID: MODELING-315
Signed-off-by: hongyuzhao <zhao.hongyu@zte.com.cn>
catalog/packages/biz/notificationsutil.py
catalog/packages/biz/nsdm_subscription.py
catalog/packages/biz/vnf_pkg_subscription.py
catalog/packages/tests/test_nsdm_subscription.py
catalog/packages/tests/test_vnf_pkg_subscription.py

index a18c4b3..3a1c60c 100644 (file)
@@ -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:
index 1673d5f..d111bc2 100644 (file)
@@ -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,
index ea57420..a98fe12 100644 (file)
@@ -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." % (
index e5e2b83..2d95a1c 100644 (file)
@@ -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)
index ab90299..17de7cf 100644 (file)
@@ -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)