Beispiel #1
0
 def test_create_version_no_addon(self):
     creator = SitePermissionVersionCreator(
         user=user_factory(),
         remote_addr='4.8.15.16',
         install_origins=['https://example.com', 'https://foo.com'],
         site_permissions=['midi-sysex', 'webblah'],
     )
     version = creator.create_version()
     assert version
     addon = version.addon
     file_ = version.file
     # Reload to ensure everything was saved in database correctly.
     version.reload()
     addon.reload()
     file_.reload()
     assert version.pk
     assert version.channel == amo.RELEASE_CHANNEL_UNLISTED
     assert version.version == '1.0'
     assert sorted(version.installorigin_set.all().values_list(
         'origin', flat=True)) == [
             'https://example.com',
             'https://foo.com',
         ]
     assert addon.pk
     assert addon.status == amo.STATUS_NULL
     assert addon.type == amo.ADDON_SITE_PERMISSION
     assert list(addon.authors.all()) == [creator.user]
     assert file_.status == amo.STATUS_AWAITING_REVIEW
     assert file_._site_permissions
     assert file_._site_permissions.permissions == ['midi-sysex', 'webblah']
     activity = ActivityLog.objects.for_addons(addon).latest('pk')
     assert activity.user == creator.user
     assert activity.iplog_set.all()[0].ip_address == '4.8.15.16'
Beispiel #2
0
def create_site_permission_version(*, user_pk, remote_addr, install_origins,
                                   site_permissions, **kwargs):
    # Can raise if the user does not exist, but that's ok, we don't want to go
    # any further if that's the case.
    user = UserProfile.objects.filter(deleted=False).get(pk=user_pk)
    generator = SitePermissionVersionCreator(
        user=user,
        remote_addr=remote_addr,
        install_origins=install_origins,
        site_permissions=site_permissions,
    )
    generator.create_version()
Beispiel #3
0
 def test_create_zipfile(self):
     creator = SitePermissionVersionCreator(
         user=None,
         remote_addr=None,
         install_origins=None,
         site_permissions=None,
     )
     file_obj = creator._create_zipfile({'foo': 'bar'})
     assert file_obj.name == 'automatic.xpi'
     assert file_obj.size
     zip_file = zipfile.ZipFile(file_obj)
     assert zip_file.namelist() == ['manifest.json']
     manifest_contents = zipfile.ZipFile(file_obj).read('manifest.json')
     assert manifest_contents == b'{\n  "foo": "bar"\n}'
Beispiel #4
0
 def test_create_version_existing_addon_but_user_is_not_an_author(self):
     creator = SitePermissionVersionCreator(
         user=user_factory(),
         remote_addr='4.8.15.16',
         install_origins=['https://example.com', 'https://foo.com'],
         site_permissions=['midi-sysex', 'webblah'],
     )
     addon = addon_factory(
         version_kw={'version': '1.0'},
         type=amo.ADDON_SITE_PERMISSION,
         users=[user_factory()],
     )
     self.make_addon_unlisted(addon)
     with self.assertRaises(ImproperlyConfigured):
         creator.create_version(addon=addon)
Beispiel #5
0
 def test_create_manifest_multiple_origins_and_permissions(self):
     creator = SitePermissionVersionCreator(
         user=user_factory(),
         remote_addr='4.8.15.16',
         install_origins=['https://example.com', 'https://foo.com'],
         site_permissions=['midi-sysex', 'webblah'],
     )
     manifest_data = creator._create_manifest('2.0')
     assert manifest_data == {
         'browser_specific_settings': {
             'gecko': {
                 'strict_min_version': '97.0'
             }
         },
         'install_origins': ['https://example.com', 'https://foo.com'],
         'manifest_version': 2,
         'name': 'Site permissions for example.com, foo.com',
         'site_permissions': ['midi-sysex', 'webblah'],
         'version': '2.0',
     }
Beispiel #6
0
 def test_create_manifest_with_guid(self):
     creator = SitePermissionVersionCreator(
         user=user_factory(),
         remote_addr='4.8.15.16',
         install_origins=['https://example.com'],
         site_permissions=['midi-sysex'],
     )
     manifest_data = creator._create_manifest('1.0', 'some@guid')
     guid = (
         manifest_data.get('browser_specific_settings', {})
         .get('gecko', {})
         .get('id')
     )
     assert guid == 'some@guid'
     assert manifest_data == {
         'browser_specific_settings': {
             'gecko': {'id': guid, 'strict_min_version': '97.0'}
         },
         'install_origins': ['https://example.com'],
         'manifest_version': 2,
         'name': 'Site permissions for example.com',
         'site_permissions': ['midi-sysex'],
         'version': '1.0',
     }
Beispiel #7
0
    def test_create_version_existing_addon_wrong_origins(self):
        creator = SitePermissionVersionCreator(
            user=user_factory(),
            remote_addr='4.8.15.16',
            install_origins=['https://example.com', 'https://foo.com'],
            site_permissions=['midi-sysex', 'webblah'],
        )
        addon = addon_factory(
            version_kw={'version': '1.0'},
            type=amo.ADDON_SITE_PERMISSION,
            users=[creator.user],
        )
        initial_version = addon.versions.get()
        self.make_addon_unlisted(addon)
        with self.assertRaises(ImproperlyConfigured):
            creator.create_version(addon=addon)

        # Both need to match, not just one.
        initial_version.installorigin_set.create(origin='https://example.com')
        with self.assertRaises(ImproperlyConfigured):
            creator.create_version(addon=addon)