-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: gnupg on encryption error (#117)
* catching gnupg error on file encryption. * added tests for parallel batch enc & dec * Update changelog * bump version v24.47.0 -> v24.47.1 * Ensure dummy key files exist so as not to break all tests * Fix dummy file creation * Alter PGP key file creation --------- Co-authored-by: Adam McDonagh <[email protected]>
- Loading branch information
1 parent
c56accd
commit 7866b04
Showing
14 changed files
with
271 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "opentaskpy" | ||
version = "v24.47.0" | ||
version = "v24.47.1" | ||
authors = [{ name = "Adam McDonagh", email = "[email protected]" }] | ||
license = { text = "GPLv3" } | ||
classifiers = [ | ||
|
@@ -71,7 +71,7 @@ otf-batch-validator = "opentaskpy.cli.batch_validator:main" | |
profile = 'black' | ||
|
||
[tool.bumpver] | ||
current_version = "v24.47.0" | ||
current_version = "v24.47.1" | ||
version_pattern = "vYY.WW.PATCH[-TAG]" | ||
commit_message = "bump version {old_version} -> {new_version}" | ||
commit = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"type": "transfer", | ||
"source": { | ||
"hostname": "172.16.0.22", | ||
"directory": "/home/application/testFiles/dest", | ||
"fileRegex": "file-encrypt1\\.txt.gpg", | ||
"protocol": { "name": "sftp", "credentials": { "username": "application" } } | ||
}, | ||
"destination": [ | ||
{ | ||
"hostname": "172.16.0.21", | ||
"directory": "/home/application/testFiles/dest", | ||
"protocol": { | ||
"name": "sftp", | ||
"credentials": { "username": "application" }, | ||
"supportsPosixRename": false | ||
}, | ||
"encryption": { "decrypt": true, "private_key": "{{ PRIVATE_KEY1 }}" }, | ||
"rename": { | ||
"pattern": "^file-encrypt1\\.txt.gpg$", | ||
"sub": "file-encrypt1-decrypted.txt" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"type": "transfer", | ||
"source": { | ||
"hostname": "172.16.0.22", | ||
"directory": "/home/application/testFiles/dest", | ||
"fileRegex": "file-encrypt2\\.txt.gpg", | ||
"protocol": { "name": "sftp", "credentials": { "username": "application" } } | ||
}, | ||
"destination": [ | ||
{ | ||
"hostname": "172.16.0.21", | ||
"directory": "/home/application/testFiles/dest", | ||
"protocol": { | ||
"name": "sftp", | ||
"credentials": { "username": "application" }, | ||
"supportsPosixRename": false | ||
}, | ||
"encryption": { "decrypt": true, "private_key": "{{ PRIVATE_KEY2 }}" }, | ||
"rename": { | ||
"pattern": "^file-encrypt2\\.txt.gpg$", | ||
"sub": "file-encrypt2-decrypted.txt" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"type": "transfer", | ||
"source": { | ||
"hostname": "172.16.0.21", | ||
"directory": "/home/application/testFiles/src", | ||
"fileRegex": "file-encrypt1\\.txt", | ||
"protocol": { "name": "sftp", "credentials": { "username": "application" } } | ||
}, | ||
"destination": [ | ||
{ | ||
"hostname": "172.16.0.22", | ||
"directory": "/home/application/testFiles/dest", | ||
"protocol": { | ||
"name": "sftp", | ||
"credentials": { "username": "application" } | ||
}, | ||
"encryption": { "encrypt": true, "public_key": "{{ PUBLIC_KEY1 }}" } | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"type": "transfer", | ||
"source": { | ||
"hostname": "172.16.0.21", | ||
"directory": "/home/application/testFiles/src", | ||
"fileRegex": "file-encrypt2\\.txt", | ||
"protocol": { "name": "sftp", "credentials": { "username": "application" } } | ||
}, | ||
"destination": [ | ||
{ | ||
"hostname": "172.16.0.22", | ||
"directory": "/home/application/testFiles/dest", | ||
"protocol": { | ||
"name": "sftp", | ||
"credentials": { "username": "application" } | ||
}, | ||
"encryption": { "encrypt": true, "public_key": "{{ PUBLIC_KEY2 }}" } | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# pylint: skip-file | ||
# ruff: noqa | ||
import os | ||
|
||
from pytest_shell import fs | ||
|
||
import opentaskpy.otflogging | ||
from opentaskpy.config.loader import ConfigLoader | ||
from opentaskpy.taskhandlers import batch, execution, transfer | ||
from tests.file_helper import * # noqa: F403 | ||
from tests.fixtures.pgp import * # noqa: F403, F401 | ||
from tests.fixtures.ssh_clients import * # noqa: F403 | ||
|
||
os.environ["OTF_NO_LOG"] = "1" | ||
os.environ["OTF_LOG_LEVEL"] = "DEBUG" | ||
|
||
parallel_encryption_batch = { | ||
"type": "batch", | ||
"tasks": [ | ||
{"order_id": 1, "task_id": "encrypt-file-1-sftp"}, | ||
{"order_id": 2, "task_id": "encrypt-file-2-sftp"}, | ||
], | ||
} | ||
|
||
parallel_decryption_batch = { | ||
"type": "batch", | ||
"tasks": [ | ||
{"order_id": 1, "task_id": "decrypt-file-1-sftp"}, | ||
{"order_id": 2, "task_id": "decrypt-file-2-sftp"}, | ||
], | ||
} | ||
|
||
|
||
def test_batch_parallel_encryption( | ||
root_dir, env_vars, clear_logs, store_pgp_keys, setup_sftp_keys | ||
): | ||
# Assert one of the keys randomly | ||
assert os.path.exists("/tmp/public_key_1.txt") | ||
|
||
config_loader = ConfigLoader("test/cfg") | ||
|
||
fs.create_files( | ||
[ | ||
{ | ||
f"{root_dir}/testFiles/sftp_1/src/file-encrypt1.txt": { | ||
"content": "hellothere!" | ||
} | ||
}, | ||
{ | ||
f"{root_dir}/testFiles/sftp_1/src/file-encrypt2.txt": { | ||
"content": "hellothere!" | ||
} | ||
}, | ||
] | ||
) | ||
assert os.path.exists(f"{root_dir}/testFiles/sftp_1/src/file-encrypt1.txt") | ||
assert os.path.exists(f"{root_dir}/testFiles/sftp_1/src/file-encrypt2.txt") | ||
|
||
batch_obj = batch.Batch( | ||
None, | ||
f"parallel-encryption-batch", | ||
parallel_encryption_batch, | ||
config_loader, | ||
) | ||
|
||
# Run the batch and expect a true status | ||
assert batch_obj.run() | ||
|
||
assert os.path.exists(f"{root_dir}/testFiles/sftp_2/dest/file-encrypt1.txt.gpg") | ||
assert os.path.exists(f"{root_dir}/testFiles/sftp_2/dest/file-encrypt2.txt.gpg") | ||
|
||
|
||
def test_batch_parallel_decryption( | ||
root_dir, env_vars, clear_logs, store_pgp_keys, setup_sftp_keys | ||
): | ||
# Assert one of the keys randomly | ||
assert os.path.exists("/tmp/private_key_1.txt") | ||
|
||
config_loader = ConfigLoader("test/cfg") | ||
|
||
assert os.path.exists(f"{root_dir}/testFiles/sftp_2/dest/file-encrypt1.txt.gpg") | ||
assert os.path.exists(f"{root_dir}/testFiles/sftp_2/dest/file-encrypt2.txt.gpg") | ||
|
||
batch_obj = batch.Batch( | ||
None, | ||
f"parallel-decryption-batch", | ||
parallel_decryption_batch, | ||
config_loader, | ||
) | ||
|
||
# Run the batch and expect a true status | ||
assert batch_obj.run() | ||
|
||
# Assert files have been decrypted and transferred back to sftp1 | ||
assert os.path.exists( | ||
f"{root_dir}/testFiles/sftp_1/dest/file-encrypt1-decrypted.txt" | ||
) | ||
assert os.path.exists( | ||
f"{root_dir}/testFiles/sftp_1/dest/file-encrypt2-decrypted.txt" | ||
) |