-
Notifications
You must be signed in to change notification settings - Fork 0
fix(task_database): Use stable SHA1 hash for task ID generation #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import unittest | ||
| import json | ||
|
Check warning on line 2 in tests/test_task_database.py
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Style Guide ReferencesFootnotes
|
||
| from task_database import TaskDatabase | ||
|
|
||
| class TestTaskDatabase(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.db = TaskDatabase(db_path=":memory:") | ||
|
|
||
| def test_normalise_task_generates_stable_id(self): | ||
| """ | ||
| Verify that _normalise_task generates a predictable, stable SHA1 hash | ||
| for a task payload that does not have an explicit ID. | ||
| """ | ||
| payload = { | ||
| "name": "Test Task", | ||
| "description": "A description for the test task.", | ||
| "status": "pending" | ||
| } | ||
| # The expected ID is the SHA1 hash of the sorted JSON payload. | ||
| # This has been corrected to match the actual output of hashlib.sha1. | ||
| expected_id = "a5b0c8d49a4c19a78200530eccd3caf4f859e5b5" | ||
|
|
||
| normalized_task = self.db._normalise_task(payload, "2023-10-27T10:00:00Z") | ||
|
|
||
| self.assertEqual(normalized_task["task_id"], expected_id) | ||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While SHA1 is sufficient for generating a unique ID in this context, it is considered a legacy algorithm with known theoretical weaknesses. For better future-proofing and to align with current cryptographic best practices, consider using a more modern hash function from the SHA-2 family, such as SHA-256. This change would also require updating the expected hash value in the corresponding test.