Permalink
Browse files

don't copy premium addons to the mirrors (bug 679132)

  • Loading branch information...
Andy McKay
Andy McKay committed Aug 25, 2011
1 parent 6867a76 commit fd66f1624967fb06128074ed7af0866fd518308b
Showing with 36 additions and 4 deletions.
  1. +7 −1 apps/files/models.py
  2. +15 −3 apps/files/tests/test_models.py
  3. +8 −0 apps/versions/tests.py
  4. +6 −0 apps/versions/views.py
View
@@ -216,6 +216,8 @@ def file_path(self):
@property
def mirror_file_path(self):
if self.version.addon.is_premium():
return
return os.path.join(settings.MIRROR_STAGE_PATH,
str(self.version.addon_id), self.filename)
@@ -253,7 +255,8 @@ def hide_disabled_file(self):
src, dst = self.file_path, self.guarded_file_path
self.mv(src, dst, 'Moving disabled file: %s => %s')
# Remove the file from the mirrors if necessary.
if os.path.exists(smart_str(self.mirror_file_path)):
if (self.mirror_file_path and
os.path.exists(smart_str(self.mirror_file_path))):
log.info('Unmirroring disabled file: %s'
% self.mirror_file_path)
os.remove(self.mirror_file_path)
@@ -270,6 +273,9 @@ def copy_to_mirror(self):
try:
if os.path.exists(self.file_path):
dst = self.mirror_file_path
if not dst:
return
log.info('Moving file to mirror: %s => %s'
% (self.file_path, dst))
if not os.path.exists(os.path.dirname(dst)):
@@ -190,17 +190,29 @@ def test_generate_filename_ja(self):
f.version.addon = Addon(name=u' フォクすけ といっしょ')
eq_(f.generate_filename(), 'addon-0.1.7-fx.xpi')
def test_copy_to_mirror(self):
f = File.objects.get(id=67442)
if os.path.exists(f.mirror_file_path):
def clean_files(self, f):
if f.mirror_file_path and os.path.exists(f.mirror_file_path):
os.remove(f.mirror_file_path)
if not os.path.exists(os.path.dirname(f.file_path)):
os.mkdir(os.path.dirname(f.file_path))
if not os.path.exists(f.file_path):
open(f.file_path, 'w')
def test_copy_to_mirror(self):
f = File.objects.get(id=67442)
self.clean_files(f)
f.copy_to_mirror()
assert os.path.exists(f.mirror_file_path)
@mock.patch('shutil.copyfile')
def test_not_copy_to_mirror(self, copyfile):
f = File.objects.get(id=67442)
f.version.addon.update(premium_type=amo.ADDON_PREMIUM)
self.clean_files(f)
f.copy_to_mirror()
assert not f.mirror_file_path
assert not copyfile.called
def test_generate_hash(self):
f = File()
f.version = Version.objects.get(pk=81551)
View
@@ -485,6 +485,10 @@ def test_beta_addon_beta_file(self):
self.file.update(status=amo.STATUS_BETA)
self.assert_served_locally(self.client.get(self.file_url))
def test_no_premium(self):
self.addon.update(premium_type=amo.ADDON_PREMIUM)
eq_(self.client.get(self.file_url).status_code, 403)
class TestDownloadsLatest(TestDownloadsBase):
@@ -565,6 +569,10 @@ def test_query_params(self):
eq_(r.status_code, 302)
assert r['Location'].endswith('?src=xxx'), r['Location']
def test_no_premium(self):
self.addon.update(premium_type=amo.ADDON_PREMIUM)
eq_(self.client.get(self.latest_url).status_code, 403)
class TestVersionFromUpload(UploadTest, amo.tests.TestCase):
fixtures = ['base/apps', 'base/addon_3615', 'base/users',
View
@@ -92,6 +92,9 @@ def download_file(request, file_id, type=None):
file = get_object_or_404(File.objects, pk=file_id)
addon = get_object_or_404(Addon.objects, pk=file.version.addon_id)
if addon.is_premium():
return http.HttpResponseForbidden()
if addon.is_disabled or file.status == amo.STATUS_DISABLED:
if acl.check_addon_ownership(request, addon, viewer=True, ignore_disabled=True):
return HttpResponseSendFile(request, file.guarded_file_path,
@@ -110,6 +113,9 @@ def download_file(request, file_id, type=None):
guard = lambda: Addon.objects.filter(_current_version__isnull=False)
@addon_view_factory(guard)
def download_latest(request, addon, type='xpi', platform=None):
if addon.is_premium():
return http.HttpResponseForbidden()
platforms = [amo.PLATFORM_ALL.id]
if platform is not None and int(platform) in amo.PLATFORMS:
platforms.append(int(platform))

0 comments on commit fd66f16

Please sign in to comment.