Skip to content

fix(webhook): require ngrok authtoken before tunnel startup (#107) - #112

Open
mangeshraut712 wants to merge 1 commit into
xdevplatform:mainfrom
mangeshraut712:fix/webhook-ngrok-token-guard-107
Open

mangeshraut712 wants to merge 1 commit into
xdevplatform:mainfrom
mangeshraut712:fix/webhook-ngrok-token-guard-107

Conversation

@mangeshraut712

Copy link
Copy Markdown

Summary

Resolves #107.

When starting the webhook server with xurl webhook start, entering an empty line at the ngrok prompt when NGROK_AUTHTOKEN was unset in the environment resulted in ngrok.WithAuthtokenFromEnv() passing an empty token to ngrok.Listen(ctx, ...).

In the ngrok Go client SDK, missing or invalid credentials cause ngrok.Connect to enter an exponential-backoff retry loop without returning an error or printing a diagnostic to the console, leaving the command hanging silently past 60 seconds without establishing a tunnel or informing the user of the missing credential.

Changes

  1. cli/webhook.go:
    • Extracted resolveNgrokAuthtoken and selectNgrokAuthtoken.
    • Validates that an authtoken is present either from the user prompt or from NGROK_AUTHTOKEN.
    • Trims whitespace from both sources to ensure whitespace-only strings are treated as missing.
    • If both the prompt and environment variable are empty, outputs a clear diagnostic (Error: ngrok authtoken is required. Provide it at the prompt or set the NGROK_AUTHTOKEN environment variable) and exits with code 1 immediately, eliminating the silent hang.
    • When a token is resolved, explicitly configures tunnelOpts with ngrok.WithAuthtoken(token).
  2. cli/webhook_test.go:
    • Added unit tests covering:
      • Prompt token preference over environment variable.
      • Whitespace trimming on prompt input.
      • Fallback to NGROK_AUTHTOKEN environment variable when prompt is blank.
      • Handling whitespace-only environment tokens.
      • Rejection with actionable error when both prompt and environment are empty or whitespace.
      • resolveNgrokAuthtoken with buffered reader inputs and environment overrides.

Test Plan

  • go build ./... passes cleanly
  • go test -v -race ./cli -run Ngrok passes all 9 test cases
  • go test -race ./... passes across all packages
  • Cross-compilation verified for GOOS=windows GOARCH=amd64 and GOOS=linux GOARCH=arm64

…form#107)

When running `xurl webhook start`, entering a blank prompt when `NGROK_AUTHTOKEN`
was unset previously resulted in calling `ngrok.WithAuthtokenFromEnv()` with an
empty token into `ngrok.Listen`. In the ngrok client SDK, missing credentials
trigger exponential-backoff reconnect attempts indefinitely, causing startup to
hang silently past 60 seconds without displaying any diagnostic or error.

Validate the authtoken resolution beforehand via `resolveNgrokAuthtoken` and
`selectNgrokAuthtoken`. If both the prompted input and `NGROK_AUTHTOKEN` environment
variable are empty or whitespace, fail immediately with an actionable error
message and exit code 1.

Add unit tests covering prompt preference, whitespace trimming, environment
fallback, and missing-credential rejection.

Signed-off-by: Mangesh Raut <mbr63@drexel.edu>
@mangeshraut712

Copy link
Copy Markdown
Author

Current head d938c723 is mergeable, and the CLA check is signed and green. It requires an ngrok authtoken before webhook tunnel startup, which addresses #107. Happy to make any changes you want.

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.

fix(webhook): missing ngrok token leaves startup retrying silently

1 participant