def test_raises_error_for_archive_with_backslashes_in_filenames(self): filename = ( 'src/olympia/files/' 'fixtures/files/archive-with-invalid-chars-in-filenames.zip' ) with pytest.raises(utils.InvalidZipFile): utils.SafeZip(filename)
def test_ignores_error_for_archive_with_backslashes_in_filenames_with_argument( self, ): filename = ( 'src/olympia/files/' 'fixtures/files/archive-with-invalid-chars-in-filenames.zip' ) utils.SafeZip(filename, ignore_filename_errors=True)
def test_apps_disallow_thunderbird_and_seamonkey(self): zip_file = utils.SafeZip(get_addon_file( 'valid_firefox_and_thunderbird_addon.xpi')) extracted = utils.RDFExtractor(zip_file).parse() apps = extracted['apps'] assert len(apps) == 1 assert apps[0].appdata == amo.FIREFOX assert apps[0].min.version == '38.0a1' assert apps[0].max.version == '43.0'
def test_apps(self): zip_file = utils.SafeZip( get_addon_file('valid_firefox_and_thunderbird_addon.xpi')) extracted = utils.RDFExtractor(zip_file).parse() apps = sorted(extracted['apps'], key=attrgetter('id')) assert len(apps) == 2 assert apps[0].appdata == amo.FIREFOX assert apps[0].min.version == '38.0a1' assert apps[0].max.version == '43.0' assert apps[1].appdata == amo.THUNDERBIRD assert apps[1].min.version == '42.0' assert apps[1].max.version == '45.0'
def test_general_entity_expansion_is_disabled(self): zip_file = utils.SafeZip(os.path.join( os.path.dirname(__file__), '..', 'fixtures', 'files', 'xxe-example-install.zip')) # This asserts that the malicious install.rdf blows up with # a parse error. If it gets as far as this specific parse error # it means that the external entity was not processed. # # Before the patch in files/utils.py, this would raise an IOError # from the test suite refusing to make an external HTTP request to # the entity ref. with pytest.raises(EntitiesForbidden): utils.RDFExtractor(zip_file)
def test_raises_validation_error_when_uncompressed_size_is_too_large(self): with override_settings(MAX_ZIP_UNCOMPRESSED_SIZE=1000): with pytest.raises(forms.ValidationError): # total uncompressed size of this xpi is: 2269 bytes utils.SafeZip( get_addon_file('valid_firefox_and_thunderbird_addon.xpi'))
def test_raises_error_for_invalid_webextension_xpi(self): with pytest.raises(zipfile.BadZipFile): utils.SafeZip(get_addon_file('invalid_webextension.xpi'))
def test_raises_error_for_invalid_webextension_xpi(self): with pytest.raises(forms.ValidationError): utils.SafeZip(get_addon_file('invalid_webextension.xpi'))
def test_raises_validation_error_when_uncompressed_size_is_too_large(self): with override_settings(MAX_ZIP_UNCOMPRESSED_SIZE=1000): with pytest.raises(forms.ValidationError): # total uncompressed size of this xpi is 126kb utils.SafeZip(get_addon_file('mozilla_static_theme.zip'))