test: simplify list obfuscator tests
This commit is contained in:
parent
a406a7974b
commit
5275a2a882
2 changed files with 44 additions and 76 deletions
|
@ -1,43 +1,29 @@
|
||||||
{
|
{
|
||||||
"sites": [
|
"sites": [
|
||||||
{
|
{
|
||||||
"available_alternatives": [
|
"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": "2023-05-08T00:10:19.318707+00:00",
|
||||||
{
|
"proto": "https",
|
||||||
"created_at": "2022-03-09 12:47:07.858737",
|
"type": "mirror",
|
||||||
"proto": "https",
|
"updated_at": "2023-05-08T00:10:19.318717+00:00",
|
||||||
"type": "mirror",
|
"url": "https://d29jgqlyx17mle.cloudfront.net"
|
||||||
"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"
|
"main_domain": "guardianproject.info"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"available_alternatives": [
|
||||||
|
{
|
||||||
|
"created_at": "2024-11-07T16:39:55.674935+00:00",
|
||||||
|
"proto": "https",
|
||||||
|
"type": "mirror",
|
||||||
|
"updated_at": "2023-06-26T18:22:48.012677+00:00",
|
||||||
|
"url": "https://d3mqck17ieiv70.cloudfront.net"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"main_domain": "bbc.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": "2.0"
|
||||||
}
|
}
|
|
@ -1,44 +1,26 @@
|
||||||
import json
|
import json
|
||||||
import unittest
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from app.terraform.list import obfuscator
|
from app.terraform.list import obfuscator
|
||||||
|
|
||||||
|
|
||||||
class TestObfuscatingEncoder(unittest.TestCase):
|
@pytest.mark.parametrize("input_", ["hello", {"hello": "world"}, ["hello", "world"]])
|
||||||
def test_obfuscating_string(self):
|
def test_obfuscator_simple(input_):
|
||||||
data = "hello"
|
obfuscated = obfuscator(input_)
|
||||||
obfs = obfuscator(data)
|
output = json.dumps(obfuscated)
|
||||||
print(f"Obfuscated string: {obfs}")
|
loaded = json.loads(output.replace("!AAA!", "\\u"))
|
||||||
j = json.dumps(obfs).replace("!AAA!", "\\u")
|
assert loaded == input_
|
||||||
loaded = json.loads(j)
|
|
||||||
self.assertEqual(data, loaded)
|
|
||||||
|
|
||||||
def test_obfuscating_simple_dict(self):
|
|
||||||
data = {"hello": "world"}
|
|
||||||
obfs = obfuscator(data)
|
|
||||||
print(f"Obfuscated string: {obfs}")
|
|
||||||
j = json.dumps(obfs).replace("!AAA!", "\\u")
|
|
||||||
self.assertNotIn("hello", obfs)
|
|
||||||
self.assertNotIn("world", obfs)
|
|
||||||
loaded = json.loads(j)
|
|
||||||
self.assertEqual(data, loaded)
|
|
||||||
|
|
||||||
def test_obfuscating_simple_list(self):
|
def test_obfuscator_for_real():
|
||||||
data = ["hello", "world"]
|
input_ = json.load(open("tests/list/mirrorSites.json"))
|
||||||
obfs = obfuscator(data)
|
obfuscated = obfuscator(input_)
|
||||||
print(f"Obfuscated string: {obfs}")
|
output = json.dumps(obfuscated)
|
||||||
j = json.dumps(obfs).replace("!AAA!", "\\u")
|
allowed_characters = ["!", "A", ",", " ", "{", "}", "[", "]", ":", '"', chr(13)]
|
||||||
self.assertNotIn("hello", obfs)
|
allowed_characters.extend([chr(x) for x in range(ord("0"), ord("9") + 1)])
|
||||||
self.assertNotIn("world", obfs)
|
allowed_characters.extend([chr(x) for x in range(ord("a"), ord("f") + 1)])
|
||||||
loaded = json.loads(j)
|
for c in output:
|
||||||
self.assertEqual(data, loaded)
|
assert c in allowed_characters
|
||||||
|
loaded = json.loads(output.replace("!AAA!", "\\u"))
|
||||||
def test_obfuscating_for_real(self):
|
assert loaded == input_
|
||||||
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):
|
|
||||||
self.assertNotIn(chr(a), j)
|
|
||||||
loaded = json.loads(j)
|
|
||||||
self.assertEqual(data, loaded)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue