aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2015-07-09 12:21:32 -0500
committerAndy Doan <andy.doan@linaro.org>2015-07-09 12:53:52 -0500
commit01b549354bd43f03ee5bf05cf44c2d7a6200baaa (patch)
tree980376e1b065ddbfff577ac57d1439428d0ae2e7
parent9ddc69c5865d135b58206ab95053c299d426316e (diff)
downloadlinaro-license-protection-01b549354bd43f03ee5bf05cf44c2d7a6200baaa.tar.gz
fix bug in build-info uncovered by 8f2768d
Commit 8f2768d changed the way the search_path and filename were passed to the build-info code. Rather than relying on os.path calls, it tries to be generic and infer from the url of the request. The problem is that we now can pass a search path like: foo//panda.txt All our unit-tests have build-info patterns like *panda* and thus the "foo//panda.txt" was okay because of the leading *. However, in production people may use build-info's like panda* which no longer match. In one sense its a bug in 8f2768d, but really the root problem is that the logic of BuildInfo.getInfoForFile was wrong. It was trying to do fnmatch'ing based on full paths. However, build-info's are always for a single directory, so its not needed and makes things more complex. So the "fix" in this commit is really just the change to use: if fnmatch.fnmatch(self.fname, key): To ensure we have test coverage, I updated the build-info/BUILD-INFO.txt files so our unit-tests will fail w/o this fix. Specifically: license_protected_downloads.tests.test_views.ViewTests.test_unprotected_BUILD_INFO Additionally, I further simplified the getInfoForFile method by removing the block: if self.full_file_name == self.search_path: This was a specialized case that is already handled by the fnmatch test. To ensure this assumption I added a "raise RuntimeError" to the block and saw the BuildInfoFileTests.test_apply_to_dir_auth_groups_field test fail. Removing the block plus my "raise" hack got the tests working. Change-Id: Ic4dcd1f99df2df20703198dec8ca06808c20f5cf
-rw-r--r--license_protected_downloads/buildinfo.py12
-rw-r--r--license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt2
-rw-r--r--sampleroot/build-info/BUILD-INFO.txt2
3 files changed, 3 insertions, 13 deletions
diff --git a/license_protected_downloads/buildinfo.py b/license_protected_downloads/buildinfo.py
index 8d423a3..42a789b 100644
--- a/license_protected_downloads/buildinfo.py
+++ b/license_protected_downloads/buildinfo.py
@@ -126,19 +126,9 @@ class BuildInfoBase(object):
# File name matches a key directly - don't need to iterate
# through each using fnmatch to implement globs.
return block[self.fname]
-
- if self.full_file_name == self.search_path:
- # Searching for directory match. This will only match the "*"
- # glob.
- if '*' in block:
- return block['*']
- else:
- return [{}]
-
for key in block:
if key != 'format-version':
- if fnmatch.fnmatch(self.full_file_name,
- os.path.join(self.search_path, key)):
+ if fnmatch.fnmatch(self.fname, key):
return block[key]
return [{}]
diff --git a/license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt b/license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt
index b75bfd8..6902d23 100644
--- a/license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt
+++ b/license_protected_downloads/tests/testserver_root/build-info/BUILD-INFO.txt
@@ -34,7 +34,7 @@ Theme: linaro
License-Type: protected
License-Text: License
-Files-Pattern: *panda*
+Files-Pattern: panda*
Build-Name: landing-panda
License-Type: open
diff --git a/sampleroot/build-info/BUILD-INFO.txt b/sampleroot/build-info/BUILD-INFO.txt
index 9922fa8..af9ca65 100644
--- a/sampleroot/build-info/BUILD-INFO.txt
+++ b/sampleroot/build-info/BUILD-INFO.txt
@@ -28,7 +28,7 @@ License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p
OTHERWISE USE THE SOFTWARE.
</p>
-Files-Pattern: *panda*
+Files-Pattern: panda*
Build-Name: landing-panda
License-Type: open