History

adapt to changes in git-sec (#386)

Sebastian Thiel committed 4 years ago

Commit c5e23461 parent 37a607d6 files · +23 −27Browse files

Unified · Split

6 files
  1. git-credentials/src/helper.rs +2 −2
  2. git-protocol/src/fetch/tests/arguments.rs +4 −4
  3. git-transport/src/client/blocking_io/http/mod.rs +12 −16
  4. git-transport/src/client/mod.rs +1 −1
  5. git-transport/src/client/traits.rs +3 −3
  6. git-transport/tests/client/blocking_io/http/mod.rs +1 −1
git-credentials/src/helper.rs+2−2
@@ -71,7 +71,7 @@ impl NextAction { · 70 unmodified lines
7171 /// The outcome of [`action()`].
7272 pub struct Outcome {
7373 /// The obtained identity.
74− pub identity: git_sec::Identity,
74+ pub identity: git_sec::identity::Account,
7575 /// A handle to the action to perform next using another call to [`action()`].
7676 pub next: NextAction,
7777 }
@@ -127,7 +127,7 @@ pub fn action(action: Action<'_>) -> Result { · 49 unmodified lines
127127 .map(|(_, n)| n.to_owned())
128128 };
129129 Ok(Some(Outcome {
130− identity: git_sec::Identity::Account {
130+ identity: git_sec::identity::Account {
131131 username: find("username")?,
132132 password: find("password")?,
133133 },
git-protocol/src/fetch/tests/arguments.rs+4−4
@@ -20,14 +20,14 @@ struct Transport<T> { · 19 unmodified lines
2020 mod impls {
2121 use git_transport::{
2222 client,
23− client::{Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
23+ client::{Error, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
2424 Protocol, Service,
2525 };
2626
2727 use crate::fetch::tests::arguments::Transport;
2828
2929 impl<T: client::TransportWithoutIO> client::TransportWithoutIO for Transport<T> {
30− fn set_identity(&mut self, identity: Identity) -> Result<(), Error> {
30+ fn set_identity(&mut self, identity: client::Account) -> Result<(), Error> {
3131 self.inner.set_identity(identity)
3232 }
3333
@@ -64,13 +64,13 @@ mod impls { · 30 unmodified lines
6464 use async_trait::async_trait;
6565 use git_transport::{
6666 client,
67− client::{Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
67+ client::{Error, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
6868 Protocol, Service,
6969 };
7070
7171 use crate::fetch::tests::arguments::Transport;
7272 impl<T: client::TransportWithoutIO + Send> client::TransportWithoutIO for Transport<T> {
73− fn set_identity(&mut self, identity: Identity) -> Result<(), Error> {
73+ fn set_identity(&mut self, identity: client::Account) -> Result<(), Error> {
7474 self.inner.set_identity(identity)
7575 }
7676
git-transport/src/client/blocking_io/http/mod.rs+12−16
@@ -32,7 +32,7 @@ pub struct Transport<H: Http> { · 31 unmodified lines
3232 http: H,
3333 service: Option<Service>,
3434 line_provider: Option<git_packetline::StreamingPeekableIter<H::ResponseBody>>,
35− identity: Option<git_sec::Identity>,
35+ identity: Option<git_sec::identity::Account>,
3636 }
3737
3838 impl Transport<Impl> {
@@ -71,21 +71,17 @@ impl<H: Http> Transport<H> { · 32 unmodified lines
7171
7272 #[allow(clippy::unnecessary_wraps, unknown_lints)]
7373 fn add_basic_auth_if_present(&self, headers: &mut Vec<Cow<'_, str>>) -> Result<(), client::Error> {
74− if let Some(identity) = &self.identity {
75− match identity {
76− git_sec::Identity::Account { username, password } => {
77− #[cfg(not(debug_assertions))]
78− if self.url.starts_with("http://") {
79− return Err(client::Error::AuthenticationRefused(
80− "Will not send credentials in clear text over http",
81− ));
82− }
83− headers.push(Cow::Owned(format!(
84− "Authorization: Basic {}",
85− base64::encode(format!("{}:{}", username, password))
86− )))
87− }
74+ if let Some(git_sec::identity::Account { username, password }) = &self.identity {
75+ #[cfg(not(debug_assertions))]
76+ if self.url.starts_with("http://") {
77+ return Err(client::Error::AuthenticationRefused(
78+ "Will not send credentials in clear text over http",
79+ ));
8880 }
81+ headers.push(Cow::Owned(format!(
82+ "Authorization: Basic {}",
83+ base64::encode(format!("{}:{}", username, password))
84+ )))
8985 }
9086 Ok(())
9187 }
@@ -100,7 +96,7 @@ fn append_url(base: &str, suffix: &str) -> String { · 8 unmodified lines
10096 }
10197
10298 impl<H: Http> client::TransportWithoutIO for Transport<H> {
103− fn set_identity(&mut self, identity: git_sec::Identity) -> Result<(), client::Error> {
99+ fn set_identity(&mut self, identity: git_sec::identity::Account) -> Result<(), client::Error> {
104100 self.identity = Some(identity);
105101 Ok(())
106102 }
git-transport/src/client/mod.rs+1−1
@@ -28,7 +28,7 @@ pub use capabilities::Capabilities; · 27 unmodified lines
2828 mod non_io_types;
2929 pub use non_io_types::{Error, MessageKind, WriteMode};
3030
31−pub use git_sec::Identity;
31+pub use git_sec::identity::Account;
3232
3333 ///
3434 #[cfg(any(feature = "blocking-client", feature = "async-client"))]
git-transport/src/client/traits.rs+3−3
@@ -13,7 +13,7 @@ pub trait TransportWithoutIO { · 12 unmodified lines
1313 /// of the identity in order to mark it as invalid. Otherwise the user might have difficulty updating obsolete
1414 /// credentials.
1515 /// Please note that most transport layers are unauthenticated and thus return [an error][Error::AuthenticationUnsupported] here.
16− fn set_identity(&mut self, _identity: git_sec::Identity) -> Result<(), Error> {
16+ fn set_identity(&mut self, _identity: git_sec::identity::Account) -> Result<(), Error> {
1717 Err(Error::AuthenticationUnsupported)
1818 }
1919 /// Get a writer for sending data and obtaining the response. It can be configured in various ways
@@ -50,7 +50,7 @@ pub trait TransportWithoutIO { · 30 unmodified lines
5050
5151 // Would be nice if the box implementation could auto-forward to all implemented traits.
5252 impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for Box<T> {
53− fn set_identity(&mut self, identity: git_sec::Identity) -> Result<(), Error> {
53+ fn set_identity(&mut self, identity: git_sec::identity::Account) -> Result<(), Error> {
5454 self.deref_mut().set_identity(identity)
5555 }
5656
@@ -73,7 +73,7 @@ impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for Box<T> { · 16 unmodified lines
7373 }
7474
7575 impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for &mut T {
76− fn set_identity(&mut self, identity: git_sec::Identity) -> Result<(), Error> {
76+ fn set_identity(&mut self, identity: git_sec::identity::Account) -> Result<(), Error> {
7777 self.deref_mut().set_identity(identity)
7878 }
7979
git-transport/tests/client/blocking_io/http/mod.rs+1−1
@@ -42,7 +42,7 @@ fn assert_error_status( · 41 unmodified lines
4242 fn http_authentication_error_can_be_differentiated_and_identity_is_transmitted() -> crate::Result {
4343 let (server, mut client) = assert_error_status(401, std::io::ErrorKind::PermissionDenied)?;
4444 server.next_read_and_respond_with(fixture_bytes("v1/http-handshake.response"));
45− client.set_identity(git_sec::Identity::Account {
45+ client.set_identity(git_sec::identity::Account {
4646 username: "user".into(),
4747 password: "password".into(),
4848 })?;