tests/lists: adds some tests for the obfuscator
This commit is contained in:
parent
dbb480a030
commit
7e8e9e1033
2 changed files with 90 additions and 0 deletions
43
tests/list/mirrorSites.json
Normal file
43
tests/list/mirrorSites.json
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"sites": [
|
||||
{
|
||||
"available_alternatives": [
|
||||
{
|
||||
"created_at": "2022-03-09 12:47:07.719556",
|
||||
"proto": "tor",
|
||||
"type": "eotk",
|
||||
"updated_at": "2022-03-09 12:47:07.719557",
|
||||
"url": "https://www.bbcnewsd73hkzno2ini43t4gblxvycyac5aw4gnv7t2rccijh7745uqd.onion"
|
||||
}
|
||||
],
|
||||
"main_domain": "bbc.co.uk"
|
||||
},
|
||||
{
|
||||
"available_alternatives": [
|
||||
{
|
||||
"created_at": "2022-03-09 12:47:07.858737",
|
||||
"proto": "https",
|
||||
"type": "mirror",
|
||||
"updated_at": "2022-03-09 12:47:07.858738",
|
||||
"url": "https://d2d0cl8vuawvuv.cloudfront.net"
|
||||
},
|
||||
{
|
||||
"created_at": "2022-03-09 21:32:30.861795",
|
||||
"proto": "https",
|
||||
"type": "mirror",
|
||||
"updated_at": "2022-03-09 21:32:58.643504",
|
||||
"url": "https://dxd59zfzkaqol.cloudfront.net"
|
||||
},
|
||||
{
|
||||
"created_at": "2022-03-09 21:35:21.639404",
|
||||
"proto": "https",
|
||||
"type": "mirror",
|
||||
"updated_at": "2022-03-09 21:35:31.996308",
|
||||
"url": "https://d12b5t7zh1bhpp.cloudfront.net"
|
||||
}
|
||||
],
|
||||
"main_domain": "guardianproject.info"
|
||||
}
|
||||
],
|
||||
"version": "2.0"
|
||||
}
|
47
tests/list/test_obfuscating_encoder.py
Normal file
47
tests/list/test_obfuscating_encoder.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
import json
|
||||
|
||||
from nose.tools import assert_equal, assert_not_in
|
||||
|
||||
from app.terraform.list import obfuscator
|
||||
|
||||
|
||||
def test_obfuscating_string():
|
||||
data = "hello"
|
||||
obfs = obfuscator(data)
|
||||
print(f"Obfuscated string: {obfs}")
|
||||
j = json.dumps(obfs).replace("!AAA!", "\\u")
|
||||
loaded = json.loads(j)
|
||||
assert_equal(data, loaded)
|
||||
|
||||
|
||||
def test_obfuscating_simple_dict():
|
||||
data = {"hello": "world"}
|
||||
obfs = obfuscator(data)
|
||||
print(f"Obfuscated string: {obfs}")
|
||||
j = json.dumps(obfs).replace("!AAA!", "\\u")
|
||||
assert_not_in("hello", obfs)
|
||||
assert_not_in("world", obfs)
|
||||
loaded = json.loads(j)
|
||||
assert_equal(data, loaded)
|
||||
|
||||
|
||||
def test_obfuscating_simple_list():
|
||||
data = ["hello", "world"]
|
||||
obfs = obfuscator(data)
|
||||
print(f"Obfuscated string: {obfs}")
|
||||
j = json.dumps(obfs).replace("!AAA!", "\\u")
|
||||
assert_not_in("hello", obfs)
|
||||
assert_not_in("world", obfs)
|
||||
loaded = json.loads(j)
|
||||
assert_equal(data, loaded)
|
||||
|
||||
|
||||
def test_obfuscating_for_real():
|
||||
data = json.load(open("tests/list/mirrorSites.json"))
|
||||
obfs = obfuscator(data)
|
||||
j = json.dumps(obfs).replace("!AAA!", "\\u")
|
||||
print(f"Obfuscated string: {obfs}")
|
||||
for a in range(17, 27):
|
||||
assert_not_in(chr(a), j)
|
||||
loaded = json.loads(j)
|
||||
assert_equal(data, loaded)
|
Loading…
Add table
Add a link
Reference in a new issue