def test_skip_signing_large_file(self, mock_reporter):
        """
        Ensure that large files are not signed.
        Because lambda functions have limited disk space.
        :return:
        """
        mock_instance = MagicMock()
        mock_instance.add_error = MagicMock()
        mock_reporter.return_value = mock_instance

        mock_s3 = MockS3Handler()
        mock_db = MockDynamodbHandler()
        mock_logger = MockLogger()
        mock_logger.warning = MagicMock()
        mock_api = MockAPI(os.path.join(self.resources_dir, 'cdn'),
                           'https://cdn.door43.org/')
        event = self.create_event()
        item = {'repo_name': 'repo_name', 'commit_id': 'commitid'}
        format = {
            "build_rules": ["signing.sign_given_url"],
            "chapters": [],
            "contributor": [
                "Narrator: Steve Lossing", "Checker: Brad Harrington",
                "Engineer: Brad Harrington"
            ],
            "format":
            "",
            "modified":
            "",
            "quality":
            "64kbps",
            "signature":
            "",
            "size":
            0,
            "url":
            "https://cdn.door43.org/en/obs/v4/64kbps/en_obs_64kbps.zip"
        }
        mockHeaders = HeaderReader([('content-length',
                                     SigningHandler.max_file_size + 1)])

        signer = SigningHandler(event=event,
                                context=None,
                                logger=mock_logger,
                                signer=self.mock_signer,
                                s3_handler=mock_s3,
                                dynamodb_handler=mock_db,
                                url_exists_handler=mock_api.url_exists,
                                download_handler=mock_api.download_file,
                                url_headers_handler=lambda url: mockHeaders)
        (already_signed,
         newly_signed) = signer.process_format(item, None, None, format)
        mock_logger.warning.assert_called_once_with(
            'File is too large to sign https://cdn.door43.org/en/obs/v4/64kbps/en_obs_64kbps.zip'
        )
        self.assertTrue(already_signed)
        self.assertEqual(
            'https://cdn.door43.org/en/obs/v4/64kbps/en_obs_64kbps.zip.sig',
            format['signature'])
        self.assertTrue(newly_signed)
Пример #2
0
 def test_signing_small_file(self, mock_reporter):
     """
     Ensure that small files are signed properly
     :return:
     """
     mock_s3 = MockS3Handler()
     mock_db = MockDynamodbHandler()
     mock_logger = MockLogger()
     mock_api = MockAPI(os.path.join(self.resources_dir, 'cdn'),
                        'https://cdn.door43.org/')
     event = self.create_event()
     item = {'repo_name': 'repo_name', 'commit_id': 'commitid'}
     format = {
         "build_rules": ["signing.sign_given_url"],
         "chapters": [],
         "contributor": [
             "Narrator: Steve Lossing", "Checker: Brad Harrington",
             "Engineer: Brad Harrington"
         ],
         "format":
         "",
         "modified":
         "",
         "quality":
         "64kbps",
         "signature":
         "",
         "size":
         0,
         "url":
         "https://cdn.door43.org/en/obs/v4/64kbps/en_obs_64kbps.zip"
     }
     mockHeaders = HeaderReader([('content-length', 123)])
     signer = SigningHandler(event,
                             None,
                             logger=mock_logger,
                             signer=self.mock_signer,
                             s3_handler=mock_s3,
                             dynamodb_handler=mock_db,
                             url_exists_handler=mock_api.url_exists,
                             download_handler=mock_api.download_file,
                             url_headers_handler=lambda url: mockHeaders)
     (already_signed,
      newly_signed) = signer.process_format(item, None, None, format)
     self.assertEqual(
         'https://cdn.door43.org/en/obs/v4/64kbps/en_obs_64kbps.zip.sig',
         format['signature'])
     self.assertNotIn(
         'File is too large to sign https://cdn.door43.org/en/obs/v4/64kbps/en_obs_64kbps.zip',
         mock_logger._messages)
     self.assertFalse(already_signed)
     self.assertTrue(newly_signed)
