Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cli_client/python/timesketch_cli_client/commands/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,17 @@ def delete_sketch(ctx: click.Context, force_delete: bool) -> None:
)

for timeline in sketch.list_timelines():
try:
# timeline.description and timeline.status lazy-load from the API.
# If the sketch is already soft-deleted, the timeline endpoint
# returns a 404, which raises a RuntimeError.
timeline_desc = timeline.description
timeline_status = timeline.status
except RuntimeError:
Comment thread
jaegeral marked this conversation as resolved.
Outdated
timeline_desc = "N/A"
timeline_status = "N/A"
click.echo(
f" Timeline: {timeline.id} {timeline.name} {timeline.description} {timeline.status}" # pylint: disable=line-too-long
f" Timeline: {timeline.id} {timeline.name} {timeline_desc} {timeline_status}" # pylint: disable=line-too-long
)

if force_delete:
Expand Down
35 changes: 35 additions & 0 deletions end_to_end_tests/cli_client_e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,41 @@ def test_cli_integration(self):
self.assertions.assertEqual(result.exit_code, 0, f"Failed: {result.output}")
self.assertions.assertEqual(result.output.strip(), "42")

def test_cli_sketch_delete_soft_deleted(self):
"""Tests that a soft-deleted sketch can be deleted via CLI."""
# Create a new sketch to be soft-deleted and then hard-deleted
sketch_name = f"cli_soft_delete_test_{uuid.uuid4().hex}"
sketch = self.api.create_sketch(name=sketch_name)

# We need a timeline to trigger the loop in sketch.py
self.import_timeline("evtx_part.csv", sketch=sketch)

# Soft delete the sketch
sketch.delete(force_delete=False)

# Now try to delete it via CLI (dry-run first, then force)
cli_ctx_obj = E2ECliContextObject(
api_client=self.api,
sketch_instance=sketch,
output_format="text",
)

# Dry-run
result = self.runner.invoke(sketch_group, ["delete"], obj=cli_ctx_obj)
self.assertions.assertEqual(
result.exit_code,
0,
f"CLI command 'sketch delete' (dry-run) failed on soft-deleted sketch.\nOutput:\n{result.output}\nException:\n{result.exception}"
)

# Force-delete
result_force = self.runner.invoke(sketch_group, ["delete", "--force_delete"], obj=cli_ctx_obj)
self.assertions.assertEqual(
result_force.exit_code,
0,
f"CLI command 'sketch delete --force_delete' failed on soft-deleted sketch.\nOutput:\n{result_force.output}\nException:\n{result_force.exception}"
)


# Register the new test class with the test manager
manager.EndToEndTestManager.register_test(CliClientE2ETest)
Loading