Skip to content

Commit

Permalink
Allow remote overrides for http options
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 24, 2022
1 parent c523c22 commit 0340b01
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
9 changes: 3 additions & 6 deletions git-repository/src/repository/config/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ impl crate::Repository {
///
/// Note that the caller may cast the instance themselves to modify it before passing it on.
///
///
// let (mut cascade, _action_with_normalized_url, prompt_opts) =
// self.remote.repo.config_snapshot().credential_helpers(url)?;
// Ok(Box::new(move |action| cascade.invoke(action, prompt_opts.clone())) as AuthenticateFn<'_>)
/// For transports that support proxy authentication, the authentication
/// [default authentication method](crate::config::Snapshot::credential_helpers()) will be used with the url of the proxy.
/// For transports that support proxy authentication, the
/// [default authentication method](crate::config::Snapshot::credential_helpers()) will be used with the url of the proxy
/// if it contains a user name.
pub fn transport_options<'a>(
&self,
url: impl Into<&'a BStr>,
Expand Down
Git LFS file not shown
10 changes: 10 additions & 0 deletions git-repository/tests/fixtures/make_config_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ git init http-config
git config gitoxide.http.connectTimeout 60k
)

git clone --shared http-config http-remote-override
(cd http-remote-override

git config http.proxy http://localhost:9090
git config http.proxyAuthMethod basic

git config remote.origin.proxy overridden
git config remote.origin.proxyAuthMethod negotiate
)

git init http-proxy-empty
(cd http-proxy-empty
git config http.proxy localhost:9090
Expand Down
26 changes: 17 additions & 9 deletions git-repository/tests/repository/config/transport_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
))]
mod http {
use git_repository as git;
use git_transport::client::http::options::{FollowRedirects, ProxyAuthMethod};

pub(crate) fn repo(name: &str) -> git::Repository {
let dir = git_testtools::scripted_fixture_repo_read_only("make_config_repos.sh").unwrap();
Expand All @@ -20,6 +21,20 @@ mod http {
.to_owned()
}

#[test]
#[ignore]
fn remote_overrides() {
let repo = repo("http-remote-override");
let git_transport::client::http::Options {
proxy,
proxy_auth_method,
..
} = http_options(&repo);

assert_eq!(proxy.as_deref(), Some("overridden"));
assert_eq!(proxy_auth_method, ProxyAuthMethod::Negotiate);
}

#[test]
fn simple_configuration() {
let repo = repo("http-config");
Expand All @@ -40,22 +55,15 @@ mod http {
&["ExtraHeader: value2", "ExtraHeader: value3"],
"it respects empty values to clear prior values"
);
assert_eq!(
follow_redirects,
git_transport::client::http::options::FollowRedirects::Initial
);
assert_eq!(follow_redirects, FollowRedirects::Initial);
assert_eq!(low_speed_limit_bytes_per_second, 5120);
assert_eq!(low_speed_time_seconds, 10);
assert_eq!(proxy.as_deref(), Some("http://localhost:9090"),);
assert!(
proxy_authenticate.is_none(),
"no username means no authentication required"
);
assert_eq!(
proxy_auth_method,
git_transport::client::http::options::ProxyAuthMethod::Basic,
"TODO: implement auth"
);
assert_eq!(proxy_auth_method, ProxyAuthMethod::Basic, "TODO: implement auth");
assert_eq!(user_agent.as_deref(), Some("agentJustForHttp"));
assert_eq!(connect_timeout, Some(std::time::Duration::from_millis(60 * 1024)));
assert!(
Expand Down

0 comments on commit 0340b01

Please sign in to comment.