forked from mozilla-releng/balrog
-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_guardian.py
71 lines (60 loc) · 2.46 KB
/
test_guardian.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pytest
from auslib.blobs.guardian import GuardianBlob
@pytest.fixture(scope="session")
def guardianblob():
blob = GuardianBlob()
blob.loadJSON(
"""
{
"name": "Guardian-1.0.0.0",
"product": "Guardian",
"schema_version": 10000,
"version": "1.0.0.0",
"required": true,
"hashFunction": "sha512",
"platforms": {
"WINNT_x86_64": {
"fileUrl": "https://a.com/this/is/1.0.0.0.msi",
"hashValue": "abcdef"
},
"Darwin_x86_64": {
"fileUrl": "https://a.com/this/is/1.0.0.0.dmg",
"hashValue": "ghijkl"
}
}
}
"""
)
return blob
@pytest.mark.parametrize("whitelistedDomains,expected", [({"a.com": ("Guardian",)}, False), ({}, True)])
def testContainsForbiddenDomain(guardianblob, whitelistedDomains, expected):
assert guardianblob.containsForbiddenDomain("Guardian", whitelistedDomains) is expected
@pytest.mark.parametrize(
"version,expected", [("0.5.0.0", True), ("0.8.0.0", True), ("0.99.99.99", True), ("1.0.0.0", False), ("1.0.5.0", False), ("2.0.0.0", False)]
)
def testShouldServeUpdateVariousVersions(guardianblob, version, expected):
updateQuery = {"product": "Guardian", "version": version, "buildTarget": "WINNT_x86_64", "channel": "release"}
assert guardianblob.shouldServeUpdate(updateQuery) is expected
def testShouldServeUpdateMissingBuildTarget(guardianblob):
updateQuery = {"product": "Guardian", "version": "0.5.0.0", "buildTarget": "Linux_x86_64", "channel": "release"}
assert not guardianblob.shouldServeUpdate(updateQuery)
@pytest.mark.parametrize(
"buildTarget,whitelistedDomains,expected",
[
(
"WINNT_x86_64",
{"a.com": ("Guardian",)},
{"required": True, "url": "https://a.com/this/is/1.0.0.0.msi", "version": "1.0.0.0", "hashFunction": "sha512", "hashValue": "abcdef"},
),
(
"Darwin_x86_64",
{"a.com": ("Guardian",)},
{"required": True, "url": "https://a.com/this/is/1.0.0.0.dmg", "version": "1.0.0.0", "hashFunction": "sha512", "hashValue": "ghijkl"},
),
("Linux_x86_64", {"a.com": ("Guardian",)}, {}),
("WINNT_x86_64", {}, {}),
],
)
def testGetResponse(guardianblob, buildTarget, whitelistedDomains, expected):
updateQuery = {"product": "Guardian", "version": "0.5.0.0", "buildTarget": buildTarget, "channel": "release"}
assert guardianblob.getResponse(updateQuery, whitelistedDomains) == expected