Skip to content

Commonize OIDC handler test cases with table-driven generation#111

Open
kbukum1 wants to merge 1 commit intomainfrom
commonize-oidc-handler-tests
Open

Commonize OIDC handler test cases with table-driven generation#111
kbukum1 wants to merge 1 commit intomainfrom
commonize-oidc-handler-tests

Conversation

@kbukum1
Copy link
Copy Markdown
Contributor

@kbukum1 kbukum1 commented Apr 24, 2026

Commonize OIDC handler test cases with table-driven generation

Follow-up from #108 — reduces repetitive test code while preserving identical coverage.

Problem

oidc_handling_test.go had 65 hand-written test cases (13 ecosystems × 5 OIDC providers) with near-identical structure. Adding a new provider required copying ~13 blocks; adding a new ecosystem required copying ~5 blocks. Each block repeated the same provider credential fields, handler factory, and assertion logic.

Approach

Introduce buildEcosystemCases helper and oidcProviderFields shared function:

  • oidcProviderFields(provider) — returns provider-specific credential fields (aws-region, tenant-id, etc.) shared across all ecosystems
  • buildEcosystemCases(name, factory, logLabel, variants) — generates test cases by merging ecosystem URL config with provider fields, deriving log lines and auth URLs automatically
  • Each ecosystem defines only what varies: credential URL fields per provider, with explicit overrides for special cases

Special cases preserved with explicit overrides:

  • Docker/Helm JFrog: host-derived log targets
  • Go proxy/Terraform Azure: host-based credentials
  • Python GCP: index-url with /simple suffix stripping
  • RubyGems: dual url+host credential fields
  • NuGet: service index discovery mocks and resource URL registration
  • Composer JFrog: dual registry+url fields

Result

  • 1846 → 685 lines (~63% reduction)
  • Same 65 test cases with identical names and assertions
  • Adding a new provider = add 1 entry to oidcProviderFields + 1 line per ecosystem
  • Adding a new ecosystem = add 1 buildEcosystemCases call with 5 variants
  • Test runner and assertion logic unchanged

Copilot AI review requested due to automatic review settings April 24, 2026 23:37
@kbukum1 kbukum1 requested a review from a team as a code owner April 24, 2026 23:37
Copy link
Copy Markdown

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

Refactors oidc_handling_test.go to generate OIDC handler URL/auth/log assertion cases via shared, table-driven helpers, reducing repetitive per-ecosystem/per-provider boilerplate while aiming to keep the same coverage.

Changes:

  • Adds oidcProviderFields + buildEcosystemCases helpers and supporting structs to generate OIDC test cases across providers.
  • Rewrites TestOIDCURLsAreAuthenticated to use provider variants per ecosystem (including special-case overrides like NuGet mocks and Python /simple behavior).
  • Normalizes provider token-exchange endpoint mocks within the shared test runner.
Show a summary per file
File Description
internal/handlers/oidc_handling_test.go Replaces many hand-written OIDC URL/auth test cases with helper-generated, table-driven cases and provider-specific token-exchange mocks.

Copilot's findings

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

Comment thread internal/handlers/oidc_handling_test.go Outdated
Comment thread internal/handlers/oidc_handling_test.go Outdated
Replace 65 hand-written test cases (13 ecosystems × 5 providers) with
table-driven generation using buildEcosystemCases helper. Each ecosystem
defines its variants compactly — provider credential fields are shared
via oidcProviderFields, and expected log lines / auth URLs are derived
automatically with explicit overrides for special cases.

Reduces oidc_handling_test.go from 1846 to 685 lines (~63%) while
preserving identical test coverage: same 65 test cases, same test names,
same assertions, same provider mock endpoints.

Special cases handled explicitly:
- Docker/Helm JFrog: host-derived log targets
- Go proxy/Terraform Azure: host-based credentials
- Python GCP: index-url with /simple suffix stripping
- RubyGems: dual url+host credential fields
- NuGet: service index discovery mocks and resource URL registration
- Composer JFrog: dual registry+url fields

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kbukum1 kbukum1 force-pushed the commonize-oidc-handler-tests branch from 0950347 to a12df54 Compare April 25, 2026 00:05
@kbukum1 kbukum1 requested a review from Copilot April 25, 2026 00:06
Copy link
Copy Markdown

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.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines +295 to +305
nugetMocks := func(baseURL string) []mockHttpRequest {
host := strings.TrimPrefix(strings.TrimPrefix(baseURL, "https://"), "http://")
host = strings.SplitN(host, "/", 2)[0]
pathPrefix := strings.TrimPrefix(baseURL, "https://"+host)
pathPrefix = strings.TrimSuffix(pathPrefix, "/index.json")
return []mockHttpRequest{{
verb: "GET",
url: baseURL,
response: fmt.Sprintf(`{"version":"3.0.0","resources":[{"@id":"https://%s%s/v3/packages","@type":"PackageBaseAddress/3.0.0"}]}`,
host, pathPrefix),
}}
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

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

In the NuGet test case generator, nugetMocks always appends /v3/packages to the derived pathPrefix. For a base service index like https://cloudsmith.example.com/v3/index.json, pathPrefix becomes /v3, producing a mocked resource URL of .../v3/v3/packages (and the test then authenticates that URL). This changes the covered behavior vs the prior hand-written tests (which used .../v3/packages) and doesn’t match typical NuGet service index layouts. Consider special-casing the /v3 prefix (or deriving the resource URL from the index directory) so .../v3/index.json yields .../v3/packages while nested repos (e.g. .../my-repo/index.json) still yield .../my-repo/v3/packages.

Copilot uses AI. Check for mistakes.
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.

2 participants