Skip to content

Support setting an "Authorization" and a "Proxy-Authorization" HTTP request headers. - #5038

Open
amejia1 wants to merge 11 commits into
rust-lang:mainfrom
amejia1:main
Open

Support setting an "Authorization" and a "Proxy-Authorization" HTTP request headers.#5038
amejia1 wants to merge 11 commits into
rust-lang:mainfrom
amejia1:main

Conversation

@amejia1

@amejia1 amejia1 commented Aug 30, 2026

Copy link
Copy Markdown

The "Authorization" request header is used to authenticate to rustup distribution mirrors that require authentication. The "Proxy-Authorization" request header is used to authenticate to proxies.

This change introduces the new "rustup-mock-server" and "rustup-mock-proxy" test binaries, which are used to test the proper functioning of the new support for the "Authorization" and "Proxy-Authorization" HTTP request headers. A "test-rustup-init.sh" script has also been added to test the proper functioning of the "rustup-init.sh" script with the newly supported request headers.

As part of this change, "rustup-init.sh" was also modified to support distribution servers and proxies running on the localhost using HTTP. This not only provides the benefit of being able to use the "rustup-mock-server" and "rustup-mock-proxy" to run tests, it also provides additional support for custom servers and proxies which run on the localhost and forward requests to corporate servers that may require more elaborate forms of authentication, such as the usage of cookies or the usage of mTLS.

It doesn't seem like putting a disclaimer that AI agents were used is necessary. In any case, at least for the benefit of those that may have been using AI agents for much longer than I have, these code changes were made with the assistance of AI agents. I used a local LLM running this Qwen3.8-27B model.

This addresses #1343 .

I had a previous PR to offer similar functionality (see #4672 ). I decided to redo the code changes entirely, using a locally built mock server and proxy for the tests instead of relying on containers. I also decided to redo the changes with the aid of an AI agent.

amejia1 added 11 commits August 29, 2026 21:50
…equest headers.

The "Authorization" request header is used to authenticate to rustup
distribution mirrors that require authentication. The
"Proxy-Authorization" request header is used to authenticate to proxies.

This change introduces the new "rustup-mock-server" and
"rustup-mock-proxy" test binaries, which are used to test the proper
functioning of the new support for the "Authorization" and
"Proxy-Authorization" HTTP request headers. A "test-rustup-init.sh"
script has also been added to test the proper functioning of the
"rustup-init.sh" script with the newly supported request headers.

As part of this change, "rustup-init.sh" was also modified to support
distribution servers and proxies running on the localhost using HTTP.
This not only provides the benefit of being able to use the
"rustup-mock-server" and "rustup-mock-proxy" to run tests, it also
provides additional support for custom servers and proxies which run on
the localhost and forward requests to corporate servers that may
require more elaborate forms of authentication, such as the usage of
cookies or the usage of mTLS.
Adding the `rustup-mock-server` and `rustup-mock-proxy` binaries made
`cargo run` without `--bin` ambiguous, as the package no longer has a
single binary to run by default. Set `default-run` to `rustup-init` to
restore the previous behavior of `cargo run`.
The `check` CI job formats all TOML files with taplo and fails on
any difference; the `base64` dependency added by the previous commit
was not in taplo's expected position.
The CI build images ship a non-rustup Rust (at /rustc-sysroot/bin),
which makes rustup-init prompt "Continue?" before installing and
abort when the piped input is not "yes". Set
RUSTUP_INIT_SKIP_PATH_CHECK in the mock-based tests, as the clitools
test infrastructure already does (src/test/clitools.rs), so the
check is skipped there.
The assertion rendered the path to a string and checked that it ends
with ".local/share/...", which fails on Windows, where path
separators are backslashes. Compare the final path components
instead, and inject the home directory so the test does not depend
on the ambient environment.
On Windows, rustup-init prompts to install Visual C++ when the MSVC
build tools are missing, which breaks the hermetic tests on such
machines. Set RUSTUP_INIT_SKIP_MSVC_CHECK in the mock-based tests, as
with the rustc/cargo-in-PATH check and as the clitools test
infrastructure does (src/test/clitools.rs).
On Windows, the default data file location for rustup-mock-server
and rustup-mock-proxy is now under the LOCALAPPDATA directory,
falling back to C:\Users\%USER%\AppData\Local and then to the
system temporary directory. The platform-specific fallback logic
lives in pure helpers (unix_default_dir and windows_default_dir)
that take their inputs as parameters, so it is unit-tested on
every platform.
On Windows, rustup-init prompts "Press the Enter key to continue"
after a successful install and aborts when stdin is exhausted. The
mock-based tests piped a single "1" to answer the installation
menu, which left nothing for that second prompt. Invoke rustup-init
with -y instead, the same unattended flag the other rustup-init
tests use (e.g. tests/suite/cli_exact.rs), so no prompt reads from
stdin at all.
When base64 was moved next to the openssl dependency it ended up
below the comment that documents openssl. Place it in its
alphabetical position (between anyhow and cc) so the comment sits
directly above openssl. Verified with taplo using the same
configuration the check CI job applies.
The 14 tests in the test-rustup-init.sh shell script are now all
integration tests: the 10 rustup-init scenarios live in
tests/suite/proxy.rs, and the 4 rustup-init.sh scenarios now live in a
new tests/suite/init_sh.rs module.

Each init_sh test starts a mock dist server (seeded with the
rustup-init binary built from this repo, at dist/<arch>/rustup-init
for the architecture the script detects), runs
`sh rustup-init.sh -y --no-modify-path` with a restricted PATH that
contains only the commands the script needs and a single downloader
(curl or wget), and checks that the installed rustup binary works.
Two of the tests cover the new authorization header variables: one
installs directly from an authenticated mock server with
RUSTUP_AUTHORIZATION_HEADER, the other installs through an
authenticated proxy with both RUSTUP_AUTHORIZATION_HEADER and
RUSTUP_PROXY_AUTHORIZATION_HEADER.

The module is disabled on Windows (`#![cfg(not(windows))]`), where
rustup-init.exe is downloaded and run directly and the script is not
used. With the mock-based tests all running under `cargo test
--features test`, the test-rustup-init.sh script is no longer needed
and has been deleted. The "Test Scripts" section of
doc/dev-guide/src/testing.md is rewritten as a "Test Suite" section
describing the new layout.
Point developers who want to work without network access to the
rustup-mock-server program and the "Using with rustup" section of the
testing documentation, which contains a complete example.
@djc

djc commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

I am not excited about these changes. I think they add a lot of complexity solely for the benefit of testing pretty niche behavior. There's also no clean commit history.

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