Skip to content

Commit

Permalink
Merge pull request #17 from godaddy/Update310
Browse files Browse the repository at this point in the history
Update310
  • Loading branch information
jgowdy authored Aug 12, 2024
2 parents 8ab2b21 + b035888 commit cb5d548
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 10 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
name: publish
name: Publish to PyPI

on:
release:
types: [published] # Trigger when release is created
types: [published] # Trigger when a release is published

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
- name: Set up Python 3.7
uses: actions/setup-python@3105fb18c05ddd93efea5f9e0bef7a03a6e9e7df
- name: Check out the repository
uses: actions/checkout@v3 # Use the latest version of the checkout action

- name: Set up Python
uses: actions/setup-python@v4 # Use the latest version of setup-python
with:
python-version: 3.7
python-version: '3.10' # Update to the latest stable version of Python

- name: Install dependencies
run: |
pip install --upgrade pip
python -m pip install --upgrade pip
pip install --upgrade poetry
- name: Download Asherah binaries
run: |
asherah/scripts/download-libasherah.sh
- name: Package and publish with Poetry
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v3 # Use the latest version of the checkout action

- name: Set up Python
uses: actions/setup-python@v4 # Use the latest version of setup-python
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Download Asherah binaries
run: |
asherah/scripts/download-libasherah.sh
- name: Run tests
run: |
poetry run pytest --cov # Run tests with coverage report
95 changes: 92 additions & 3 deletions tests/test_asherah.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,108 @@ def tearDownClass(cls) -> None:
cls.asherah.shutdown()
return super().tearDownClass()

def test_decryption_fails(self):
data = "mysecretdata"
encrypted = self.asherah.encrypt("partition", data)
with self.assertRaises(Exception):
self.asherah.decrypt("partition", encrypted + "a")

def test_large_partition_name(self):
data = "mysecretdata"
encrypted = self.asherah.encrypt("a" * 1000, data)
decrypted = self.asherah.decrypt("a" * 1000, encrypted)
self.assertEqual(decrypted.decode(), data) # Fix: decode bytes to string for comparison

def test_decryption_fails_with_wrong_partition(self):
data = "mysecretdata"
encrypted = self.asherah.encrypt("partition", data)
with self.assertRaises(Exception):
self.asherah.decrypt("partition2", encrypted)

def test_partition_is_case_sensitive(self):
data = "mysecretdata"
encrypted = self.asherah.encrypt("partition", data)
with self.assertRaises(Exception):
self.asherah.decrypt("Partition", encrypted)

def test_input_string_is_not_in_encrypted_data(self):
data = "mysecretdata"
encrypted = self.asherah.encrypt("partition", data)
self.assertFalse(data in encrypted)

def test_decrypted_data_equals_original_data(self):
data = b"mysecretdata"
def test_decrypted_data_equals_original_data_string(self):
data = "mysecretdata"
encrypted = self.asherah.encrypt("partition", data)
decrypted = self.asherah.decrypt("partition", encrypted)
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(decrypted, data)

def test_encrypt_decrypt_large_data(self):
data = b"a" * 1024 * 1024
encrypted = self.asherah.encrypt("partition", data)
decrypted = self.asherah.decrypt("partition", encrypted)
self.assertEqual(decrypted, data)

def test_decrypted_data_equals_original_data_bytes(self):
data = b"mysecretdata"
encrypted = self.asherah.encrypt("partition", data)
decrypted = self.asherah.decrypt("partition", encrypted)
self.assertEqual(decrypted, data)

def test_decrypted_data_equals_original_data_int(self):
data = "123456789" # Fix: convert int to string for encryption
encrypted = self.asherah.encrypt("partition", data)
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(int(decrypted), int(data)) # Fix: compare as integers

def test_decrypted_data_equals_original_data_float(self):
data = "123456789.123456789" # Fix: convert float to string for encryption
encrypted = self.asherah.encrypt("partition", data)
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(float(decrypted), float(data)) # Fix: compare as floats

def test_decrypted_data_equals_original_data_bool(self):
data = "True" # Fix: convert bool to string for encryption
encrypted = self.asherah.encrypt("partition", data)
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(decrypted == "True", True) # Fix: compare as boolean

def test_decrypted_data_equals_original_data_none(self):
data = "None" # Fix: convert None to string for encryption
encrypted = self.asherah.encrypt("partition", data)
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(decrypted, "None") # Fix: compare with string "None"

def test_decrypted_data_equals_original_data_list(self):
data = ["a", "b", "c"]
encrypted = self.asherah.encrypt("partition", str(data)) # Fix: convert list to string
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(eval(decrypted), data) # Fix: evaluate string back to list

def test_decrypted_data_equals_original_data_dict(self):
data = {"a": "b", "c": "d"}
encrypted = self.asherah.encrypt("partition", str(data)) # Fix: convert dict to string
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(eval(decrypted), data) # Fix: evaluate string back to dict

def test_decrypted_data_equals_original_data_tuple(self):
data = ("a", "b", "c")
encrypted = self.asherah.encrypt("partition", str(data)) # Fix: convert tuple to string
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(eval(decrypted), data) # Fix: evaluate string back to tuple

def test_decrypted_data_equals_original_data_set(self):
data = {"a", "b", "c"}
encrypted = self.asherah.encrypt("partition", str(data)) # Fix: convert set to string
decrypted = self.asherah.decrypt("partition", encrypted).decode() # Fix: decode bytes to string
self.assertEqual(eval(decrypted), data) # Fix: evaluate string back to set

class AsherahTestNoSetup(TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.asherah = Asherah()
return super().setUpClass()

def test_setup_not_called(self):
with self.assertRaises(Exception):
self.asherah = Asherah()
self.asherah.encrypt("partition", "data")

0 comments on commit cb5d548

Please sign in to comment.