Skip to content

Commit

Permalink
Added a test and changed README.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Nov 11, 2023
1 parent ad86321 commit 185c84d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: |
sudo apt update && sudo apt install -y libnss-wrapper
- uses: Swatinem/rust-cache@v2
- name: Test
env:
NSS_WRAPPER_PASSWD: contrib/fixtures/passwd
NSS_WRAPPER_GROUP: contrib/fixtures/group
run: |
cargo test
LD_PRELOAD=libnss_wrapper.so cargo test --features nsswrapper nsswrapper_
build:
strategy:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: |
sudo apt update && sudo apt install -y libnss-wrapper
- uses: Swatinem/rust-cache@v2
- name: Test
env:
NSS_WRAPPER_PASSWD: contrib/fixtures/passwd
NSS_WRAPPER_GROUP: contrib/fixtures/group
run: |
cargo test
LD_PRELOAD=libnss_wrapper.so cargo test --features nsswrapper nsswrapper_
build:
strategy:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/tip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: |
sudo apt update && sudo apt install -y libnss-wrapper
- uses: Swatinem/rust-cache@v2
- name: Test
env:
NSS_WRAPPER_PASSWD: contrib/fixtures/passwd
NSS_WRAPPER_GROUP: contrib/fixtures/group
run: |
cargo test
LD_PRELOAD=libnss_wrapper.so cargo test --features nsswrapper nsswrapper_
build:
strategy:
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ authors = ["Antoine POPINEAU <[email protected]>"]
edition = "2018"
build = "build.rs"

[features]
default = []
nsswrapper = []

[dependencies]
chrono = { version = "^0.4", features = ["unstable-locales"] }
crossterm = { version = "^0.27", features = ["event-stream"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Note that, by default, all commands are prefixed with `setsid` to completely det

### User menu

Optionally, a user can be selected from a menu instead of typing out their name, with the `--user-menu` option, this will present all users present in `/etc/passwd` at the time `tuigreet` was run, with a UID within the acceptable range. The values for the minimum and maximum UIDs are selected as follows, for each value:
Optionally, a user can be selected from a menu instead of typing out their name, with the `--user-menu` option, this will present all users returned by NSS at the time `tuigreet` was run, with a UID within the acceptable range. The values for the minimum and maximum UIDs are selected as follows, for each value:

* A user-provided value, through `--user-menu-min-uid` or `--user-menu-max-uid`;
* **Or**, the available values for `UID_MIN` or `UID_MAX` from `/etc/login.defs`;
Expand Down
Empty file added contrib/fixtures/group
Empty file.
4 changes: 4 additions & 0 deletions contrib/fixtures/passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root:x:0:0::/root:/bin/bash
joe:x:1000:1000:Joe:/home/joe:/bin/bash
bob:x:1500:1500::/home/bob:/bin/zsh
postgres:x:2100:2100::/srv/postgresql:/usr/bin/nologin
2 changes: 1 addition & 1 deletion src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl Greeter {
}

// Parses command line arguments to configured the software accordingly.
async fn parse_options(&mut self) {
pub async fn parse_options(&mut self) {
let opts = Greeter::options();

self.config = match opts.parse(env::args().collect::<Vec<String>>()) {
Expand Down
17 changes: 17 additions & 0 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,20 @@ pub fn capslock_status() -> bool {
Err(_) => false,
}
}

#[cfg(feature = "nsswrapper")]
#[cfg(test)]
mod nsswrapper_tests {
#[test]
fn nsswrapper_get_users_from_nss() {
use super::get_users;

let users = get_users(1000, 2000);

assert_eq!(users.len(), 2);
assert_eq!(users[0].username, "joe");
assert_eq!(users[0].name, Some("Joe".to_string()));
assert_eq!(users[1].username, "bob");
assert_eq!(users[1].name, None);
}
}

0 comments on commit 185c84d

Please sign in to comment.