Skip to content

rust-guard: replace magic integrity strings with constants; add security-tool label tests#6470

Merged
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-replace-magic-strings
May 25, 2026
Merged

rust-guard: replace magic integrity strings with constants; add security-tool label tests#6470
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-replace-magic-strings

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 25, 2026

Two helper functions in helpers.rs used raw string literals "none" and "approved" as fallback defaults while every other reference in the codebase uses policy_integrity::NONE / policy_integrity::APPROVED. Additionally, the security-sensitive arms of apply_tool_labels (secret scanning, code scanning, Dependabot, job logs) lacked unit tests to enforce their always-private invariant.

Changes

labels/helpers.rs — eliminate magic strings

  • effective_disapproval_integrity: "none"super::constants::policy_integrity::NONE
  • effective_endorser_min_integrity: "approved"super::constants::policy_integrity::APPROVED
// Before
fn effective_disapproval_integrity<'a>(ctx: &'a PolicyContext) -> &'a str {
    let v = ctx.disapproval_integrity.trim();
    if v.is_empty() { "none" } else { v }
}

// After
fn effective_disapproval_integrity<'a>(ctx: &'a PolicyContext) -> &'a str {
    let v = ctx.disapproval_integrity.trim();
    if v.is_empty() { super::constants::policy_integrity::NONE } else { v }
}

labels/tool_rules.rs — security-tool label tests

Three new tests added to the #[cfg(test)] block, guarding against regressions where a refactor could silently apply visibility-inherited secrecy to these tools (leaking data on public repos):

Test Tools covered
apply_tool_labels_secret_scanning_is_always_private list_secret_scanning_alerts, get_secret_scanning_alert
apply_tool_labels_code_scanning_and_dependabot_are_always_private list_code_scanning_alerts, get_code_scanning_alert, list_dependabot_alerts, get_dependabot_alert
apply_tool_labels_get_job_logs_is_always_private get_job_logs

Each test asserts that secrecy contains a private: label and integrity contains an approved: label, regardless of repo visibility.

Copilot AI changed the title [WIP] Replace magic integrity strings with constants in Rust Guard rust-guard: replace magic integrity strings with constants; add security-tool label tests May 25, 2026
Copilot AI requested a review from lpcox May 25, 2026 14:20
Copilot finished work on behalf of lpcox May 25, 2026 14:20
@lpcox lpcox marked this pull request as ready for review May 25, 2026 14:24
Copilot AI review requested due to automatic review settings May 25, 2026 14:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens the Rust GitHub guard’s labeling consistency and strengthens regression protection for security-sensitive tools by removing hard-coded integrity tokens and adding unit tests that enforce always-private secrecy for security tooling outputs.

Changes:

  • Replace fallback magic strings in labels/helpers.rs with canonical policy_integrity::{NONE,APPROVED} constants.
  • Add unit tests in labels/tool_rules.rs ensuring secret scanning, code scanning, Dependabot alerts, and job logs always receive private secrecy and approved integrity labels.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/helpers.rs Replaces "none" / "approved" fallbacks with canonical integrity constants to avoid drift/typos.
guards/github-guard/rust-guard/src/labels/tool_rules.rs Adds tests enforcing always-private secrecy + approved integrity for security-tool endpoints.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@lpcox lpcox merged commit 1695cf7 into main May 25, 2026
27 checks passed
@lpcox lpcox deleted the copilot/rust-guard-replace-magic-strings branch May 25, 2026 14:28
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.

[rust-guard] Rust Guard: Replace magic integrity strings with constants + add security-tool label tests

3 participants