Пример #3
0
    def test_manually_sign(self, mock_reporter):
        """
        This is used to manually sign large media files.
        You shouldn't actually run this test unless you want to use the signature
        :return:
        """
        return  # This takes a long time so you don't usually want to do this
        mock_s3 = MockS3Handler()
        mock_db = MockDynamodbHandler()
        mock_logger = MockLogger()
        event = self.create_event()
        item = {'repo_name': 'repo_name', 'commit_id': 'commitid'}
        quality = '720p'
        key = 'en/obs/v4/{0}/en_obs_{0}.zip'.format(quality)

        format = {
            "build_rules": ["signing.sign_given_url"],
            "format": "",
            "modified": "",
            "signature": "",
            "size": 0,
            "url": "https://cdn.door43.org/{}".format(key)
        }

        pem_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                '../../functions/signing/uW-sk.enc')
        signer = Signer(pem_file)

        signing_handler = SigningHandler(event,
                                         None,
                                         logger=mock_logger,
                                         s3_handler=mock_s3,
                                         signer=signer,
                                         dynamodb_handler=mock_db,
                                         url_size_handler=lambda url: 1)
        (already_signed, newly_signed) = signing_handler.process_format(
            item, None, None, format)
        self.assertTrue(newly_signed)
        mock_s3.download_file(
            '{}.sig'.format(key),
            os.path.expanduser('~/{}.sig'.format(os.path.basename(key))))
 def test_signing_remote_3gp_file(self, mock_reporter):
     """
     Ensure that small files are signed properly
     :return:
     """
     mock_s3 = MockS3Handler()
     mock_db = MockDynamodbHandler()
     mock_logger = MockLogger()
     mock_api = MockAPI(os.path.join(self.resources_dir, 'filedn'),
                        'https://filedn.com/')
     event = self.create_event()
     item = {'repo_name': 'repo_name', 'commit_id': 'commitid'}
     format = {
         "build_rules": ["signing.sign_given_url"],
         "chapters": [],
         "contributor": [],
         "format": "",
         "modified": "",
         "quality": "3GP",
         "signature": "",
         "size": 0,
         "url": "https://filedn.com/XYZ/en/obs/v6/en_obs_v6_3GP.zip"
     }
     mockHeaders = HeaderReader([('content-length', 345)])
     signer = SigningHandler(event,
                             None,
                             logger=mock_logger,
                             signer=self.mock_signer,
                             s3_handler=mock_s3,
                             dynamodb_handler=mock_db,
                             url_exists_handler=mock_api.url_exists,
                             download_handler=mock_api.download_file,
                             url_headers_handler=lambda url: mockHeaders)
     (already_signed,
      newly_signed) = signer.process_format(item, None, None, format)
     self.assertEqual('', format['signature'])
     self.assertEqual('application/zip; content=video/3gpp',
                      format['format'])
     self.assertEqual(116, format['size'])
     self.assertTrue(already_signed)
     self.assertTrue(newly_signed)
Пример #5
0
    def test_signing_obs_html(self, mock_reporter):
        mock_s3 = MockS3Handler()
        mock_db = MockDynamodbHandler()
        mock_logger = MockLogger()
        mock_api = MockAPI(os.path.join(self.resources_dir, 'cdn'),
                           'https://cdn.door43.org/')
        event = self.create_event()
        item = {'repo_name': 'repo_name', 'commit_id': 'commitid'}
        format = {
            "build_rules": ["signing.html_format"],
            "format": "text/html",
            "modified": "",
            "signature": "",
            "size": "",
            # NOTE: this is not the actual url format used
            "url": "https://cdn.door43.org/temp/en_obs/f8a8d8d757/en/obs.html"
        }

        dublin_core = {"identifier": "obs", "language": {"identifier": "en"}}
        mockHeaders = HeaderReader([('content-length', 123)])
        signer = SigningHandler(event,
                                None,
                                logger=mock_logger,
                                signer=self.mock_signer,
                                s3_handler=mock_s3,
                                dynamodb_handler=mock_db,
                                url_exists_handler=mock_api.url_exists,
                                download_handler=mock_api.download_file,
                                url_headers_handler=lambda url: mockHeaders)
        (already_signed,
         newly_signed) = signer.process_format(item, dublin_core, None, format)
        self.assertEqual(
            'https://cdn.door43.org/en/obs/v3/media/html/obs.html',
            format['url'])
        self.assertEqual(
            'https://cdn.door43.org/en/obs/v3/media/html/obs.html.sig',
            format['signature'])
        self.assertFalse(already_signed)
        self.assertTrue(newly_signed)