Skip to content

surface network errors from integration token validation#1062

Merged
mergify[bot] merged 2 commits intomainfrom
kdreyer/fix-integration-validation-errors
Mar 27, 2026
Merged

surface network errors from integration token validation#1062
mergify[bot] merged 2 commits intomainfrom
kdreyer/fix-integration-validation-errors

Conversation

@ktdreyer
Copy link
Copy Markdown
Contributor

@ktdreyer ktdreyer commented Mar 26, 2026

Summary

  • Unwrap *url.Error in ValidateGitHubToken, ValidateGitLabToken, ValidateGoogleToken, and ValidateJiraToken to surface the inner network error (TLS, DNS, timeout, connection refused) without leaking the request URL or token.

Fixes #1037

Test plan

  • go vet ./handlers/ passes
  • Ginkgo tests pass (go test -tags test ./handlers/ -ginkgo.focus="Integration Validation")
  • Manual test against internal GitLab instance via make kind-up — error now shows TLS/certificate cause

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Unwraps network errors from *url.Error to expose underlying causes without leaking request details; validation functions now return normalized network errors on request failures; Jira validation aggregates last network error when no HTTP response is received; tests added to assert redaction and error propagation.

Changes

Cohort / File(s) Summary
Error handling & validation logic
components/backend/handlers/integration_validation.go
Added networkError(err error) to extract inner errors from *url.Error. Updated ValidateGitHubToken, ValidateGitLabToken, and ValidateGoogleToken to return fmt.Errorf("request failed: %w", networkError(err)) on client.Do failures. Modified ValidateJiraToken to track whether any HTTP response was seen and to return the last normalized network error when all attempts fail without a 401.
Integration tests
components/backend/handlers/integration_validation_test.go
New tests (build tag test) add connRefusedURL() to simulate refused connections, cover networkError behavior, and verify ValidateGitLabToken and ValidateJiraToken propagate network-level causes (e.g., “refused”) while redacting request URLs and token values; includes httptest servers for success/failure scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'surface network errors from integration token validation' directly and clearly describes the primary change: making network errors visible in token validation functions.
Linked Issues check ✅ Passed The PR fully addresses issue #1037: unwraps *url.Error in all four token validation functions, surfaces network errors without leaking URLs/tokens, and adds 12 tests verifying proper behavior.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objectives: error handling improvements in integration_validation.go and corresponding tests in integration_validation_test.go, with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description accurately describes the changeset by identifying the unwrapped network errors being surfaced in the four validation functions and mentions both the test plan and the fixed issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kdreyer/fix-integration-validation-errors

Comment @coderabbitai help to get the list of available commands and usage tips.

@ktdreyer
Copy link
Copy Markdown
Contributor Author

I tested it locally. Here's a screenshot:

image

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/backend/handlers/integration_validation_test.go`:
- Around line 50-64: Tests calling ValidateGitHubToken rely on real network
behavior and only assert on the error message when an error happens, so they can
pass without exercising the network-failure path; change the tests to
deterministically simulate a connection failure (like the existing
connRefusedURL() approach used for GitLab/Jira) by injecting a failing endpoint
or by using a custom http.Client/Transport stub so ValidateGitHubToken’s network
helper code is exercised; update the test(s) to call ValidateGitHubToken (or its
underlying HTTP helper used by ValidateGitLabToken) with an unreachable URL or
mocked Transport and assert the error message begins with "request failed: " and
is not exactly "request failed".

In `@components/backend/handlers/integration_validation.go`:
- Around line 15-20: The networkError function currently does a direct type
assertion against *url.Error which misses wrapped errors; change it to use
errors.As to detect and extract a *url.Error from a possibly wrapped error (and
return urlErr.Err), update the function signature to import/use the errors
package, and keep the fallback of returning the original err when no *url.Error
is found; reference the networkError function and the *url.Error type when
making this change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1ca76916-ff37-4ad2-a7a6-e972b64e92c8

📥 Commits

Reviewing files that changed from the base of the PR and between ee88acc and 890bb0f.

📒 Files selected for processing (2)
  • components/backend/handlers/integration_validation.go
  • components/backend/handlers/integration_validation_test.go

@ktdreyer ktdreyer force-pushed the kdreyer/fix-integration-validation-errors branch from 27170ad to cb62764 Compare March 26, 2026 19:22
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/backend/handlers/integration_validation.go (1)

97-100: ⚠️ Potential issue | 🟠 Major

Fail fast on Jira request-construction errors.

Line 98 currently continues on http.NewRequestWithContext failures, so a malformed base URL falls through to the Line 134 return true, nil path and /api/auth/jira/test can report success for an unusable URL. Since both fallback endpoints share the same base, this branch should return a sanitized error instead of retrying.

💡 Proposed fix
-		req, err := http.NewRequestWithContext(ctx, "GET", apiURL, nil)
+		req, err := http.NewRequestWithContext(ctx, http.MethodGet, apiURL, nil)
 		if err != nil {
-			continue
+			return false, fmt.Errorf("failed to create request")
 		}

Please add a malformed-URL regression test alongside the new Jira coverage.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/backend/handlers/integration_validation.go` around lines 97 - 100,
The code currently continues on http.NewRequestWithContext errors which lets a
malformed base URL incorrectly report success; update the Jira
request-construction branch to return a sanitized, non-sensitive error (e.g.,
"invalid Jira URL") instead of continue so the handler for /api/auth/jira/test
fails fast; modify the function that builds/executes the Jira request (the block
calling http.NewRequestWithContext) to return that error up the stack and add a
regression unit test for a malformed-URL case alongside the new Jira coverage to
assert the endpoint returns failure for an invalid base URL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@components/backend/handlers/integration_validation.go`:
- Around line 97-100: The code currently continues on http.NewRequestWithContext
errors which lets a malformed base URL incorrectly report success; update the
Jira request-construction branch to return a sanitized, non-sensitive error
(e.g., "invalid Jira URL") instead of continue so the handler for
/api/auth/jira/test fails fast; modify the function that builds/executes the
Jira request (the block calling http.NewRequestWithContext) to return that error
up the stack and add a regression unit test for a malformed-URL case alongside
the new Jira coverage to assert the endpoint returns failure for an invalid base
URL.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7ead27b1-2569-4fca-af80-7b2983b7f783

📥 Commits

Reviewing files that changed from the base of the PR and between 890bb0f and 27170ad.

📒 Files selected for processing (2)
  • components/backend/handlers/integration_validation.go
  • components/backend/handlers/integration_validation_test.go

@ktdreyer
Copy link
Copy Markdown
Contributor Author

@Mergifyio rebase

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 26, 2026

rebase

✅ Branch has been successfully rebased

@ktdreyer ktdreyer force-pushed the kdreyer/fix-integration-validation-errors branch from cb62764 to b51abf5 Compare March 26, 2026 21:08
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/backend/handlers/integration_validation.go`:
- Around line 94-95: The current logic treats any recorded network error
(lastNetErr) as a transport failure even when another probe produced a valid
HTTP response; change this by tracking whether any probe produced an HTTP
response (e.g., introduce a boolean like sawHTTPResponse or gotHTTPResponse
inside the probe loop) and only treat lastNetErr as a transport-level failure
when no probe produced an HTTP response (i.e., if !sawHTTPResponse && lastNetErr
!= nil). Update the places using lastNetErr (around the probe loop and the
checks referenced by lastNetErr at lines ~108-109 and ~128-131) to consult the
new flag instead of treating any network error as definitive.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 43c70363-7b85-42cf-99cf-39ce6e3b26f5

