2023-04-10 21:38:07 +00:00
|
|
|
use crate::common::{
|
|
|
|
auth::get_token,
|
|
|
|
fixture::{new_id, LLDAPFixture, User},
|
|
|
|
graphql::{post, ListUsers},
|
|
|
|
};
|
|
|
|
use reqwest::blocking::ClientBuilder;
|
2023-04-07 19:56:23 +00:00
|
|
|
use serial_test::file_serial;
|
2023-04-10 21:38:07 +00:00
|
|
|
use std::collections::HashSet;
|
2023-04-07 19:56:23 +00:00
|
|
|
mod common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[file_serial]
|
|
|
|
fn list_users() {
|
|
|
|
let mut fixture = LLDAPFixture::new();
|
2023-04-10 21:38:07 +00:00
|
|
|
let prefix = "graphql-list_users-";
|
|
|
|
let user1_name = new_id(Some(prefix));
|
|
|
|
let user2_name = new_id(Some(prefix));
|
|
|
|
let user3_name = new_id(Some(prefix));
|
|
|
|
let group1_name = new_id(Some(prefix));
|
|
|
|
let group2_name = new_id(Some(prefix));
|
2023-04-07 19:56:23 +00:00
|
|
|
let initial_state = vec![
|
2023-04-10 21:38:07 +00:00
|
|
|
User::new(&user1_name, vec![&group1_name]),
|
|
|
|
User::new(&user2_name, vec![&group1_name, &group2_name]),
|
|
|
|
User::new(&user3_name, vec![]),
|
2023-04-07 19:56:23 +00:00
|
|
|
];
|
|
|
|
fixture.load_state(&initial_state);
|
|
|
|
|
|
|
|
let client = ClientBuilder::new()
|
|
|
|
.connect_timeout(std::time::Duration::from_secs(2))
|
|
|
|
.timeout(std::time::Duration::from_secs(5))
|
|
|
|
.redirect(reqwest::redirect::Policy::none())
|
|
|
|
.build()
|
|
|
|
.expect("failed to make http client");
|
2023-04-10 21:38:07 +00:00
|
|
|
let token = get_token(&client);
|
|
|
|
let result = post::<ListUsers>(&client, &token, common::graphql::list_users::Variables {})
|
2023-04-07 19:56:23 +00:00
|
|
|
.expect("failed to list users");
|
|
|
|
let users: HashSet<String> = result.users.iter().map(|user| user.id.clone()).collect();
|
2023-04-10 21:38:07 +00:00
|
|
|
assert!(users.contains(&user1_name));
|
|
|
|
assert!(users.contains(&user2_name));
|
|
|
|
assert!(users.contains(&user3_name));
|
2023-04-07 19:56:23 +00:00
|
|
|
}
|