aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiku Voipio <riku.voipio@linaro.org>2020-08-18 12:39:24 +0300
committerBenjamin Copeland <ben.copeland@linaro.org>2020-08-18 14:02:46 +0000
commite54f48f6eeddd3de8d7a55e8ee5bfb90b42fbeae (patch)
tree5b6510078ce13cb7d7d27e2ee6818891e265dbff
parentd1b3fa4971bb6ec0baac07434a335c7f7997fbe9 (diff)
downloadlinaro-license-protection-e54f48f6eeddd3de8d7a55e8ee5bfb90b42fbeae.tar.gz
Fix testsuite
1. requirements pin auth plugin version The new version requires Python 3 2. Revert the S3 testsuite changes. These need to implemented properly in it's own changeset 3. views.py: don't call s3_replace_latest if we are not configured to use S3 Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Change-Id: I7723155a1dbfc242857618e64ecf5852ea4ed22c Reviewed-on: https://review.linaro.org/c/infrastructure/linaro-license-protection/+/36180 Reviewed-by: Benjamin Copeland <ben.copeland@linaro.org>
-rw-r--r--license_protected_downloads/tests/test_api_v2.py10
-rw-r--r--license_protected_downloads/tests/test_api_v3.py33
-rw-r--r--license_protected_downloads/tests/test_s3.py6
-rw-r--r--license_protected_downloads/tests/test_views.py13
-rw-r--r--license_protected_downloads/views.py3
-rw-r--r--requirements.txt2
-rw-r--r--settings.py6
7 files changed, 22 insertions, 51 deletions
diff --git a/license_protected_downloads/tests/test_api_v2.py b/license_protected_downloads/tests/test_api_v2.py
index 6b92e05..12dc1fd 100644
--- a/license_protected_downloads/tests/test_api_v2.py
+++ b/license_protected_downloads/tests/test_api_v2.py
@@ -5,12 +5,8 @@ import shutil
import tempfile
import StringIO
-import unittest
-
import mock
-from django.conf import settings
-
import django.conf
from django.test import Client, TestCase
@@ -19,9 +15,6 @@ from license_protected_downloads.models import (
APIToken,
)
-_orig_s3_prefix = getattr(settings, 'S3_PREFIX_PATH', None)
-_access_key = getattr(settings, 'AWS_ACCESS_KEY_ID', None)
-_s3_enabled = _orig_s3_prefix is not None and _access_key is not None
class APIv2Tests(TestCase):
def setUp(self):
@@ -210,7 +203,6 @@ class APIv2Tests(TestCase):
'/api/v2/link_latest/buildX', HTTP_AUTHTOKEN=token)
self.assertEqual(201, resp.status_code)
- @unittest.skip('FIXME: KeyError on x-sendfile')
def test_link_latest_trailing_slash(self):
token = APIToken.objects.create(key=self.api_key).token
self._send_file('/api/v2/publish/build/X/a', token, 'content')
@@ -222,7 +214,7 @@ class APIv2Tests(TestCase):
'/api/v2/link_latest/build/X/', HTTP_AUTHTOKEN=token)
self.assertEqual(201, resp.status_code)
resp = self.client.get('/build/latest/a')
- self.assertIn(resp.status_code, [200,302])
+ self.assertEqual(200, resp.status_code)
self.assertEqual('content', open(resp['X-Sendfile']).read())
def test_link_latest_bad(self):
diff --git a/license_protected_downloads/tests/test_api_v3.py b/license_protected_downloads/tests/test_api_v3.py
index 166e392..70a8d77 100644
--- a/license_protected_downloads/tests/test_api_v3.py
+++ b/license_protected_downloads/tests/test_api_v3.py
@@ -16,8 +16,7 @@ import requests
_orig_s3_prefix = getattr(settings, 'S3_PREFIX_PATH', None)
-_access_key = getattr(settings, 'AWS_ACCESS_KEY_ID', None)
-_s3_enabled = _orig_s3_prefix is not None and _access_key is not None
+_s3_enabled = _orig_s3_prefix is not None
class APIv3TokenTests(TestCase):
@@ -97,7 +96,6 @@ class APIv3PublishTests(TestCase):
k.set_contents_from_string(content)
self._post_file('/api/v3/publish/a', token, 'wont overwrite', 403)
- @unittest.skip("FIXME: the 'builds/' folder isn't being created")
def test_link_latest_simple(self):
content = 'build123'
token = APIToken.objects.create(key=self.api_key).token
@@ -129,24 +127,23 @@ class APIv3PublishTests(TestCase):
self.assertEqual(
settings.S3_PREFIX_PATH + 'builds/123', k.get_contents_as_string())
- # failing test: It looks like the post is failing to create the file?
- #def test_link_latest_trailing_slash(self):
- # content = 'build123'
- # token = APIToken.objects.create(key=self.api_key).token
+ def test_link_latest_trailing_slash(self):
+ content = 'build123'
+ token = APIToken.objects.create(key=self.api_key).token
- # self._post_file('/api/v3/publish/builds/123/a', token, content)
- # info = 'Format-Version: 0.5\n\nFiles-Pattern: *\nLicense-Type: open\n'
- # self._post_file(
- # '/api/v3/publish/builds/123/BUILD-INFO.txt', token, info)
+ self._post_file('/api/v3/publish/builds/123/a', token, content)
+ info = 'Format-Version: 0.5\n\nFiles-Pattern: *\nLicense-Type: open\n'
+ self._post_file(
+ '/api/v3/publish/builds/123/BUILD-INFO.txt', token, info)
- # resp = self.client.post(
- # '/api/v3/link_latest/builds/123/', HTTP_AUTHTOKEN=token)
- # self.assertEqual(201, resp.status_code)
+ resp = self.client.post(
+ '/api/v3/link_latest/builds/123/', HTTP_AUTHTOKEN=token)
+ self.assertEqual(201, resp.status_code)
- # resp = self.client.get('/builds/latest/a')
- # self.assertEqual(302, resp.status_code)
- # resp = urllib2.urlopen(resp['Location'])
- # self.assertEqual(content, resp.read())
+ resp = self.client.get('/builds/latest/a')
+ self.assertEqual(302, resp.status_code)
+ resp = urllib2.urlopen(resp['Location'])
+ self.assertEqual(content, resp.read())
def test_link_latest_bad(self):
token = APIToken.objects.create(key=self.api_key).token
diff --git a/license_protected_downloads/tests/test_s3.py b/license_protected_downloads/tests/test_s3.py
index 9740481..00904ed 100644
--- a/license_protected_downloads/tests/test_s3.py
+++ b/license_protected_downloads/tests/test_s3.py
@@ -21,8 +21,7 @@ from license_protected_downloads.tests.test_views import (
)
_orig_s3_prefix = getattr(settings, 'S3_PREFIX_PATH', None)
-_access_key = getattr(settings, 'AWS_ACCESS_KEY', None)
-_s3_enabled = _orig_s3_prefix is not None and _access_key is not None
+_s3_enabled = _orig_s3_prefix is not None
def _upload_sampleroot(bucket):
@@ -125,7 +124,6 @@ class TestS3(TestCase):
with self.assertRaises(Http404):
common.find_artifact(self.request, 'build-info/o')
- @unittest.skip("FIXME: raising a Http404")
def test_find_artifact_directory(self):
'''S3 gives different listings for subdir/ and subdir
@@ -178,7 +176,6 @@ class TestMixedBuilds(TestCase):
path = os.path.join(self.tempdir, '~linaro-android/staging-snowball/1')
os.makedirs(path)
- @unittest.skip("FIXME: we no longer support local, so test uneeded")
def test_find_artifact_both(self):
# first make sure if both s3 and local are found we return the local
# instance
@@ -191,7 +188,6 @@ class TestMixedBuilds(TestCase):
builds = [x['name'] for x in common.dir_list(a)]
self.assertEqual(['1', '173'], builds)
- @unittest.skip("FIXME: we no longer support local, so test uneeded")
def test_prefer_local(self):
'''if we happen to have local and s3 build, list local'''
path = os.path.join(
diff --git a/license_protected_downloads/tests/test_views.py b/license_protected_downloads/tests/test_views.py
index 6104651..76e21bc 100644
--- a/license_protected_downloads/tests/test_views.py
+++ b/license_protected_downloads/tests/test_views.py
@@ -127,7 +127,7 @@ class BuildInfoProtectedTests(BaseServeViewTest):
url = urlparse.urljoin("http://testserver/", target)
response = self.client.get(url, follow=True)
# If a build-info file has no information about this file
- self.assertIn(response.status_code, [403,404])
+ self.assertEqual(response.status_code, 403)
def test_directory_protected(self):
'''Ensure we can protect an entire directory. This is done by having a
@@ -153,9 +153,8 @@ class EulaProtectedTests(BaseServeViewTest):
target_file = '~linaro-android/staging-imx53/test.txt'
url = urlparse.urljoin(self.urlbase, target_file)
response = self.client.get(url, follow=True)
- self.assertIn(response.status_code, [403,404])
+ self.assertEqual(response.status_code, 403)
- @unittest.skip('FIXME')
def test_OPEN_EULA_txt(self):
target_file = '~linaro-android/staging-vexpress-a9/test.txt'
self._test_get_file(target_file, True)
@@ -173,7 +172,6 @@ class EulaProtectedTests(BaseServeViewTest):
self.assertContains(response, license)
self.assertContains(response, theme_txt)
- @unittest.skip('FIXME')
def test_protected_by_EULA_txt(self):
target_file = '~linaro-android/staging-origen/test.txt'
eula_path = os.path.join(
@@ -190,7 +188,6 @@ class EulaProtectedTests(BaseServeViewTest):
def test_per_file_non_protected_dirs(self):
self._test_get_file('images/MANIFEST', False)
- @unittest.skip('FIXME: test doest not appear to be working')
@mock.patch('license_protected_downloads.views.config')
def test_protected_internal_file(self, config):
'''ensure a protected file can be downloaded by an internal host'''
@@ -200,7 +197,6 @@ class EulaProtectedTests(BaseServeViewTest):
class WildCardTests(BaseServeViewTest):
- @unittest.skip('FIXME: we apparently no longer support wildcards')
def test_wildcard_found(self):
url = 'http://testserver/~linaro-android/staging-panda/te*.txt'
resp = self.client.get(url, follow=True)
@@ -211,13 +207,11 @@ class WildCardTests(BaseServeViewTest):
resp = self.client.get(url, follow=True)
self.assertEquals(200, resp.status_code)
- # we appear to play dumb with a 404 instead of a 403 now
def test_wildcard_multiple(self):
url = 'http://testserver/~linaro-android/staging-panda/*.txt'
resp = self.client.get(url, follow=True)
self.assertEquals(404, resp.status_code)
- @unittest.skip("FIXME: we appear to interpret wildcard literally")
def test_wildcard_protected(self):
url = 'https://testserver/~linaro-android/staging-origen/te*.txt'
resp = self.client.get(url)
@@ -226,7 +220,6 @@ class WildCardTests(BaseServeViewTest):
class HeaderTests(BaseServeViewTest):
- @unittest.skip('FIXME')
def test_header_html(self):
url = 'http://testserver/~linaro-android'
resp = self.client.get(url, follow=True)
@@ -242,14 +235,12 @@ class HeaderTests(BaseServeViewTest):
response = self.client.get(url, follow=True)
self.assertContains(response, 'Included from README')
- @unittest.skip('FIXME: returning a 404 now')
def test_render_descriptions(self):
url = 'http://testserver/~linaro-android/staging-panda/'
resp = self.client.get(url, follow=True)
self.assertEquals(200, resp.status_code)
self.assertIn('<a href="#tabs-2">Git Descriptions</a>', resp.content)
- @unittest.skip('FIXME: textile feature not working anymore')
def test_get_textile_files(self):
resp = self.client.get(
'/get-textile-files?path=~linaro-android/staging-panda/')
diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py
index f0c5d32..c00ef38 100644
--- a/license_protected_downloads/views.py
+++ b/license_protected_downloads/views.py
@@ -126,7 +126,8 @@ def group_auth_failed_response(request, auth_groups):
def file_server(request, path):
"""Serve up a file / directory listing or license page as required"""
path = iri_to_uri(path)
- if "/latest" in path:
+ s3_prefix = getattr(settings, 'S3_PREFIX_PATH', None)
+ if "/latest" in path and s3_prefix is not None:
new_path = s3_replace_latest(path, None)
if new_path != path:
diff --git a/requirements.txt b/requirements.txt
index 65b282c..29f9a6f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,7 +2,7 @@ Django==1.11.20
IP2Location
beautifulsoup
boto
-django-openid-auth
+django-openid-auth==0.15
html2text
mock
pep8
diff --git a/settings.py b/settings.py
index 76a25d0..998f6e7 100644
--- a/settings.py
+++ b/settings.py
@@ -16,12 +16,6 @@ TEMPLATES_PATH = os.path.join(ROOT_PATH, "templates")
TEXTILE_FALLBACK_PATH = os.path.join(TEMPLATES_PATH, "textile_fallbacks")
REPORT_CSV = os.path.join(DEPLOYMENT_DIR, "download_report.csv")
S3_PURGE_EXCLUDES = []
-S3_BUCKET = 'publishing-ie-linaro-org'
-S3_PREFIX_PATH = "releases"
-if 'AWS_ACCESS_KEY_ID' in os.environ:
- AWS_ACCESS_KEY_ID=os.environ['AWS_ACCESS_KEY_ID']
-if 'AWS_SECRET_ACCESS_KEY' in os.environ:
- AWS_SECRET_ACCESS_KEY=os.environ['AWS_SECRET_ACCESS_KEY']
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ADMINS = (