Exemplo n.º 1
0
 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.'
Exemplo n.º 2
0
 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.'
Exemplo n.º 3
0
 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.')
Exemplo n.º 4
0
 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"]]
     }
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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."
Exemplo n.º 8
0
 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."}
Exemplo n.º 9
0
 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()