📥 Commits

Reviewing files that changed from the base of the PR and between cb62764 and b51abf5.

📒 Files selected for processing (2)
  • components/backend/handlers/integration_validation.go
  • components/backend/handlers/integration_validation_test.go

@ktdreyer ktdreyer force-pushed the kdreyer/fix-integration-validation-errors branch from ec8356c to 18d510e Compare March 26, 2026 21:58
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/backend/handlers/integration_validation.go`:
- Around line 93-95: The validation currently treats malformed Jira URLs as
success because request-construction failures leave lastNetErr nil and fall
through to returning true; update the probe logic in integration_validation.go
so that any error returned when building an *http.Request* (capture errors where
request creation fails) is assigned to lastNetErr and does not set
sawHTTPResponse, and after the probe loop if sawHTTPResponse is false return
false, lastNetErr (or a wrapped error) instead of true,nil; apply the same
change to the other probe blocks mentioned (where got401, lastNetErr,
sawHTTPResponse are used) and add a regression test that passes an obviously
malformed Jira URL and asserts validation returns false with the construction
error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 726f8f1a-f719-4504-8364-b6ad5ab3b446

📥 Commits

Reviewing files that changed from the base of the PR and between b51abf5 and 18d510e.

📒 Files selected for processing (2)
  • components/backend/handlers/integration_validation.go
  • components/backend/handlers/integration_validation_test.go

@ambient-code
Copy link
Copy Markdown
Contributor

ambient-code bot commented Mar 27, 2026

Review Queue Status

Check Status Detail
CI pass ---
Conflicts pass ---
Reviews FAIL CodeRabbit Major: Malformed Jira URLs treated as successful; mixed results return transport failure

Action needed: Address CodeRabbit Major issues on error handling logic

Auto-generated by Review Queue workflow. Updated when PR changes.

@ktdreyer ktdreyer marked this pull request as draft March 27, 2026 13:49
@ktdreyer ktdreyer marked this pull request as ready for review March 27, 2026 17:03
ktdreyer and others added 2 commits March 27, 2026 13:03
The "request failed" message hid the root cause (TLS, DNS,
timeout) because the code avoided wrapping *url.Error to
prevent leaking tokens. Unwrap *url.Error to extract only
the inner network error, which is safe to expose.

Users connecting to internal instances (eg GitLab behind a
corporate CA) now see actionable diagnostics like
"request failed: tls: failed to verify certificate" instead
of the opaque "request failed".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously, if one API version probe (e.g. v3) received a normal HTTP
response (like 404) but the other (v2) hit a network error, the
function returned "request failed" even though the server was
reachable. Track whether any probe received an HTTP response and only
surface the network error when none did.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ktdreyer ktdreyer force-pushed the kdreyer/fix-integration-validation-errors branch from 18d510e to 22c072a Compare March 27, 2026 17:03
Copy link
Copy Markdown
Member

@bobbravo2 bobbravo2 left a comment

Choose a reason for hiding this comment

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

Lgtm. Nice work with the code rabbit, and thanks for tracking follow up work!

@mergify mergify bot added the queued label Mar 27, 2026
mergify bot added a commit that referenced this pull request Mar 27, 2026
@mergify mergify bot merged commit 48b7f09 into main Mar 27, 2026
40 checks passed
@mergify mergify bot deleted the kdreyer/fix-integration-validation-errors branch March 27, 2026 22:24
@mergify
Copy link
Copy Markdown

mergify bot commented Mar 27, 2026

Merge Queue Status

This pull request spent 11 seconds in the queue, including 1 second running CI.

Required conditions to merge

@mergify mergify bot removed the queued label Mar 27, 2026
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.

Internal GitLab connection fails with unhelpful "request failed" error

2 participants