Repository navigation
Normalize environment tokens and report invalid credentials before network requests - #127
Open
aryansri05 wants to merge 4 commits into
Open
aryansri05 wants to merge 4 commits into
aryansri05 wants to merge 4 commits into
Conversation
…twork requests A PROOFLINE_TOKEN that ends in a line break or carriage return made the HTTP client refuse to build every request. Nothing was sent, yet the CLI reported "could not reach <origin>: builder error", exited 4 from `ci review`, and without --org asked for an organization ID. Whitespace around the variable is no longer part of the token. A control character inside it, or a variable that holds only whitespace, is refused in credentials::load before the organization lookup and any request, with a message that names PROOFLINE_TOKEN and exit 1. An empty variable stays unset, as before.
…t for it Review follow-ups: - Whitespace inside PROOFLINE_TOKEN is refused with the control characters, before any request that carries the token, instead of being sent in a malformed Authorization header. - The configuration and setup commands no longer wrap a blank or malformed PROOFLINE_TOKEN in a `proofline login` hint, which refuses while the variable is set. - The comment in credentials::load says the check precedes requests that carry the token; the update check runs earlier and never has it. - Tests cover no-break and other Unicode spaces around, inside and as the whole value.
…decisive Review follow-ups: - credentials::load trims the token itself, so a caller of the public `run` gets the same treatment as the binary. `environment_token` only decides that an empty variable is unset. - The exit-4 test for a padded token now uses a console that answers 502 and records each bearer, so it cannot pass on a request that was never built. The refused-connection case keeps a clean token. - The GitHub Actions OIDC test also runs with PROOFLINE_TOKEN set to the empty string and expects the same requests as with it unset. - A C1 control character inside the token is covered, and the comment on the whitespace-only test says its fixture only records issuer attempts.
A caller of the public `run` that passes an empty string as `Some` would skip the GitHub Actions sign-in and be refused as a blank token. The doc comment now points at `credentials::environment_token`, which the binary uses.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
PROOFLINE_TOKENends in a line break or carriage return, the HTTP client refuses to build the request, nothing is sent, and the CLI reports an outage:main(5dd916f)--org ID reviews,--org ID statuscould not reach <origin>: builder error--org ID ci review …--orgcould not read PROOFLINE_TOKEN's organization (the MCP server could not be reached); name it with --org or PROOFLINE_ORGANIZATION_IDNothing names the token, and a CI job reads exit 4 as Proofline being down.
Reproduce in bash or zsh against any origin, reachable or not:
PROOFLINE_TOKEN=$'pl_example\n' proofline --org 0190f3a0-0000-7000-8000-000000000001 reviews$'…'keeps the line break in the value."$(printf 'pl_example\n')"does not reproduce it, because command substitution strips trailing newlines.I reproduced this by setting the variable directly. A CI secret saved with its trailing newline, or a
.envfile with CRLF line endings, are plausible ways to end up there; I did not test either.Change
credentials::loadtrims whitespace around the token before using it, so the binary and any caller ofrunare treated alike.PROOFLINE_TOKENand the command exits 1, not 4.configandsetupcommands no longer wrap these two errors in aproofline loginhint, becauseproofline loginrefuses while the variable is set.The token never appears in either message.
Behaviour change to note
With a working stored sign-in and a whitespace-only
PROOFLINE_TOKEN, a Git hook used to review with the stored sign-in. It now prints the token error and, under the defaultonIncompletepolicy, lets the commit or push proceed, as it does for any other credential failure.onIncomplete=blockrefuses it. I kept the hook's existing policy rather than making token errors a hard failure.Tests
tests/http.rsruns the binary against a loopback console:Bearer <token>(with--org);--org);ci review,reviewsandsetup status, with and without--org;ci reviewwith exit 4 only after each request arrived with the trimmed token;ci reviewwith exit 4;PROOFLINE_TOKENset to the empty string and expects the same requests as with it unset.The first five fail on
main'ssrc/and pass with this change. The last two pass on both, since they pin behaviour that must not change.src/credentials.rshas unit tests for the same rules.Checks run
On rustc 1.97.0 (stable), not the pinned 1.100.0, which was not available in my environment:
cargo fmt --checkcargo clippy --locked --all-targets -- -D warningscargo test --lockedcargo deny check(cargo-deny 0.20.2)All four passed. The pinned toolchain has not run this change yet; this repository's
Checksworkflow will be the first to.