Skip to content

Fixed bug in test_rule() of security_rules.py - #143

Merged
dandye merged 3 commits into
google:mainfrom
sidxparab:bug-fix-tool-test-rule
Aug 30, 2026
Merged

Fixed bug in test_rule() of security_rules.py#143
dandye merged 3 commits into
google:mainfrom
sidxparab:bug-fix-tool-test-rule

Conversation

@sidxparab

Copy link
Copy Markdown
Contributor

Issue:

There exists an bug in the test_rule tool that causes it to fail consistently.

The tool fails because the end_time value passed to the SecOps API is invalid. SecOps doesn't make the recently ingested logs for the 'Test Rule Function'(this can verified via the UI). Hence, the API requires that the end_time be rounded down to the beginning of the current hour. However, the current implementation on line #472 uses the exact current time (datetime.now()), which the API rejects as being later than the allowed maximum.
This results in an error stating that the end_time is greater than expected.

(Attach screenshot of the error below)

Solution:

I suggest replacing the current time calculation logic with the snippet below. This code rounds the end_time down to the start of the current hour, which will satisfy the API's requirement and resolve the error.

        current_time = datetime.now(timezone.utc)
        # Buffer back to the start of the current hour
        end_time = current_time.replace(minute=0, second=0, microsecond=0)  # Rounds down to the start of current hour
        start_time = end_time - timedelta(hours=hours_back)

        logger.info(f'Rule test time range: {start_time} to {end_time} (buffered to start of current hour)')
mcp-bug

@sidxparab
sidxparab requested a review from a team August 13, 2025 13:30
@google-cla

google-cla Bot commented Aug 13, 2025

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mihirvala08 mihirvala08 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Evidence

Tested on Cline (VS Code extension) using following prompt: Can you test SomaEntityOnlyLiveRuleProbeRule detection rule against past logs of 19 hours?

Image

@dandye
dandye force-pushed the bug-fix-tool-test-rule branch from a408fc5 to 3f576d4 Compare August 30, 2026 01:44

@dandye dandye left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @sidxparab for identifying this Chronicle API constraint and contributing the fix.

@dandye
dandye merged commit b66352e into google:main Aug 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants