Skip to content

Commit

Permalink
Empty proxies can disable the proxy; cleanup test fixture, let it hav…
Browse files Browse the repository at this point in the history
…e its own
  • Loading branch information
Byron committed Nov 15, 2022
1 parent f4ff821 commit 21f3283
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
Git LFS file not shown
22 changes: 22 additions & 0 deletions git-repository/tests/fixtures/make_config_repos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set -eu -o pipefail

git init http-config
(cd http-config
git config http.extraHeader "ExtraHeader: value1"
git config --add http.extraHeader ""
git config --add http.extraHeader "ExtraHeader: value2"
git config --add http.extraHeader "ExtraHeader: value3"
git config http.followRedirects initial
git config http.lowSpeedLimit 5k
git config http.lowSpeedTime 10
git config http.postBuffer 8k
git config http.proxy localhost:9090
git config http.proxyAuthMethod anyauth
git config http.userAgent agentJustForHttp
)

git init http-config-empty-proxy
(cd http-config-empty-proxy
git config http.proxy localhost:9090
git config --add http.proxy "" # a value override disabling it later
)
16 changes: 1 addition & 15 deletions git-repository/tests/fixtures/make_fetch_repos.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set -eu -o pipefail

# IMPORTANT: keep this repo small as it's used for writes, hence will be executed for each writer!
git clone --bare "${1:?First argument is the complex base repo from make_remote_repos.sh/base}" base

git clone --shared base clone-as-base-with-changes
Expand Down Expand Up @@ -28,18 +29,3 @@ git clone --shared base worktree-root
git worktree add --lock ../wt-c-locked
git worktree add ../wt-deleted && rm -Rf ../wt-deleted
)

git init http-config
(cd http-config
git config http.extraHeader "ExtraHeader: value1"
git config --add http.extraHeader ""
git config --add http.extraHeader "ExtraHeader: value2"
git config --add http.extraHeader "ExtraHeader: value3"
git config http.followRedirects initial
git config http.lowSpeedLimit 5k
git config http.lowSpeedTime 10
git config http.postBuffer 8k
git config http.proxy localhost:9090
git config http.proxyAuthMethod anyauth
git config http.userAgent agentJustForHttp
)
32 changes: 19 additions & 13 deletions git-repository/tests/repository/config/transport_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,8 @@
mod http {
use git_repository as git;

fn base_repo_path() -> String {
git::path::realpath(
git_testtools::scripted_fixture_repo_read_only("make_remote_repos.sh")
.unwrap()
.join("base"),
)
.unwrap()
.to_string_lossy()
.into_owned()
}

pub(crate) fn repo(name: &str) -> git::Repository {
let dir = git_testtools::scripted_fixture_repo_read_only_with_args("make_fetch_repos.sh", [base_repo_path()])
.unwrap();
let dir = git_testtools::scripted_fixture_repo_read_only("make_config_repos.sh").unwrap();
git::open_opts(dir.join(name), git::open::Options::isolated()).unwrap()
}

Expand Down Expand Up @@ -72,4 +60,22 @@ mod http {
"backed is never set as it's backend specific, rather custom options typically"
)
}

#[test]
fn empty_proxy_string_turns_it_off() {
let repo = repo("http-config-empty-proxy");

let http_config = repo
.transport_options("https://example.com/does/not/matter")
.expect("valid configuration")
.expect("configuration available for http");
let http_config = http_config
.downcast_ref::<git_transport::client::http::Options>()
.expect("http options have been created");
assert_eq!(
http_config.proxy.as_deref(),
Some(""),
"empty strings indicate that the proxy is to be unset by the transport"
);
}
}

0 comments on commit 21f3283

Please sign in to comment.