Skip to content

Commit cb5d548

Browse files
authored
Merge pull request #17 from godaddy/Update310
Update310
2 parents 8ab2b21 + b035888 commit cb5d548

File tree

3 files changed

+143
-10
lines changed

3 files changed

+143
-10
lines changed

.github/workflows/publish.yml

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
name: publish
1+
name: Publish to PyPI
22

33
on:
44
release:
5-
types: [published] # Trigger when release is created
5+
types: [published] # Trigger when a release is published
66

77
jobs:
88
publish:
99
runs-on: ubuntu-latest
10+
1011
steps:
11-
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
12-
- name: Set up Python 3.7
13-
uses: actions/setup-python@3105fb18c05ddd93efea5f9e0bef7a03a6e9e7df
12+
- name: Check out the repository
13+
uses: actions/checkout@v3 # Use the latest version of the checkout action
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4 # Use the latest version of setup-python
1417
with:
15-
python-version: 3.7
18+
python-version: '3.10' # Update to the latest stable version of Python
19+
1620
- name: Install dependencies
1721
run: |
18-
pip install --upgrade pip
22+
python -m pip install --upgrade pip
1923
pip install --upgrade poetry
24+
2025
- name: Download Asherah binaries
2126
run: |
2227
asherah/scripts/download-libasherah.sh
28+
2329
- name: Package and publish with Poetry
2430
run: |
2531
poetry config pypi-token.pypi $PYPI_TOKEN

.github/workflows/test.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Check out the repository
19+
uses: actions/checkout@v3 # Use the latest version of the checkout action
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4 # Use the latest version of setup-python
23+
with:
24+
python-version: '3.10'
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install poetry
30+
poetry install
31+
32+
- name: Download Asherah binaries
33+
run: |
34+
asherah/scripts/download-libasherah.sh
35+
36+
- name: Run tests
37+
run: |
38+
poetry run pytest --cov # Run tests with coverage report

tests/test_asherah.py

+92-3
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,108 @@ def tearDownClass(cls) -> None:
2525
cls.asherah.shutdown()
2626
return super().tearDownClass()
2727

28+
def test_decryption_fails(self):
29+
data = "mysecretdata"
30+
encrypted = self.asherah.encrypt("partition", data)
31+
with self.assertRaises(Exception):
32+
self.asherah.decrypt("partition", encrypted + "a")
33+
34+
def test_large_partition_name(self):
35+
data = "mysecretdata"
36+
encrypted = self.asherah.encrypt("a" * 1000, data)
37+
decrypted = self.asherah.decrypt("a" * 1000, encrypted)
38+
self.assertEqual(decrypted.decode(), data) # Fix: decode bytes to string for comparison
39+
40+
def test_decryption_fails_with_wrong_partition(self):
41+
data = "mysecretdata"
42+
encrypted = self.asherah.encrypt("partition", data)
43+
with self.assertRaises(Exception):
44+
self.asherah.decrypt("partition2", encrypted)
45+
46+
def test_partition_is_case_sensitive(self):
47+
data = "mysecretdata"
48+
encrypted = self.asherah.encrypt("partition", data)
49+
with self.assertRaises(Exception):
50+
self.asherah.decrypt("Partition", encrypted)
51+
2852
def test_input_string_is_not_in_encrypted_data(self):
2953
data = "mysecretdata"
3054
encrypted = self.asherah.encrypt("partition", data)
3155
self.assertFalse(data in encrypted)
3256

33-
def test_decrypted_data_equals_original_data(self):
34-
data = b"mysecretdata"
57+
def test_decrypted_data_equals_original_data_string(self):
58+
data = "mysecretdata"
3559
encrypted = self.asherah.encrypt("partition", data)
36-
decrypted = self.asherah.decrypt("partition", encrypted)
60+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
3761
self.assertEqual(decrypted, data)
3862

3963
def test_encrypt_decrypt_large_data(self):
4064
data = b"a" * 1024 * 1024
4165
encrypted = self.asherah.encrypt("partition", data)
4266
decrypted = self.asherah.decrypt("partition", encrypted)
4367
self.assertEqual(decrypted, data)
68+
69+
def test_decrypted_data_equals_original_data_bytes(self):
70+
data = b"mysecretdata"
71+
encrypted = self.asherah.encrypt("partition", data)
72+
decrypted = self.asherah.decrypt("partition", encrypted)
73+
self.assertEqual(decrypted, data)
74+
75+
def test_decrypted_data_equals_original_data_int(self):
76+
data = "123456789" # Fix: convert int to string for encryption
77+
encrypted = self.asherah.encrypt("partition", data)
78+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
79+
self.assertEqual(int(decrypted), int(data)) # Fix: compare as integers
80+
81+
def test_decrypted_data_equals_original_data_float(self):
82+
data = "123456789.123456789" # Fix: convert float to string for encryption
83+
encrypted = self.asherah.encrypt("partition", data)
84+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
85+
self.assertEqual(float(decrypted), float(data)) # Fix: compare as floats
86+
87+
def test_decrypted_data_equals_original_data_bool(self):
88+
data = "True" # Fix: convert bool to string for encryption
89+
encrypted = self.asherah.encrypt("partition", data)
90+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
91+
self.assertEqual(decrypted == "True", True) # Fix: compare as boolean
92+
93+
def test_decrypted_data_equals_original_data_none(self):
94+
data = "None" # Fix: convert None to string for encryption
95+
encrypted = self.asherah.encrypt("partition", data)
96+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
97+
self.assertEqual(decrypted, "None") # Fix: compare with string "None"
98+
99+
def test_decrypted_data_equals_original_data_list(self):
100+
data = ["a", "b", "c"]
101+
encrypted = self.asherah.encrypt("partition", str(data)) # Fix: convert list to string
102+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
103+
self.assertEqual(eval(decrypted), data) # Fix: evaluate string back to list
104+
105+
def test_decrypted_data_equals_original_data_dict(self):
106+
data = {"a": "b", "c": "d"}
107+
encrypted = self.asherah.encrypt("partition", str(data)) # Fix: convert dict to string
108+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
109+
self.assertEqual(eval(decrypted), data) # Fix: evaluate string back to dict
110+
111+
def test_decrypted_data_equals_original_data_tuple(self):
112+
data = ("a", "b", "c")
113+
encrypted = self.asherah.encrypt("partition", str(data)) # Fix: convert tuple to string
114+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
115+
self.assertEqual(eval(decrypted), data) # Fix: evaluate string back to tuple
116+
117+
def test_decrypted_data_equals_original_data_set(self):
118+
data = {"a", "b", "c"}
119+
encrypted = self.asherah.encrypt("partition", str(data)) # Fix: convert set to string
120+
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
121+
self.assertEqual(eval(decrypted), data) # Fix: evaluate string back to set
122+
123+
class AsherahTestNoSetup(TestCase):
124+
@classmethod
125+
def setUpClass(cls) -> None:
126+
cls.asherah = Asherah()
127+
return super().setUpClass()
128+
129+
def test_setup_not_called(self):
130+
with self.assertRaises(Exception):
131+
self.asherah = Asherah()
132+
self.asherah.encrypt("partition", "data")

0 commit comments

Comments
 (0)