Exemple #1
0
    def _check_injected_file_quota(self, context, injected_files):
        """Enforce quota limits on injected files.

        Raises a QuotaError if any limit is exceeded.

        """
        if injected_files is None:
            return
        limit = quota.allowed_injected_files(context, len(injected_files))
        if len(injected_files) > limit:
            raise quota.QuotaError(code="OnsetFileLimitExceeded")
        path_limit = quota.allowed_injected_file_path_bytes(context)
        for path, content in injected_files:
            if len(path) > path_limit:
                raise quota.QuotaError(code="OnsetFilePathLimitExceeded")
            content_limit = quota.allowed_injected_file_content_bytes(context, len(content))
            if len(content) > content_limit:
                raise quota.QuotaError(code="OnsetFileContentLimitExceeded")
Exemple #2
0
 def test_unlimited_db_allowed_injected_file_content_bytes(self):
     self.flags(quota_max_injected_file_content_bytes=12345)
     db.quota_create(self.context, self.project_id, "injected_file_content_bytes", None)
     limit = quota.allowed_injected_file_content_bytes(self.context, 23456)
     self.assertEqual(limit, 23456)
Exemple #3
0
 def test_unlimited_default_allowed_injected_file_content_bytes(self):
     self.flags(quota_max_injected_file_content_bytes=-1)
     limit = quota.allowed_injected_file_content_bytes(self.context, 23456)
     self.assertEqual(limit, 23456)
 def test_overridden_allowed_injected_file_content_bytes(self):
     self.flags(quota_max_injected_file_content_bytes=12345)
     db.quota_create(self.context, self.project_id,
                     'injected_file_content_bytes', 5678)
     limit = quota.allowed_injected_file_content_bytes(self.context, 23456)
     self.assertEqual(limit, 5678)
Exemple #5
0
 def test_unlimited_db_allowed_injected_file_content_bytes(self):
     FLAGS.quota_max_injected_file_content_bytes = 12345
     db.quota_create(self.context, self.project_id,
                     'injected_file_content_bytes', None)
     limit = quota.allowed_injected_file_content_bytes(self.context, 23456)
     self.assertEqual(limit, 23456)
Exemple #6
0
 def test_default_allowed_injected_file_content_bytes(self):
     FLAGS.quota_max_injected_file_content_bytes = 12345
     limit = quota.allowed_injected_file_content_bytes(self.context, 23456)
     self.assertEqual(limit, 12345)
Exemple #7
0
 def test_allowed_injected_file_content_bytes(self):
     self.assertEqual(
         quota.allowed_injected_file_content_bytes(self.context), FLAGS.quota_max_injected_file_content_bytes
     )