Skip to content

fix: resolve CodeQL code-quality findings (with tests) - #23

Merged
ErikMeinders merged 1 commit into
mainfrom
fix/codeql-quality-findings
Jul 21, 2026
Merged

fix: resolve CodeQL code-quality findings (with tests)#23
ErikMeinders merged 1 commit into
mainfrom
fix/codeql-quality-findings

Conversation

@ErikMeinders

Copy link
Copy Markdown
Member

Summary

Resolves the code-quality alerts surfaced by the new CodeQL scan, backed by a test suite since users rely on this tool. Nothing goes to main until CI (pytest on Python 3.10–3.13) is green and this PR is reviewed.

CodeQL findings addressed

# Severity Finding Fix
4 warning Unreachable statement in _create_1password_key Restructured so the SSH-agent reminder actually runs before return True
2, 3 note Bare except: handles BaseException Narrowed to except Exception: so KeyboardInterrupt/SystemExit propagate
5 note Repeated import re Removed the redundant nested import
6–12 note Unused imports Removed (json, check_ssh_agent, success, error, re, format_instance_id, Path)

Alert #1 (high, "clear-text logging of sensitive data") is a false positive — the flagged strings contain the product name 1Password, not a real password. Recommend dismissing it as "false positive" in the Security tab.

Tests added (tests/test_setup.py)

  • _create_1password_key: success path saves the key and shows the reminder. This test fails against the old unreachable-code version (verified locally) and passes against the fix — it genuinely guards the behaviour change.
  • setup_aws_profile: a missing profile is still handled, but KeyboardInterrupt now propagates (verifies the narrowed except).
  • validate_instance_id: valid/invalid regression cases.

16 tests, all passing locally.

CI

New .github/workflows/test.yml runs pytest on Python 3.10–3.13 for pushes and PRs to main/develop.

Notes

  • No functional/user-facing behaviour change except the (previously dead) 1Password reminder now displays as originally intended.
  • pytest added to the dev dependency group.

🤖 Generated with Claude Code

Address code scanning alerts from the security-and-quality suite:

- Remove unused imports (json, check_ssh_agent, success, error in
  setup.py; re, success, format_instance_id in cli.py; Path in core.py
  and _1password.py)
- Remove redundant nested 'import re' in setup.py (already imported at
  module top)
- Fix unreachable statement in _create_1password_key: the SSH-agent
  reminder and its return were dead code after both branches returned;
  restructured so the reminder is shown before returning True
- Replace two bare 'except:' blocks with 'except Exception:' so
  KeyboardInterrupt/SystemExit propagate

Add pytest suite (tests/test_setup.py) covering the behavioural changes:
- _create_1password_key success path now saves the key AND shows the
  reminder (regression test fails against the old unreachable code)
- setup_aws_profile handles a missing profile but lets KeyboardInterrupt
  propagate (verifies the narrowed except)
- validate_instance_id valid/invalid cases

Add .github/workflows/test.yml running pytest on Python 3.10-3.13 for
pushes and PRs, gating merges to main/develop.

The high-severity 'clear-text logging of sensitive data' alert is a
false positive: the flagged strings contain the product name
'1Password', not an actual password.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 21, 2026 18:24
Comment thread tests/test_setup.py

def _install_stubs(self, monkeypatch, setup, *, create_success=True,
save_success=True):
import cloudx_proxy.setup as setup_mod
Comment thread tests/test_setup.py
"""The bare except was narrowed to Exception (issue #2 in CodeQL)."""

def test_missing_profile_is_handled(self, monkeypatch, setup):
import cloudx_proxy.setup as setup_mod
Comment thread tests/test_setup.py
assert isinstance(result, bool)

def test_keyboard_interrupt_propagates(self, monkeypatch, setup):
import cloudx_proxy.setup as setup_mod
@ErikMeinders
ErikMeinders merged commit ed1eb01 into main Jul 21, 2026
11 checks passed
@ErikMeinders
ErikMeinders deleted the fix/codeql-quality-findings branch July 21, 2026 18:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses CodeQL “security-and-quality” findings in the CloudX setup flow (notably exception handling and a previously unreachable 1Password reminder), and adds a pytest-backed regression suite plus CI to ensure the fixes stay covered across Python 3.10–3.13.

Changes:

  • Fixes CodeQL-reported quality issues in CloudXSetup (unreachable reminder code; replace bare except: with except Exception:; remove redundant/unused imports).
  • Adds a focused pytest suite covering the corrected 1Password success path, narrowed exception handling behavior, and instance-id validation.
  • Introduces a GitHub Actions workflow to run pytest on pushes/PRs to main/develop, and wires pytest into the dev dependency group.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cloudx_proxy/setup.py Fixes unreachable reminder logic, narrows exception handling, and removes redundant/unused imports per CodeQL.
cloudx_proxy/cli.py Removes unused imports tied to CodeQL notes.
cloudx_proxy/core.py Removes unused Path import.
cloudx_proxy/_1password.py Removes unused Path import.
tests/test_setup.py Adds regression tests for the touched behaviors (1Password key creation reminder, exception handling, instance-id validation).
tests/__init__.py Establishes tests as a package (empty init).
pyproject.toml Adds pytest to the dev group and configures pytest discovery/options.
uv.lock Locks pytest and its transitive dependencies.
.github/workflows/test.yml Adds CI job to run pytest on Python 3.10–3.13 for pushes/PRs.

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

Comment on lines +27 to +33
- name: Checkout
uses: actions/checkout@v7

- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: ${{ matrix.python-version }}
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