Unified · Split
| @@ -71,7 +71,7 @@ impl NextAction { · 70 unmodified lines | ||
| 71 | 71 | /// The outcome of [`action()`]. |
| 72 | 72 | pub struct Outcome { |
| 73 | 73 | /// The obtained identity. |
| 74 | − pub identity: git_sec::Identity, | |
| 74 | + pub identity: git_sec::identity::Account, | |
| 75 | 75 | /// A handle to the action to perform next using another call to [`action()`]. |
| 76 | 76 | pub next: NextAction, |
| 77 | 77 | } |
| @@ -127,7 +127,7 @@ pub fn action(action: Action<'_>) -> Result { · 49 unmodified lines | ||
| 127 | 127 | .map(|(_, n)| n.to_owned()) |
| 128 | 128 | }; |
| 129 | 129 | Ok(Some(Outcome { |
| 130 | − identity: git_sec::Identity::Account { | |
| 130 | + identity: git_sec::identity::Account { | |
| 131 | 131 | username: find("username")?, |
| 132 | 132 | password: find("password")?, |
| 133 | 133 | }, |
| @@ -20,14 +20,14 @@ struct Transport<T> { · 19 unmodified lines | ||
| 20 | 20 | mod impls { |
| 21 | 21 | use git_transport::{ |
| 22 | 22 | client, |
| 23 | − client::{Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode}, | |
| 23 | + client::{Error, MessageKind, RequestWriter, SetServiceResponse, WriteMode}, | |
| 24 | 24 | Protocol, Service, |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | 27 | use crate::fetch::tests::arguments::Transport; |
| 28 | 28 | |
| 29 | 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 | 31 | self.inner.set_identity(identity) |
| 32 | 32 | } |
| 33 | 33 | |
| @@ -64,13 +64,13 @@ mod impls { · 30 unmodified lines | ||
| 64 | 64 | use async_trait::async_trait; |
| 65 | 65 | use git_transport::{ |
| 66 | 66 | client, |
| 67 | − client::{Error, Identity, MessageKind, RequestWriter, SetServiceResponse, WriteMode}, | |
| 67 | + client::{Error, MessageKind, RequestWriter, SetServiceResponse, WriteMode}, | |
| 68 | 68 | Protocol, Service, |
| 69 | 69 | }; |
| 70 | 70 | |
| 71 | 71 | use crate::fetch::tests::arguments::Transport; |
| 72 | 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 | 74 | self.inner.set_identity(identity) |
| 75 | 75 | } |
| 76 | 76 | |
| @@ -32,7 +32,7 @@ pub struct Transport<H: Http> { · 31 unmodified lines | ||
| 32 | 32 | http: H, |
| 33 | 33 | service: Option<Service>, |
| 34 | 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 | |
| 38 | 38 | impl Transport<Impl> { |
| @@ -71,21 +71,17 @@ impl<H: Http> Transport<H> { · 32 unmodified lines | ||
| 71 | 71 | |
| 72 | 72 | #[allow(clippy::unnecessary_wraps, unknown_lints)] |
| 73 | 73 | 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 | + )); | |
| 88 | 80 | } |
| 81 | + headers.push(Cow::Owned(format!( | |
| 82 | + "Authorization: Basic {}", | |
| 83 | + base64::encode(format!("{}:{}", username, password)) | |
| 84 | + ))) | |
| 89 | 85 | } |
| 90 | 86 | Ok(()) |
| 91 | 87 | } |
| @@ -100,7 +96,7 @@ fn append_url(base: &str, suffix: &str) -> String { · 8 unmodified lines | ||
| 100 | 96 | } |
| 101 | 97 | |
| 102 | 98 | 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> { | |
| 104 | 100 | self.identity = Some(identity); |
| 105 | 101 | Ok(()) |
| 106 | 102 | } |
| @@ -28,7 +28,7 @@ pub use capabilities::Capabilities; · 27 unmodified lines | ||
| 28 | 28 | mod non_io_types; |
| 29 | 29 | pub use non_io_types::{Error, MessageKind, WriteMode}; |
| 30 | 30 | |
| 31 | −pub use git_sec::Identity; | |
| 31 | +pub use git_sec::identity::Account; | |
| 32 | 32 | |
| 33 | 33 | /// |
| 34 | 34 | #[cfg(any(feature = "blocking-client", feature = "async-client"))] |
| @@ -13,7 +13,7 @@ pub trait TransportWithoutIO { · 12 unmodified lines | ||
| 13 | 13 | /// of the identity in order to mark it as invalid. Otherwise the user might have difficulty updating obsolete |
| 14 | 14 | /// credentials. |
| 15 | 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 | 17 | Err(Error::AuthenticationUnsupported) |
| 18 | 18 | } |
| 19 | 19 | /// 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 | 51 | // Would be nice if the box implementation could auto-forward to all implemented traits. |
| 52 | 52 | 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> { | |
| 54 | 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 | |
| 75 | 75 | 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> { | |
| 77 | 77 | self.deref_mut().set_identity(identity) |
| 78 | 78 | } |
| 79 | 79 | |
| @@ -42,7 +42,7 @@ fn assert_error_status( · 41 unmodified lines | ||
| 42 | 42 | fn http_authentication_error_can_be_differentiated_and_identity_is_transmitted() -> crate::Result { |
| 43 | 43 | let (server, mut client) = assert_error_status(401, std::io::ErrorKind::PermissionDenied)?; |
| 44 | 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 | 46 | username: "user".into(), |
| 47 | 47 | password: "password".into(), |
| 48 | 48 | })?; |