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
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
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>>>
S
Source§fn getpwuid<S: PwdGrpString>(&self, uid: uid_t) -> Result<Option<Passwd<S>>>
fn getpwuid<S: PwdGrpString>(&self, uid: uid_t) -> Result<Option<Passwd<S>>>
S
Source§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>>>
S
Source§fn getgrgid<S: PwdGrpString>(&self, gid: uid_t) -> Result<Option<Group<S>>>
fn getgrgid<S: PwdGrpString>(&self, gid: uid_t) -> Result<Option<Group<S>>>
S
Source§fn getresuid(&self) -> (uid_t, uid_t, uid_t)
fn getresuid(&self) -> (uid_t, uid_t, uid_t)
Auto Trait Implementations§
impl Freeze for MockPwdGrpProvider
impl RefUnwindSafe for MockPwdGrpProvider
impl Send for MockPwdGrpProvider
impl Sync for MockPwdGrpProvider
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes