diff options
| -rw-r--r-- | oxish/src/authentication.rs | 30 | ||||
| -rw-r--r-- | oxish/src/tests.rs | 10 |
2 files changed, 19 insertions, 21 deletions
diff --git a/oxish/src/authentication.rs b/oxish/src/authentication.rs index 452b2b2..e534429 100644 --- a/oxish/src/authentication.rs +++ b/oxish/src/authentication.rs @@ -327,13 +327,19 @@ struct CachedUser { } /// User data as retrieved from the system database +#[non_exhaustive] #[derive(Clone, Debug)] pub struct User { - pub(crate) name: Username, - pub(crate) id: u32, - pub(crate) gid: u32, - pub(crate) home_dir: PathBuf, - pub(crate) shell: PathBuf, + /// The user's name + pub name: Username, + /// The user's UID + pub id: u32, + /// The user's GID + pub gid: u32, + /// The user's home directory + pub home_dir: PathBuf, + /// The user's shell + pub shell: PathBuf, } impl User { @@ -435,20 +441,6 @@ impl User { }) } - /// Create a new user with the given name and home directory - /// - /// This is primarily intended for testing. - #[cfg(test)] - pub(crate) fn new(name: String, id: u32, gid: u32, home_dir: PathBuf) -> Result<Self, Error> { - Ok(Self { - name: Username::try_from(name)?, - id, - gid, - home_dir, - shell: PathBuf::from("/bin/sh"), - }) - } - const FAKE_HOME: *const c_char = c"/var/empty".as_ptr().cast::<c_char>(); const DEFAULT_SHELL: *const c_char = c"/bin/sh".as_ptr().cast::<c_char>(); } diff --git a/oxish/src/tests.rs b/oxish/src/tests.rs index e63b151..349c19b 100644 --- a/oxish/src/tests.rs +++ b/oxish/src/tests.rs @@ -12,7 +12,7 @@ use tokio::{io::AsyncWriteExt, net::TcpListener, process::Command, time::timeout use zeroize::Zeroizing; use crate::{ - SessionState, SideState, + SessionState, SideState, Username, authentication::{AuthorizedKey, SingleUser, User}, server::Server, }; @@ -111,7 +111,13 @@ async fn handshake( let authorized_key = fs::read_to_string(key_path.with_extension("pub")).unwrap(); let key = AuthorizedKey::from_str(&authorized_key, provider) .expect("failed to parse generated public key"); - let user = User::new(USER.to_string(), 1000, 1000, PathBuf::from("/var/empty")).unwrap(); + let user = User { + name: Username::try_from(USER.to_string()).unwrap(), + id: 1000, + gid: 1000, + home_dir: PathBuf::from("/var/empty"), + shell: PathBuf::from("/bin/sh"), + }; // Start the server on a loopback port and serve exactly one connection. let (_, pkcs8) = provider |
