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
71/// The outcome of [`action()`].71/// The outcome of [`action()`].
72pub struct Outcome {72pub struct Outcome {
73 /// The obtained identity.73 /// The obtained identity.
74 pub identity: git_sec::Identity,74 pub identity: git_sec::identity::Account,
75 /// A handle to the action to perform next using another call to [`action()`].75 /// A handle to the action to perform next using another call to [`action()`].
76 pub next: NextAction,76 pub next: NextAction,
77}77}
@@ -127,7 +127,7 @@ pub fn action(action: Action<'_>) -> Result { · 49 unmodified lines
127 .map(|(_, n)| n.to_owned())127 .map(|(_, n)| n.to_owned())
128 };128 };
129 Ok(Some(Outcome {129 Ok(Some(Outcome {
130 identity: git_sec::Identity::Account {130 identity: git_sec::identity::Account {
131 username: find("username")?,131 username: find("username")?,
132 password: find("password")?,132 password: find("password")?,
133 },133 },
git-protocol/src/fetch/tests/arguments.rs+4−4
@@ -20,14 +20,14 @@ struct Transport<T> { · 19 unmodified lines
20mod impls {20mod impls {
21 use git_transport::{21 use git_transport::{
22 client,22 client,
23 client::{Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},23 client::{Error, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
24 Protocol, Service,24 Protocol, Service,
25 };25 };
26 26
27 use crate::fetch::tests::arguments::Transport;27 use crate::fetch::tests::arguments::Transport;
28 28
29 impl<T: client::TransportWithoutIO> client::TransportWithoutIO for Transport<T> {29 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> {
31 self.inner.set_identity(identity)31 self.inner.set_identity(identity)
32 }32 }
33 33
@@ -64,13 +64,13 @@ mod impls { · 30 unmodified lines
64 use async_trait::async_trait;64 use async_trait::async_trait;
65 use git_transport::{65 use git_transport::{
66 client,66 client,
67 client::{Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode},67 client::{Error, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
68 Protocol, Service,68 Protocol, Service,
69 };69 };
70 70
71 use crate::fetch::tests::arguments::Transport;71 use crate::fetch::tests::arguments::Transport;
72 impl<T: client::TransportWithoutIO + Send> client::TransportWithoutIO for Transport<T> {72 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> {
74 self.inner.set_identity(identity)74 self.inner.set_identity(identity)
75 }75 }
76 76
git-transport/src/client/blocking_io/http/mod.rs+12−16
@@ -32,7 +32,7 @@ pub struct Transport<H: Http> { · 31 unmodified lines
32 http: H,32 http: H,
33 service: Option<Service>,33 service: Option<Service>,
34 line_provider: Option<git_packetline::StreamingPeekableIter<H::ResponseBody>>,34 line_provider: Option<git_packetline::StreamingPeekableIter<H::ResponseBody>>,
35 identity: Option<git_sec::Identity>,35 identity: Option<git_sec::identity::Account>,
36}36}
37 37
38impl Transport<Impl> {38impl Transport<Impl> {
@@ -71,21 +71,17 @@ impl<H: Http> Transport<H> { · 32 unmodified lines
71 71
72 #[allow(clippy::unnecessary_wraps, unknown_lints)]72 #[allow(clippy::unnecessary_wraps, unknown_lints)]
73 fn add_basic_auth_if_present(&self, headers: &mut Vec<Cow<'_, str>>) -> Result<(), client::Error> {73 fn add_basic_auth_if_present(&self, headers: &mut Vec<Cow<'_, str>>) -> Result<(), client::Error> {
74 if let Some(identity) = &self.identity {74 if let Some(git_sec::identity::Account { username, password }) = &self.identity {
75 match identity {75 #[cfg(not(debug_assertions))]
76 git_sec::Identity::Account { username, password } => {76 if self.url.starts_with("http://") {
77 #[cfg(not(debug_assertions))]77 return Err(client::Error::AuthenticationRefused(
78 if self.url.starts_with("http://") {78 "Will not send credentials in clear text over http",
79 return Err(client::Error::AuthenticationRefused(79 ));
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 }
88 }80 }
81 headers.push(Cow::Owned(format!(
82 "Authorization: Basic {}",
83 base64::encode(format!("{}:{}", username, password))
84 )))
89 }85 }
90 Ok(())86 Ok(())
91 }87 }
@@ -100,7 +96,7 @@ fn append_url(base: &str, suffix: &str) -> String { · 8 unmodified lines
100}96}
101 97
102impl<H: Http> client::TransportWithoutIO for Transport<H> {98impl<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> {
104 self.identity = Some(identity);100 self.identity = Some(identity);
105 Ok(())101 Ok(())
106 }102 }
git-transport/src/client/mod.rs+1−1
@@ -28,7 +28,7 @@ pub use capabilities::Capabilities; · 27 unmodified lines
28mod non_io_types;28mod non_io_types;
29pub use non_io_types::{Error, MessageKind, WriteMode};29pub use non_io_types::{Error, MessageKind, WriteMode};
30 30
31pub use git_sec::Identity;31pub use git_sec::identity::Account;
32 32
33///33///
34#[cfg(any(feature = "blocking-client", feature = "async-client"))]34#[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
13 /// of the identity in order to mark it as invalid. Otherwise the user might have difficulty updating obsolete13 /// of the identity in order to mark it as invalid. Otherwise the user might have difficulty updating obsolete
14 /// credentials.14 /// credentials.
15 /// Please note that most transport layers are unauthenticated and thus return [an error][Error::AuthenticationUnsupported] here.15 /// 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> {
17 Err(Error::AuthenticationUnsupported)17 Err(Error::AuthenticationUnsupported)
18 }18 }
19 /// Get a writer for sending data and obtaining the response. It can be configured in various ways19 /// 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
50 50
51// Would be nice if the box implementation could auto-forward to all implemented traits.51// Would be nice if the box implementation could auto-forward to all implemented traits.
52impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for Box<T> {52impl<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> {
54 self.deref_mut().set_identity(identity)54 self.deref_mut().set_identity(identity)
55 }55 }
56 56
@@ -73,7 +73,7 @@ impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for Box<T> { · 16 unmodified lines
73}73}
74 74
75impl<T: TransportWithoutIO + ?Sized> TransportWithoutIO for &mut T {75impl<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> {
77 self.deref_mut().set_identity(identity)77 self.deref_mut().set_identity(identity)
78 }78 }
79 79
git-transport/tests/client/blocking_io/http/mod.rs+1−1
@@ -42,7 +42,7 @@ fn assert_error_status( · 41 unmodified lines
42fn http_authentication_error_can_be_differentiated_and_identity_is_transmitted() -> crate::Result {42fn http_authentication_error_can_be_differentiated_and_identity_is_transmitted() -> crate::Result {
43 let (server, mut client) = assert_error_status(401, std::io::ErrorKind::PermissionDenied)?;43 let (server, mut client) = assert_error_status(401, std::io::ErrorKind::PermissionDenied)?;
44 server.next_read_and_respond_with(fixture_bytes("v1/http-handshake.response"));44 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 {
46 username: "user".into(),46 username: "user".into(),
47 password: "password".into(),47 password: "password".into(),
48 })?;48 })?;