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": [
|
||||
{
|
||||
"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"
|
||||
},
|
||||
"sites": [
|
||||
{
|
||||
"available_alternatives": [
|
||||
{
|
||||
"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"
|
||||
"created_at": "2023-05-08T00:10:19.318707+00:00",
|
||||
"proto": "https",
|
||||
"type": "mirror",
|
||||
"updated_at": "2023-05-08T00:10:19.318717+00:00",
|
||||
"url": "https://d29jgqlyx17mle.cloudfront.net"
|
||||
}
|
||||
],
|
||||
"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 unittest
|
||||
|
||||
import pytest
|
||||
|
||||
from app.terraform.list import obfuscator
|
||||
|
||||
|
||||
class TestObfuscatingEncoder(unittest.TestCase):
|
||||
def test_obfuscating_string(self):
|
||||
data = "hello"
|
||||
obfs = obfuscator(data)
|
||||
print(f"Obfuscated string: {obfs}")
|
||||
j = json.dumps(obfs).replace("!AAA!", "\\u")
|
||||
loaded = json.loads(j)
|
||||
self.assertEqual(data, loaded)
|
||||
@pytest.mark.parametrize("input_", ["hello", {"hello": "world"}, ["hello", "world"]])
|
||||
def test_obfuscator_simple(input_):
|
||||
obfuscated = obfuscator(input_)
|
||||
output = json.dumps(obfuscated)
|
||||
loaded = json.loads(output.replace("!AAA!", "\\u"))
|
||||
assert loaded == input_
|
||||
|
||||
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):
|
||||
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_for_real(self):
|
||||
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)
|
||||
def test_obfuscator_for_real():
|
||||
input_ = json.load(open("tests/list/mirrorSites.json"))
|
||||
obfuscated = obfuscator(input_)
|
||||
output = json.dumps(obfuscated)
|
||||
allowed_characters = ["!", "A", ",", " ", "{", "}", "[", "]", ":", '"', chr(13)]
|
||||
allowed_characters.extend([chr(x) for x in range(ord("0"), ord("9") + 1)])
|
||||
allowed_characters.extend([chr(x) for x in range(ord("a"), ord("f") + 1)])
|
||||
for c in output:
|
||||
assert c in allowed_characters
|
||||
loaded = json.loads(output.replace("!AAA!", "\\u"))
|
||||
assert loaded == input_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue