-
Notifications
You must be signed in to change notification settings - Fork 75
fix: str_to_isoformat for unformatted datetime #1330
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
Open
0xAlcidius
wants to merge
9
commits into
fox-it:main
Choose a base branch
from
0xAlcidius:fix/isodate_format_xml_py_bugfix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fc55c8a
fix: created str_to_isoformat function to resolve unformatted datetim…
0xAlcidius 8f74dff
Created basic test cases observed in Tasks
0xAlcidius 17e4002
Return datetime object in str_to_isoformat
0xAlcidius 5e4d4ba
Revision of format implementation
0xAlcidius d587f20
Added no leading zero test case
0xAlcidius 3ad9626
Formatted .py files with Ruff
0xAlcidius e392696
Improved code according to review
0xAlcidius 9549bb4
Changed compare output
0xAlcidius b8e1280
formatting
0xAlcidius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| from flow.record import GroupedRecord | ||
|
|
||
| from dissect.target.plugins.os.windows.tasks._plugin import TaskRecord, TasksPlugin | ||
| from dissect.target.plugins.os.windows.tasks.xml import parse_datetime | ||
| from tests._utils import absolute_path | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -265,3 +266,36 @@ def test_xml_task_invalid( | |
| with caplog.at_level(logging.WARNING, target_win.log.name): | ||
| assert len(list(target_win.tasks(group=True))) == 18 | ||
| assert "Invalid task file encountered:" in caplog.text | ||
|
|
||
|
|
||
| def test_xml_task_time() -> None: | ||
| assert parse_datetime("2023-07-05T14:30:00") == datetime(2023, 7, 5, 14, 30, 0, tzinfo=timezone.utc).replace( | ||
|
Member
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. Same for these replace calls. |
||
| tzinfo=None | ||
| ) | ||
|
|
||
|
|
||
| def test_xml_task_time_valid_space() -> None: | ||
| assert parse_datetime("2024-01-01 09:15:00") == datetime(2024, 1, 1, 9, 15, 0, tzinfo=timezone.utc).replace( | ||
| tzinfo=None | ||
| ) | ||
|
|
||
|
|
||
| def test_xml_task_time_empty() -> None: | ||
| assert parse_datetime("") is None | ||
|
|
||
|
|
||
| def test_xml_task_time_invalid() -> None: | ||
| with pytest.raises(ValueError, match=r"(does not match format)"): | ||
| parse_datetime("invalid datetime") | ||
|
|
||
|
|
||
| def test_xml_task_time_utc() -> None: | ||
| assert parse_datetime("2025-07-14T07:15:00Z") == datetime.strptime( | ||
| "2025-07-14 07:15:00+00:00", "%Y-%m-%d %H:%M:%S%z" | ||
| ) | ||
|
|
||
|
|
||
| def test_xml_task_time_no_leading_zero() -> None: | ||
| assert parse_datetime("2023-3-12T11:00:00") == datetime(2023, 3, 12, 11, 0, 0, tzinfo=timezone.utc).replace( | ||
| tzinfo=None | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The two
replace(tzinfo=)calls cancel each other out here.