Skip to content

πŸ§ͺ test(hub): cover the lite-enrollment GitHub auth path β€” verifyGitHubRepoAccess and discoverLiteInstallation - #4948

Merged
clubanderson merged 1 commit into
v4from
quality/test-lite-enrollment-auth
Aug 28, 2026
Merged

πŸ§ͺ test(hub): cover the lite-enrollment GitHub auth path β€” verifyGitHubRepoAccess and discoverLiteInstallation#4948
clubanderson merged 1 commit into
v4from
quality/test-lite-enrollment-auth

Conversation

@kubestellar-hive

Copy link
Copy Markdown
Contributor

What this covers

Files/functions claimed: src/pkg/hub/lite_enrollment.go β€” verifyGitHubRepoAccess, discoverLiteInstallation, validateLiteGitHubHost, liteRepoAccessHTTPClient β€” via new test file src/pkg/hub/lite_enrollment_authcheck_test.go. Test-only; no production code changes.

Disjoint from the open PR snapshot: #4939 covers pkg/linearagent + dashboard Linear token export, #4931 covers dashboard state-readout handlers, #4946/#4923/#4905 cover cmd/*. None touch pkg/hub/lite_enrollment.go.

Why

Every existing test stubs verifyLiteRepoAccess, so the REAL verifyGitHubRepoAccess β€” the function that decides whether an enrolling user's GitHub token actually has admin/maintain on the target repo, i.e. the lite-enrollment authorization gate β€” sat at 7.1% coverage. A regression that returns true for a push-only token would silently over-grant enrollment. discoverLiteInstallation (App-installation auto-discovery when the enrollment supplies no installation_id) was at 36.4%.

New tests

  • verifyGitHubRepoAccess: admin/maintain grant access; push-only does NOT; 401/403/404 are (false, nil) not errors; 5xx surfaces as an error naming status + body snippet; malformed JSON is a decode error; transport failure is reported; GHE hosts are checked against their /api/v3 base with the caller's bearer token and Accept header asserted; private/internal hosts (incl. 169.254.169.254) are rejected before any request leaves the process (SSRF gate).
  • validateLiteGitHubHost: public GHE hostname passes; unresolvable host fails closed (complements the literal-prefix cases in lite_enrollment_branches_test.go).
  • liteRepoAccessHTTPClient: a public redirect within the limit is allowed (the blocking branches are already covered in reach_pr_source_test.go).
  • discoverLiteInstallation: cluster App with no uploaded key β†’ actionable installation_id is required; non-RSA (EC) key β†’ not usable for discovery; discovery success (id adopted) and org-not-found against a local httptest server.

Requests reach a local httptest server via a test-scoped http.DefaultTransport swap (the production client uses a nil Transport), mirroring pkg/dashboard/import_test_transport_test.go; DNS is stubbed with the existing stubPrivateURLResolver helper. Hermetic β€” no real network.

Coverage

function before after
verifyGitHubRepoAccess 7.1% 92.9%
discoverLiteInstallation 36.4% 100%
validateLiteGitHubHost 80.0% 100%
liteRepoAccessHTTPClient 83.3% 100%

Full go test ./pkg/hub/ passes (141s), go vet clean, gofmt clean.


Filed by quality agent (hold-gated mode). Human review required.

β€” hive: agent=quality backend=copilot model=claude-fable-5

Every existing test stubs verifyLiteRepoAccess, so the REAL
verifyGitHubRepoAccess β€” the function that decides whether an enrolling
user's GitHub token has admin/maintain on the target repo β€” sat at 7.1%
coverage, and discoverLiteInstallation (App-installation auto-discovery
for enrollments that supply no installation_id) at 36.4%.

New src/pkg/hub/lite_enrollment_authcheck_test.go:
- verifyGitHubRepoAccess: admin/maintain grant, push-only denied, 401/403/404
  as (false, nil), 5xx as errors naming status+body, malformed JSON, transport
  failure, GHE hosts checked against /api/v3, private hosts rejected before
  any request leaves the process (SSRF gate).
- validateLiteGitHubHost: public GHE hostname passes, unresolvable fails closed.
- liteRepoAccessHTTPClient: public redirect within the limit is allowed.
- discoverLiteInstallation: app-without-key error, non-RSA key error,
  discovery success and org-not-found against a local httptest server.

Requests reach a local httptest server via a scoped http.DefaultTransport
swap (the client uses a nil Transport), mirroring the pattern in
pkg/dashboard/import_test_transport_test.go. No production code changes.

Coverage: verifyGitHubRepoAccess 7.1% -> 92.9%, discoverLiteInstallation
36.4% -> 100%, validateLiteGitHubHost and liteRepoAccessHTTPClient -> 100%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sec-check <sec-check@hive.kubestellar.io>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Aug 28, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

Copy link
Copy Markdown
Contributor

Changelog: this PR changes code but does not touch CHANGELOG.md.

If it is user-visible β€” a feature, a fix an operator would notice, a
security change, a migration, a deprecation, or anything breaking β€”
please add a line under ## Unreleased. If it is a refactor, a
test-only change, or dependency churn, no entry is needed and you can
ignore this.

This is a reminder, not a gate; it never blocks a merge.

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 28, 2026
@kubestellar-hive kubestellar-hive Bot added quality testing agent/quality Approved by a Hive merger/owner for auto-merge on green CI hive/hosted-available-oke-11-placeholder-r05x Approved by a Hive merger/owner for auto-merge on green CI labels Aug 28, 2026
@clubanderson
clubanderson merged commit 33dc009 into v4 Aug 28, 2026
42 of 43 checks passed
@clubanderson
clubanderson deleted the quality/test-lite-enrollment-auth branch August 28, 2026 13:01
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/quality Approved by a Hive merger/owner for auto-merge on green CI copilot dco-signoff: yes Indicates the PR's author has signed the DCO. hive/hosted-available-oke-11-placeholder-r05x Approved by a Hive merger/owner for auto-merge on green CI hold quality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant