Exemple #1
0
    def test_post___bmp_32kb___returns_status_code_200_protected_file(self):
        """
        5-Test_File submit using pre-signed url with valid x-api key is successful
        Steps:
            Post a file payload request with file url to endpoint: '[API GATEWAY URL]/api/Rebuild' with valid x-api key
        Expected:
            The response is returned with the processed file and success code 200
        """
        # Send post request
        response = requests.post(url=self.endpoint,
                                 json={
                                     "InputGetUrl":
                                     self.bmp_32kb_urls.get("InputGetUrl"),
                                     "OutputPutUrl":
                                     self.bmp_32kb_urls.get("OutputPutUrl"),
                                 },
                                 headers={
                                     "x-api-key": self.x_api_key,
                                 })

        # Status code should be 200, ok
        self.assertEqual(response.status_code, HTTPStatus.OK)

        # Response etag should be the same as the md5 of the input file
        self.assertEqual(
            ast.literal_eval(response.headers.get("gw-put-file-etag")),
            get_md5(self.bmp_32kb))
    def test_post___xls_malware_macro_48kb___returns_status_code_200_sanitised_file(
            self):
        """
        12-Test_upload of files with issues and or malware using base64 code with valid jwt token 
        Execution Steps:
            Post a payload request with file containing malware to url: '[API GATEWAY URL]/api/Rebuild/base64' with valid jwt token
            Post a payload request with file containing structural issues to url: '[API GATEWAY URL]/api/Rebuild/base64' with valid jwt token
            Post a payload request with file containing issues and malware to url: '[API GATEWAY URL]/api/Rebuild/base64' with valid jwt token
        Expected Results:
        The response message returned for file containing malware is:'OK' with success code '200'
        The response message returned for file containing structural issues is: 'Unprocessable Entity' with error code '422'
        The response message returned for file containing malware is: 'Unprocessable Entity' with error code '422'
        """

        # Set variable for file to test
        test_file = get_file_bytes(self.xls_malware_macro_48kb)

        # Send post request
        response = requests.post(
            url=self.endpoint,
            json={"Base64": b64encode(test_file).decode()},
            headers={
                "Content-Type": "application/json",
                "Authorization": self.jwt_token
            })

        # Status code should be 200, OK
        self.assertEqual(response.status_code, HTTPStatus.OK)

        # Response content as file bytes should match known md5 of expected bytes.
        response_file_bytes = b64decode(response.content)
        self.assertEqual(get_md5(response_file_bytes),
                         "4b6ef99d2932fd735a4eed1c1ca236ee")
