def test_legacy_bad_install_rdf(self): xpi = LegacyAddonFileFactory(signed=False) xpi.add_file("install.rdf", b"{}") with pytest.raises(ValidationError) as exc: ExtensionFactory(xpi__from_func=xpi.open) assert len(exc.value.error_dict["xpi"]) == 1 assert exc.value.error_dict["xpi"][0].message == 'Legacy addon "install.rdf" is corrupt.'
def test_legacy_bad_install_rdf(self): xpi = LegacyAddonFileFactory(signed=False) xpi.add_file("install.rdf", b"{}") with pytest.raises(ValidationError) as exc: ExtensionFactory(xpi__from_func=xpi.open) assert len(exc.value.error_dict["xpi"]) == 1 assert exc.value.error_dict["xpi"][ 0].message == 'Legacy addon "install.rdf" is corrupt.'
def test_legacy_no_id(self): xpi = LegacyAddonFileFactory(overwrite_data={"id": ""}, signed=False) with pytest.raises(ValidationError) as exc: ExtensionFactory(xpi__from_func=xpi.open) assert len(exc.value.error_dict["xpi"]) == 1 assert (exc.value.error_dict["xpi"][0].message == 'Legacy addons "install.rdf" must specify an id.')
def test_uploads_must_be_signed_legacy(self, api_client, storage): xpi = LegacyAddonFileFactory(signed=False) res = self._upload_extension(api_client, xpi.path) assert res.status_code == 400 # Client error assert res.data == { "xpi": [ExtensionFileField.default_error_messages["not_signed"]] }
def test_can_update_xpi(self, api_client, storage): legacy = LegacyAddonFileFactory() e = ExtensionFactory(xpi__from_func=legacy.open) webext = WebExtensionFileFactory() _, filename = os.path.split(webext.path) res = self._update_extension(api_client, e.id, webext.path) assert res.status_code == 200 e.refresh_from_db() assert e.xpi.name.endswith(filename)
def test_keeps_extension_filename(self, api_client, storage): xpi = LegacyAddonFileFactory() res = self._upload_extension(api_client, xpi.path) assert res.status_code == 201, f"body of unexpected response: {res.data}" # created _, filename = os.path.split(xpi.path) assert res.data["xpi"].split("/")[-1] == url_quote(filename) # Download the XPI to make sure the url is actually good res = api_client.get(res.data["xpi"], follow=True) assert res.status_code == 200
def test_xpi_must_be_signed(self): xpi = WebExtensionFileFactory(signed=False) with pytest.raises(ValidationError) as exc: ExtensionFactory(xpi__from_func=xpi.open) assert len(exc.value.error_dict["xpi"]) == 1 assert exc.value.error_dict["xpi"][ 0].message == "Extension file must be signed." xpi = LegacyAddonFileFactory(signed=False) with pytest.raises(ValidationError) as exc: ExtensionFactory(xpi__from_func=xpi.open) assert len(exc.value.error_dict["xpi"]) == 1 assert exc.value.error_dict["xpi"][ 0].message == "Extension file must be signed."
def test_uploads_must_be_signed_legacy(self, api_client, storage): xpi = LegacyAddonFileFactory(signed=False) res = self._upload_extension(api_client, xpi.path) assert res.status_code == 400 # Client error assert res.data == {"xpi": "Extension file must be signed."}
def test_upload_works_legacy(self, api_client, storage): xpi = LegacyAddonFileFactory() res = self._upload_extension(api_client, xpi.path) assert res.status_code == 201 # created Extension.objects.filter(id=res.data["id"]).exists()