Skip to content
Merged
Changes from all commits
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
28 changes: 14 additions & 14 deletions labs/lab48-cloud-ir-automation/tests/test_cloud_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import hashlib
import json
import uuid
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_isolation_metadata_structure(self):

tags = [
{"Key": "IR_Isolated", "Value": "true"},
{"Key": "IR_IsolationTime", "Value": datetime.utcnow().isoformat()},
{"Key": "IR_IsolationTime", "Value": datetime.now(timezone.utc).isoformat()},
{"Key": "IR_OriginalSGs", "Value": json.dumps(original_sgs)},
{"Key": "IR_IsolationReason", "Value": reason},
]
Expand All @@ -85,7 +85,7 @@ def test_isolation_result_structure(self):
"instance_id": "i-1234567890abcdef0",
"original_security_groups": ["sg-original-123"],
"isolation_sg": "sg-isolation-789",
"timestamp": datetime.utcnow().isoformat(),
"timestamp": datetime.now(timezone.utc).isoformat(),
}

required_fields = [
Expand Down Expand Up @@ -172,15 +172,15 @@ def test_revocation_result_structure(self):
"Removed console access",
"Attached deny-all policy",
],
"timestamp": datetime.utcnow().isoformat(),
"timestamp": datetime.now(timezone.utc).isoformat(),
}

assert result["status"] == "revoked"
assert len(result["actions_taken"]) >= 3

def test_session_invalidation_policy(self):
"""Test session invalidation policy structure."""
current_time = datetime.utcnow().isoformat()
current_time = datetime.now(timezone.utc).isoformat()

invalidation_policy = {
"Version": "2012-10-17",
Expand Down Expand Up @@ -245,7 +245,7 @@ def test_block_result_structure(self):
"Added 1.2.3.4 to WAF block list",
"Added NACL rule 100 to block 1.2.3.4",
],
"timestamp": datetime.utcnow().isoformat(),
"timestamp": datetime.now(timezone.utc).isoformat(),
}

assert result["status"] == "blocked"
Expand All @@ -270,7 +270,7 @@ def test_snapshot_metadata_tags(self):
{"Key": "IR_CaseId", "Value": case_id},
{"Key": "IR_InstanceId", "Value": instance_id},
{"Key": "IR_DeviceName", "Value": device_name},
{"Key": "IR_CreatedAt", "Value": datetime.utcnow().isoformat()},
{"Key": "IR_CreatedAt", "Value": datetime.now(timezone.utc).isoformat()},
{"Key": "IR_Type", "Value": "forensic_evidence"},
]

Expand All @@ -295,7 +295,7 @@ def test_snapshot_result_structure(self):
"device_name": "/dev/sdb",
},
],
"timestamp": datetime.utcnow().isoformat(),
"timestamp": datetime.now(timezone.utc).isoformat(),
}

assert result["status"] == "snapshots_created"
Expand All @@ -316,7 +316,7 @@ def test_cloudtrail_evidence_structure(self):

evidence = {
"case_id": case_id,
"collection_time": datetime.utcnow().isoformat(),
"collection_time": datetime.now(timezone.utc).isoformat(),
"time_range": {
"start": time_range["start"].isoformat(),
"end": time_range["end"].isoformat(),
Expand Down Expand Up @@ -371,7 +371,7 @@ def test_hash_file_structure(self):
"md5": "d41d8cd98f00b204e9800998ecf8427e",
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
},
"hash_time": datetime.utcnow().isoformat(),
"hash_time": datetime.now(timezone.utc).isoformat(),
}

assert hash_record["original_file"] == s3_key
Expand All @@ -384,21 +384,21 @@ def test_chain_of_custody_structure(self):

custody_record = {
"case_id": case_id,
"created_at": datetime.utcnow().isoformat(),
"created_at": datetime.now(timezone.utc).isoformat(),
"created_by": "arn:aws:iam::123456789012:user/investigator",
"evidence_items": [
{
"item_id": str(uuid.uuid4()),
"description": "CloudTrail logs",
"s3_path": "s3://bucket/cases/IR-2024-001/cloudtrail/events.json",
"hashes": {"sha256": "abc123..."},
"collected_at": datetime.utcnow().isoformat(),
"collected_at": datetime.now(timezone.utc).isoformat(),
}
],
"custody_chain": [
{
"action": "created",
"timestamp": datetime.utcnow().isoformat(),
"timestamp": datetime.now(timezone.utc).isoformat(),
"actor": "arn:aws:iam::123456789012:user/investigator",
"notes": "Initial evidence collection",
}
Expand Down Expand Up @@ -691,7 +691,7 @@ def test_rollback_capability(self):
isolation_record = {
"instance_id": "i-123",
"original_security_groups": ["sg-original-1", "sg-original-2"],
"isolation_time": datetime.utcnow().isoformat(),
"isolation_time": datetime.now(timezone.utc).isoformat(),
}

# Rollback would restore original SGs
Expand Down
Loading