This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
8,809 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
[submodule "jetpack/addon-sdk"] | |||
path = jetpack/addon-sdk | |||
url = git://github.com/mozilla/addon-sdk.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1,4 @@ | |||
include validator/testcases/hashes.txt | include validator/testcases/hashes.txt | ||
include validator/app_versions.json | |||
include validator/testcases/jetpack_data.txt | |||
include validator/testcases/whitelist_hashes.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule addon-sdk
added at
5a73e7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
#!/bin/bash | |||
|
|||
rm ../validator/testcases/jetpack_data.txt | |||
|
|||
cd addon-sdk | |||
git pull origin --tags | |||
for tagname in `git tag`; | |||
do | |||
git checkout $tagname | |||
for f in `find . -type f -name "*.js"`; | |||
do | |||
python ../make_hash.py $f $tagname >> ../../validator/testcases/jetpack_data.txt | |||
done | |||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
import hashlib | |||
import os | |||
import sys | |||
|
|||
hash = hashlib.sha256(open(sys.argv[1]).read()).hexdigest() | |||
print sys.argv[1], sys.argv[2], hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,272 @@ | |||
import hashlib | |||
import json | |||
import nose | |||
import validator.testcases.jetpack as jetpack | |||
from validator.errorbundler import ErrorBundle | |||
|
|||
def _do_test(xpi_package): | |||
|
|||
err = ErrorBundle() | |||
jetpack.inspect_jetpack(err, xpi_package) | |||
return err | |||
|
|||
class MockXPI: | |||
|
|||
def __init__(self, resources): | |||
self.resources = resources | |||
|
|||
def read(self, name): | |||
return self.resources[name] | |||
|
|||
def __iter__(self): | |||
for name in self.resources.keys(): | |||
yield name | |||
|
|||
def __contains__(self, name): | |||
return name in self.resources | |||
|
|||
|
|||
def test_not_jetpack(): | |||
"""Test that add-ons which do not match the Jetpack pattern are ignored.""" | |||
|
|||
err = _do_test(MockXPI({"foo": True, "bar": True})) | |||
assert not err.errors | |||
assert not err.warnings | |||
assert not err.notices | |||
assert not err.metadata | |||
|
|||
|
|||
def test_bad_harnessoptions(): | |||
"""Test that a malformed harness-options.json file is warned against.""" | |||
|
|||
err = _do_test(MockXPI({"bootstrap.js": True, | |||
"components/harness.js": True, | |||
"harness-options.json": "foo bar"})) | |||
assert err.failed() | |||
assert err.warnings | |||
print err.warnings | |||
assert err.warnings[0]["id"][-1] == "bad_harness-options.json" | |||
|
|||
|
|||
def test_pass_jetpack(): | |||
"""Test that a minimalistic Jetpack setup will pass.""" | |||
|
|||
harnessoptions = {"sdkVersion": "foo", | |||
"manifest": {}} | |||
|
|||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/bootstrap.js") as bootstrap_file: | |||
bootstrap = bootstrap_file.read() | |||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/components/harness.js") as harness_file: | |||
harness = harness_file.read() | |||
|
|||
err = _do_test(MockXPI({"bootstrap.js": bootstrap, | |||
"components/harness.js": harness, | |||
"harness-options.json": | |||
json.dumps(harnessoptions)})) | |||
assert not err.failed() | |||
assert "is_jetpack" in err.metadata and err.metadata["is_jetpack"] | |||
|
|||
# Test that all files are marked as pretested. | |||
pretested_files = err.get_resource("pretested_files") | |||
assert pretested_files | |||
assert "bootstrap.js" in pretested_files | |||
assert "components/harness.js" in pretested_files | |||
|
|||
|
|||
def test_missing_elements(): | |||
"""Test that missing elements in harness-options will fail.""" | |||
|
|||
harnessoptions = {"sdkVersion": "foo"} | |||
|
|||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/bootstrap.js") as bootstrap_file: | |||
bootstrap = bootstrap_file.read() | |||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/components/harness.js") as harness_file: | |||
harness = harness_file.read() | |||
|
|||
err = _do_test(MockXPI({"bootstrap.js": bootstrap, | |||
"components/harness.js": harness, | |||
"harness-options.json": | |||
json.dumps(harnessoptions)})) | |||
assert err.failed() | |||
|
|||
|
|||
def test_skip_safe_files(): | |||
"""Test that missing elements in harness-options will fail.""" | |||
|
|||
harnessoptions = {"sdkVersion": "foo", | |||
"manifest": {}} | |||
|
|||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/bootstrap.js") as bootstrap_file: | |||
bootstrap = bootstrap_file.read() | |||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/components/harness.js") as harness_file: | |||
harness = harness_file.read() | |||
|
|||
err = _do_test(MockXPI({"bootstrap.js": bootstrap, | |||
"components/harness.js": harness, | |||
"harness-options.json": | |||
json.dumps(harnessoptions), | |||
"foo.png": True, | |||
"bar.JpG": True, | |||
"safe.GIF": True, | |||
"icon.ico": True, | |||
"foo/.DS_Store": True})) | |||
assert not err.failed() | |||
|
|||
|
|||
def test_pass_manifest_elements(): | |||
"""Test that proper elements in harness-options will pass.""" | |||
|
|||
harnessoptions = {"sdkVersion": "foo", | |||
"manifest": | |||
{"resource://bootstrap.js": | |||
{"name": "bootstrap_test", | |||
"hash": | |||
"fc074074112a10a0267beb7c8ac0a6fd4d7d308eb7e3fb50c1db3d3becf5c99b", | |||
"zipname": "bootstrap.js"}}} | |||
|
|||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/bootstrap.js") as bootstrap_file: | |||
bootstrap = bootstrap_file.read() | |||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/components/harness.js") as harness_file: | |||
harness = harness_file.read() | |||
|
|||
err = _do_test(MockXPI({"bootstrap.js": bootstrap, | |||
"components/harness.js": harness, | |||
"harness-options.json": | |||
json.dumps(harnessoptions)})) | |||
print err.print_summary(verbose=True) | |||
assert not err.failed() | |||
assert "jetpack_loaded_modules" in err.metadata | |||
nose.tools.eq_(err.metadata["jetpack_loaded_modules"], | |||
["bootstrap_test"]) | |||
assert "jetpack_identified_files" in err.metadata | |||
assert "bootstrap.js" in err.metadata["jetpack_identified_files"] | |||
|
|||
assert "jetpack_unknown_files" in err.metadata | |||
assert not err.metadata["jetpack_unknown_files"] | |||
|
|||
|
|||
def test_bad_resource(): | |||
"""Test for failure on non-resource:// modules.""" | |||
|
|||
harnessoptions = {"sdkVersion": "foo", | |||
"manifest": | |||
{"bootstrap.js": | |||
{"name": "bootstrap_test", | |||
"hash": | |||
"fc074074112a10a0267beb7c8ac0a6fd4d7d308eb7e3fb50c1db3d3becf5c99b", | |||
"zipname": "bootstrap.js"}}} | |||
|
|||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/bootstrap.js") as bootstrap_file: | |||
bootstrap = bootstrap_file.read() | |||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/components/harness.js") as harness_file: | |||
harness = harness_file.read() | |||
|
|||
err = _do_test(MockXPI({"bootstrap.js": bootstrap, | |||
"components/harness.js": harness, | |||
"harness-options.json": | |||
json.dumps(harnessoptions)})) | |||
print err.print_summary(verbose=True) | |||
assert err.failed() | |||
|
|||
|
|||
def test_missing_manifest_elements(): | |||
"""Test that missing manifest elements in harness-options will fail.""" | |||
|
|||
harnessoptions = {"sdkVersion": "foo", | |||
"manifest": | |||
{"resource://bootstrap.js": | |||
{"name": "bootstrap_test", | |||
"zipname": "bootstrap.js"}}} | |||
|
|||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/bootstrap.js") as bootstrap_file: | |||
bootstrap = bootstrap_file.read() | |||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/components/harness.js") as harness_file: | |||
harness = harness_file.read() | |||
|
|||
err = _do_test(MockXPI({"bootstrap.js": bootstrap, | |||
"components/harness.js": harness, | |||
"harness-options.json": | |||
json.dumps(harnessoptions)})) | |||
print err.print_summary(verbose=True) | |||
assert err.failed() | |||
|
|||
|
|||
def test_mismatched_hash(): | |||
""" | |||
Test that failure occurs when the actual file hash doesn't match the hash | |||
provided by harness-options.js. | |||
""" | |||
|
|||
harnessoptions = {"sdkVersion": "foo", | |||
"manifest": | |||
{"resource://bootstrap.js": | |||
{"name": "bootstrap_test", | |||
"hash": "foobar", | |||
"zipname": "bootstrap.js"}}} | |||
|
|||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/bootstrap.js") as bootstrap_file: | |||
bootstrap = bootstrap_file.read() | |||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/components/harness.js") as harness_file: | |||
harness = harness_file.read() | |||
|
|||
err = _do_test(MockXPI({"bootstrap.js": bootstrap, | |||
"components/harness.js": harness, | |||
"harness-options.json": | |||
json.dumps(harnessoptions)})) | |||
print err.print_summary(verbose=True) | |||
assert err.failed() | |||
|
|||
|
|||
def test_mismatched_db_hash(): | |||
""" | |||
Test that failure occurs when the hash of a file doesn't exist in the | |||
Jetpack known file database. | |||
""" | |||
|
|||
test_file = "This is the content of the test file." | |||
|
|||
harnessoptions = {"sdkVersion": "foo", | |||
"manifest": | |||
{"resource://test.js": | |||
{"name": "test file", | |||
"hash": hashlib.sha256(test_file).hexdigest(), | |||
"zipname": "test.js"}}} | |||
|
|||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/bootstrap.js") as bootstrap_file: | |||
bootstrap = bootstrap_file.read() | |||
with open("jetpack/addon-sdk/python-lib/cuddlefish/" | |||
"app-extension/components/harness.js") as harness_file: | |||
harness = harness_file.read() | |||
|
|||
err = _do_test(MockXPI({"test.js": test_file, | |||
"bootstrap.js": bootstrap, | |||
"components/harness.js": harness, | |||
"harness-options.json": | |||
json.dumps(harnessoptions)})) | |||
print err.print_summary(verbose=True) | |||
assert err.failed() | |||
|
|||
assert "jetpack_loaded_modules" in err.metadata | |||
assert not err.metadata["jetpack_loaded_modules"] | |||
assert "jetpack_identified_files" in err.metadata | |||
|
|||
assert "jetpack_unknown_files" in err.metadata | |||
nose.tools.eq_(err.metadata["jetpack_unknown_files"], | |||
["test.js"]) | |||
|
|||
|
Oops, something went wrong.