Exemple #3
0
    def test_post___doc_embedded_images_12kb_content_management_policy_sanitise___returns_status_code_200_sanitised_file(
            self):
        """
        7b-Test_The default cmp policy is applied to submitted file using pre-signed url
        Steps:
                Set cmp policy for file type as 'cmptype'
                Post a file payload request with file url: '[API GATEWAY URL]/api/Rebuild/sas' with valid x-api key
        Expected:
        The response is returned with error code '200'
                If cmpType is 'Sanitise', Then the file is returned sanitised
                If cmpType is 'Allow', Then the file is allowed & the original file is returned
                If cmpType is 'Disallow', Then the file is allowed & the original file is returned
        """
        # Send post request
        response = requests.post(
            url=self.endpoint,
            json={
                "InputGetUrl":
                self.doc_embedded_images_12kb_urls.get("InputGetUrl"),
                "OutputPutUrl":
                self.doc_embedded_images_12kb_urls.get("OutputPutUrl"),
                "ContentManagementFlags": {
                    "WordContentManagement": {
                        "Metadata": 1,
                        "InternalHyperlinks": 1,
                        "ExternalHyperlinks": 1,
                        "EmbeddedFiles": 1,
                        "EmbeddedImages": 1,
                        "DynamicDataExchange": 1,
                        "Macros": 1,
                        "ReviewComments": 1,
                    },
                },
            },
            headers={
                "x-api-key": self.x_api_key,
            })

        # Status code should be 200, ok
        self.assertEqual(response.status_code, HTTPStatus.OK)

        # Response etag should be different to the md5 of the input file
        self.assertNotEqual(
            ast.literal_eval(response.headers.get("gw-put-file-etag")),
            get_md5(self.doc_embedded_images_12kb))

        # etag should match expected md5
        self.assertEqual(
            ast.literal_eval(response.headers.get("gw-put-file-etag")),
            "665f3d263d7fe25b7491cbeec657abb0")
    def test_post___doc_embedded_images_12kb_content_management_policy_sanitise___returns_status_code_200_sanitised_file(self):
        """
        4-Test_The default cmp policy is applied to submitted file using file endpoint
        Steps:
            Set cmp policy for file type as 'cmptype'
            Post file payload request to endpoint: '[API GATEWAY URL]/api/Rebuild/file' with valid x-api key
        Expected:
        The response is returned with success code '200'
            0) If cmpType is 'Allow', Then the file is allowed & the original file is returned
            1) If cmpType is 'Sanitise', Then the file is returned sanitised
            2) If cmpType is 'Disallow', Then the file is allowed & the original file is returned
        """
        # Set variable for file to test
        with open(self.doc_embedded_images_12kb, "rb") as test_file:
            # Send post request
            response = requests.post(
                url=self.endpoint,
                data={
                    "contentManagementFlagJson": json.dumps({
                        "WordContentManagement": {
                            "Metadata": 1,
                            "InternalHyperlinks": 1,
                            "ExternalHyperlinks": 1,
                            "EmbeddedFiles": 1,
                            "EmbeddedImages": 1,
                            "DynamicDataExchange": 1,
                            "Macros": 1,
                            "ReviewComments": 1
                        }
                    })
                },
                files=[("file", test_file)],
                headers={
                    "accept": "application/octet-stream",
                    "x-api-key": self.x_api_key,
                },
            )

        # Status code should be 200, ok
        self.assertEqual(
            response.status_code,
            HTTPStatus.OK
        )

        # Response content file bytes should match known md5 of expected bytes
        self.assertEqual(
            get_md5(response.content),
            "665f3d263d7fe25b7491cbeec657abb0"
        )
    def test_post___doc_embedded_images_12kb_content_management_policy_sanitise___returns_status_code_200_sanitised_file(
            self):
        """
        4-Test_The default cmp policy is applied to submitted file using base64 code
        Steps:
            Set cmp policy for file type as 'cmptype'
            Post file payload request to endpoint: '[API GATEWAY URL]/api/Rebuild/base64' with valid jwt token
        Expected:
        The response is returned with success code '200'
            0) If cmpType is 'Allow', Then the file is allowed & the original file is returned
            1) If cmpType is 'Sanitise', Then the file is returned sanitised
            2) If cmpType is 'Disallow', Then the file is allowed & the original file is returned
        """

        # Set variable for file to test
        test_file = get_file_bytes(self.doc_embedded_images_12kb)

        # Send post request
        response = requests.post(url=self.endpoint,
                                 json={
                                     "Base64": b64encode(test_file).decode(),
                                     "ContentManagementFlags": {
                                         "WordContentManagement": {
                                             "Metadata": 1,
                                             "InternalHyperlinks": 1,
                                             "ExternalHyperlinks": 1,
                                             "EmbeddedFiles": 1,
                                             "EmbeddedImages": 1,
                                             "DynamicDataExchange": 1,
                                             "Macros": 1,
                                             "ReviewComments": 1
                                         }
                                     }
                                 },
                                 headers={
                                     "Content-Type": "application/json",
                                     "Authorization": self.jwt_token
                                 })

        # Status code should be 200, ok
        self.assertEqual(response.status_code, HTTPStatus.OK)

        # Response content as file bytes should match known md5 of expected bytes.
        response_file_bytes = b64decode(response.content)
        self.assertEqual(get_md5(response_file_bytes),
                         "665f3d263d7fe25b7491cbeec657abb0")
    def test_post___xls_malware_macro_48kb___returns_status_code_200_sanitised_file(self):
        """
        12-Test_upload of files with issues and or malware using file endpoint with valid x-api key
        Execution Steps:
            Post a payload request with file containing malware to url: '[API GATEWAY URL]/api/Rebuild/file' with valid x-api key
            Post a payload request with file containing structural issues to url: '[API GATEWAY URL]/api/Rebuild/file' with valid x-api key
            Post a payload request with file containing issues and malware to url: '[API GATEWAY URL]/api/Rebuild/file' with valid x-api key
        Expected Results:
        The response message returned for file containing malware is:'OK' with success code '200'
        The response message returned for file containing structural issues is: 'Unprocessable Entity' with error code '422'
        The response message returned for file containing malware is: 'Unprocessable Entity' with error code '422'
        """
        # Set variable for file to test
        with open(self.xls_malware_macro_48kb, "rb") as test_file:
            # Send post request
            response = requests.post(
                url=self.endpoint,
                data={
                    "contentManagementFlagJson": json.dumps({
                        "WordContentManagement": {
                            "EmbeddedImages": 2,
                        }
                    })
                },
                files=[("file", test_file)],
                headers={
                    "accept": "application/octet-stream",
                    "x-api-key": self.x_api_key,
                },
            )

        # Status code should be 200, OK
        self.assertEqual(
            response.status_code,
            HTTPStatus.OK
        )

        # Response content file bytes should match known md5 of expected bytes.
        self.assertEqual(
            get_md5(response.content),
            "4b6ef99d2932fd735a4eed1c1ca236ee"
        )
Exemple #7
0
    def test_post___xls_malware_macro_48kb___returns_status_code_200_sanitised_file(
            self):
        """
        11a-Test_upload of files with issues and or malware using presigned with valid x-api key
        Execution Steps:
            Post a payload request with file containing malware to url: '[API GATEWAY URL]/api/Rebuild/sas' with valid x-api key
            Post a payload request with file containing structural issues to url: '[API GATEWAY URL]/api/Rebuild/sas' with valid x-api key
            Post a payload request with file containing issues and malware to url: '[API GATEWAY URL]/api/Rebuild/sas' with valid x-api key
        Expected Results:
            The response message returned for file containing malware is:'OK' with success code '200'
            The response message returned for file containing structural issues is: 'Unprocessable Entity' with error code '422'
            The response message returned for file containing malware is: 'Unprocessable Entity' with error code '422'
        """
        # Send post request
        response = requests.post(
            url=self.endpoint,
            json={
                "InputGetUrl":
                self.xls_malware_macro_48kb_urls.get("InputGetUrl"),
                "OutputPutUrl":
                self.xls_malware_macro_48kb_urls.get("OutputPutUrl"),
            },
            headers={"x-api-key": self.x_api_key})

        # Status code should be 200, ok
        self.assertEqual(response.status_code, HTTPStatus.OK)

        # Response etag should be different to the md5 of the input file
        self.assertNotEqual(
            ast.literal_eval(response.headers.get("gw-put-file-etag")),
            get_md5(self.xls_malware_macro_48kb))

        # etag should match expected md5
        self.assertEqual(
            ast.literal_eval(response.headers.get("gw-put-file-etag")),
            "4b6ef99d2932fd735a4eed1c1ca236ee")