Skip to content

test(ssh): cover FindPrivateKeys edge cases - #1025

Merged
skevetter merged 3 commits into
mainfrom
pkg-ssh-git/find-private-keys-tests
Aug 18, 2026
Merged

test(ssh): cover FindPrivateKeys edge cases#1025
skevetter merged 3 commits into
mainfrom
pkg-ssh-git/find-private-keys-tests

Conversation

@devsy-app

@devsy-app devsy-app Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

pkg/ssh: cover FindPrivateKeys edge cases

Package reviewed

pkg/ssh (SSH/git/credentials category)

Issue found

FindPrivateKeys (in pkg/ssh/ssh_add.go) had no test coverage. It reads the
user's ~/.ssh directory, parses each entry as a private key, and returns the paths
that parse successfully. Its real edge cases were unverified:

  • a missing .ssh directory surfaces a read error,
  • non-key files (.pub, config) and subdirectories must be skipped,
  • an empty .ssh directory yields no keys (no error).

Change

Add pkg/ssh/ssh_add_test.go with three table-style tests exercising those paths:

  • TestFindPrivateKeys_MissingSSHDirReturnsError~/.ssh absent → error.
  • TestFindPrivateKeys_ReturnsOnlyValidPrivateKeys — a generated RSA private key is
    returned, while an adjacent .pub, config file, and subdirectory are skipped.
    Uses a real generated key (rsa.GenerateKey) — no mocks.
  • TestFindPrivateKeys_EmptySSHDirReturnsNoKeys — empty .ssh → no keys, no error.

No behavioral change to production code.

Verification performed

  • task cli:format — clean.
  • task cli:lint:ci0 issues (new-from-patch against origin/main).
  • task cli:test — passes. The only failing package is pkg/git
    (TestRepoClone*), the known pre-existing failure on origin/main, unrelated to
    this change (which touches only pkg/ssh).
  • Focused run: go test ./pkg/ssh/ -run TestFindPrivateKeys -v — all 3 pass.

This PR was created by an AI agent as part of an automated daily package review job.

# pkg/ssh: cover FindPrivateKeys edge cases

## Package reviewed
`pkg/ssh` (SSH/git/credentials category)

## Issue found
`FindPrivateKeys` (in `pkg/ssh/ssh_add.go`) had **no test coverage**. It reads the
user's `~/.ssh` directory, parses each entry as a private key, and returns the paths
that parse successfully. Its real edge cases were unverified:

- a missing `.ssh` directory surfaces a read error,
- non-key files (`.pub`, `config`) and subdirectories must be skipped,
- an empty `.ssh` directory yields no keys (no error).

## Change
Add `pkg/ssh/ssh_add_test.go` with three table-style tests exercising those paths:

- `TestFindPrivateKeys_MissingSSHDirReturnsError` — `~/.ssh` absent → error.
- `TestFindPrivateKeys_ReturnsOnlyValidPrivateKeys` — a generated RSA private key is
  returned, while an adjacent `.pub`, `config` file, and subdirectory are skipped.
  Uses a real generated key (`rsa.GenerateKey`) — no mocks.
- `TestFindPrivateKeys_EmptySSHDirReturnsNoKeys` — empty `.ssh` → no keys, no error.

No behavioral change to production code.

## Verification performed
- `task cli:format` — clean.
- `task cli:lint:ci` — **0 issues** (new-from-patch against origin/main).
- `task cli:test` — passes. The only failing package is `pkg/git`
  (`TestRepoClone*`), the known pre-existing failure on origin/main, unrelated to
  this change (which touches only `pkg/ssh`).
- Focused run: `go test ./pkg/ssh/ -run TestFindPrivateKeys -v` — all 3 pass.

This PR was created by an AI agent as part of an automated daily package review job.
@netlify

netlify Bot commented Aug 13, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev ready!

Name Link
🔨 Latest commit 2838f05
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6a83db3e4ecff00008c0e99f
😎 Deploy Preview https://deploy-preview-1025--devsydev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 13, 2026

Copy link
Copy Markdown

Deploy Preview for images-devsy-sh ready!

Name Link
🔨 Latest commit 2838f05
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6a83db3e4f658b000804e8c8
😎 Deploy Preview https://deploy-preview-1025--images-devsy-sh.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

AI Reviewer: run a review on demand. To trigger the first review automatically, go to your organization or repository integration settings. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

Use 0o600 for the public key and config fixture files so gosec G306 (Expect WriteFile permissions to be 0600 or less) passes. The files are throwaway fixtures under a temp .ssh dir, so the stricter mode does not change test behavior.

This commit was created by an AI agent (OpenHands) on behalf of the user.
@skevetter
skevetter marked this pull request as ready for review August 18, 2026 04:10
@mergify

mergify Bot commented Aug 18, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@skevetter
skevetter merged commit fdd98ed into main Aug 18, 2026
135 of 137 checks passed
@skevetter
skevetter deleted the pkg-ssh-git/find-private-keys-tests branch August 18, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant