def test_instanciate_without_data(self): """Without data, we load the data from the file path.""" data = {'id': 'some-id'} fake_zip = utils.make_xpi({'manifest.json': json.dumps(data)}) extractor = utils.ManifestJSONExtractor(zipfile.ZipFile(fake_zip)) assert extractor.data == data
def test_allow_static_theme_waffle(self): manifest = utils.ManifestJSONExtractor( '/fake_path', '{"theme": {}}').parse() utils.check_xpi_info(manifest) assert self.parse({'theme': {}})['type'] == amo.ADDON_STATICTHEME
def test_parse_langpack(self): self.create_appversion('firefox', '60.0') self.create_appversion('firefox', '60.*') self.create_appversion('android', '60.0') self.create_appversion('android', '60.*') data = { 'applications': { 'gecko': { 'strict_min_version': '>=60.0', 'strict_max_version': '=60.*', 'id': '@langp' } }, 'langpack_id': 'foo' } parsed_data = utils.ManifestJSONExtractor('/fake_path', json.dumps(data)).parse() assert parsed_data['type'] == amo.ADDON_LPAPP assert parsed_data['strict_compatibility'] is True assert parsed_data['is_webextension'] is True apps = parsed_data['apps'] assert len(apps) == 1 # Langpacks are not compatible with android. assert apps[0].appdata == amo.FIREFOX assert apps[0].min.version == '60.0' assert apps[0].max.version == '60.*'
def test_check_xpi_info_langpack_submission_restrictions(self): user = user_factory() self.create_appversion('firefox', '60.0') self.create_appversion('firefox', '60.*') data = { 'applications': { 'gecko': { 'strict_min_version': '>=60.0', 'strict_max_version': '=60.*', 'id': '@langp' } }, 'langpack_id': 'foo' } parsed_data = utils.ManifestJSONExtractor('/fake_path.xpi', json.dumps(data)).parse() with self.assertRaises(ValidationError): # Regular users aren't allowed to submit langpacks. utils.check_xpi_info(parsed_data, xpi_file=mock.Mock(), user=user) # Shouldn't raise for users with proper permissions self.grant_permission(user, ':'.join(amo.permissions.LANGPACK_SUBMIT)) utils.check_xpi_info(parsed_data, xpi_file=mock.Mock(), user=user)
def test_parse_dictionary(self): self.create_appversion('firefox', '61.0') data = { 'applications': { 'gecko': { 'id': '@dict' } }, 'dictionaries': { 'en-US': '/path/to/en-US.dic' } } parsed_data = utils.ManifestJSONExtractor('/fake_path', json.dumps(data)).parse() assert parsed_data['type'] == amo.ADDON_DICT assert parsed_data['strict_compatibility'] is False assert parsed_data['is_webextension'] is True assert parsed_data['target_locale'] == 'en-US' apps = parsed_data['apps'] assert len(apps) == 1 # Dictionaries are not compatible with android. assert apps[0].appdata == amo.FIREFOX assert apps[0].min.version == '61.0' assert apps[0].max.version == '*'
def test_instanciate_without_data(self): """Without data, we load the data from the file path.""" data = {'id': 'some-id'} with tempfile.NamedTemporaryFile(dir=settings.TMP_PATH) as file_: file_.write(json.dumps(data)) file_.flush() mje = utils.ManifestJSONExtractor(file_.name) assert mje.data == data
def test_static_theme_max_size(self): xpi_file = mock.Mock(size=settings.MAX_STATICTHEME_SIZE - 1) manifest = utils.ManifestJSONExtractor('{"theme": {}}').parse() # Calling to check it doesn't raise. assert utils.check_xpi_info(manifest, xpi_file=xpi_file) # Increase the size though and it should raise an error. xpi_file.size = settings.MAX_STATICTHEME_SIZE + 1 with pytest.raises(forms.ValidationError) as exc: utils.check_xpi_info(manifest, xpi_file=xpi_file) assert exc.value.message == 'Maximum size for WebExtension themes is 7.0 MB.' # dpuble check only static themes are limited manifest = utils.ManifestJSONExtractor('{}').parse() assert utils.check_xpi_info(manifest, xpi_file=xpi_file)
def test_allow_static_theme_waffle(self): create_switch('allow-static-theme-uploads') manifest = utils.ManifestJSONExtractor('/fake_path', '{"theme": {}}').parse() utils.check_xpi_info(manifest) assert self.parse({'theme': {}})['is_static_theme']
def test_disallow_static_theme(self): manifest = utils.ManifestJSONExtractor('/fake_path', '{"theme": {}}').parse() with pytest.raises(forms.ValidationError) as exc: utils.check_xpi_info(manifest) assert (exc.value.message == 'WebExtension theme uploads are currently not supported.')
def test_parse_langpack_not_targeting_versions_explicitly(self): data = {'applications': {'gecko': {'id': '@langp'}}, 'langpack_id': 'foo'} parsed_data = utils.ManifestJSONExtractor(json.dumps(data)).parse() assert parsed_data['type'] == amo.ADDON_LPAPP assert parsed_data['strict_compatibility'] is True apps = parsed_data['apps'] assert len(apps) == 1 # Langpacks are not compatible with android. assert apps[0].appdata == amo.FIREFOX assert apps[0].min.version == '42.0' # The linter should force the langpack to have a strict_max_version, # so the value here doesn't matter much. assert apps[0].max.version == '*'
def test_comments_are_allowed(self): json_string = """ { // Required "manifest_version": 2, "name": "My Extension", "version": "versionString", // Recommended "default_locale": "en", "description": "A plain text description" } """ manifest = utils.ManifestJSONExtractor(json_string).parse() assert manifest.get('name') == 'My Extension'
def test_devtools_page(self): json_string = """ { // Required "manifest_version": 2, "name": "My Extension", "version": "versionString", // Recommended "default_locale": "en", "description": "A plain text description", "devtools_page": "devtools/my-page.html" } """ parsed_data = utils.ManifestJSONExtractor(json_string).parse() assert parsed_data['devtools_page'] == 'devtools/my-page.html'
def test_handle_utf_bom(self): manifest = '\xef\xbb\xbf{"manifest_version": 2, "name": "..."}' parsed = utils.ManifestJSONExtractor(None, manifest).parse() assert parsed['name'] == '...'
def parse(self, base_data): return utils.ManifestJSONExtractor( '/fake_path', json.dumps(base_data)).parse()
def test_parse_broken_dictionary(self): data = {'dictionaries': {}} with self.assertRaises(forms.ValidationError): utils.ManifestJSONExtractor('/fake_path', json.dumps(data)).parse()
def parse(self): return utils.ManifestJSONExtractor('{"site_permissions": ["webmidi"]}').parse()