pub struct MockPwdGrpProvider(/* private fields */);Expand description
Mock provider of passwd/group data
An implementor of PwdGrpProvider
which doesn’t look at the real system databases.
The Default contains just dummy entries for root.
You can pre-program it with passwd and group data.
The mock provider has interior mutability,
so the trait can take non-mut references.
Note: this affects only the methods on PwdGrpProvider,
not the plain functions in the pwd-grp crate toplevel.
§Example
use pwd_grp::Group;
use pwd_grp::mock::MockPwdGrpProvider;
use pwd_grp::PwdGrpProvider as _;
let mock = MockPwdGrpProvider::new();
assert_eq!(mock.getgrnam::<String>("root").unwrap().unwrap().gid, 0);
mock.add_to_groups([Group {
name: "wombats".to_string(),
passwd: "*".to_string(),
gid: 42,
mem: vec!["alice".to_string()].into(),
..Group::blank()
}]);
let grent: Group = mock.getgrgid(42).unwrap().unwrap();
assert_eq!(grent.passwd, "*");Implementations§
Source§impl MockPwdGrpProvider
impl MockPwdGrpProvider
Sourcepub fn add_to_passwds<I>(&self, data: impl IntoIterator<Item = I>)
pub fn add_to_passwds<I>(&self, data: impl IntoIterator<Item = I>)
Append entries to the mock passwd database
Sourcepub fn add_to_groups<I>(&self, data: impl IntoIterator<Item = I>)
pub fn add_to_groups<I>(&self, data: impl IntoIterator<Item = I>)
Append entries to the mock group database
Sourcepub fn set_uids(&self, uids: RealEffectiveSavedIds)
pub fn set_uids(&self, uids: RealEffectiveSavedIds)
Set the mock uids
Sourcepub fn set_gids(&self, gids: RealEffectiveSavedIds)
pub fn set_gids(&self, gids: RealEffectiveSavedIds)
Set the mock gids
Sourcepub fn set_supplementary_groups(&self, supplementary_groups: Vec<uid_t>)
pub fn set_supplementary_groups(&self, supplementary_groups: Vec<uid_t>)
Set the mock supplementary_groups
Trait Implementations§
Source§impl Clone for MockPwdGrpProvider
impl Clone for MockPwdGrpProvider
Source§fn clone(&self) -> MockPwdGrpProvider
fn clone(&self) -> MockPwdGrpProvider
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MockPwdGrpProvider
impl Debug for MockPwdGrpProvider
Source§impl Default for MockPwdGrpProvider
impl Default for MockPwdGrpProvider
Source§fn default() -> MockPwdGrpProvider
fn default() -> MockPwdGrpProvider
Returns the “default value” for a type. Read more
Source§impl PwdGrpProvider for MockPwdGrpProvider
impl PwdGrpProvider for MockPwdGrpProvider
Source§fn getpwnam<S: PwdGrpString>(
&self,
name: impl AsRef<<S as Deref>::Target>,
) -> Result<Option<Passwd<S>>>
fn getpwnam<S: PwdGrpString>( &self, name: impl AsRef<<S as Deref>::Target>, ) -> Result<Option<Passwd<S>>>
Look up a
passwd
entry by
name,
returning strings as
SSource§fn getpwuid<S: PwdGrpString>(&self, uid: uid_t) -> Result<Option<Passwd<S>>>
fn getpwuid<S: PwdGrpString>(&self, uid: uid_t) -> Result<Option<Passwd<S>>>
Look up a
passwd
entry by
uid,
returning strings as
SSource§fn getgrnam<S: PwdGrpString>(
&self,
name: impl AsRef<<S as Deref>::Target>,
) -> Result<Option<Group<S>>>
fn getgrnam<S: PwdGrpString>( &self, name: impl AsRef<<S as Deref>::Target>, ) -> Result<Option<Group<S>>>
Look up a
group
entry by
name,
returning strings as
SSource§fn getgrgid<S: PwdGrpString>(&self, gid: uid_t) -> Result<Option<Group<S>>>
fn getgrgid<S: PwdGrpString>(&self, gid: uid_t) -> Result<Option<Group<S>>>
Look up a
group
entry by
gid,
returning strings as
SSource§fn getresuid(&self) -> (uid_t, uid_t, uid_t)
fn getresuid(&self) -> (uid_t, uid_t, uid_t)
Get the current process’s
real, effective and saved set-uid Read more
Auto Trait Implementations§
impl Freeze for MockPwdGrpProvider
impl RefUnwindSafe for MockPwdGrpProvider
impl Send for MockPwdGrpProvider
impl Sync for MockPwdGrpProvider
impl Unpin for MockPwdGrpProvider
impl UnsafeUnpin for MockPwdGrpProvider
impl UnwindSafe for MockPwdGrpProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more