lldap/server/tests/common/auth.rs

28 lines
939 B
Rust
Raw Normal View History

2023-04-10 21:38:07 +00:00
use crate::common::env;
use reqwest::blocking::Client;
pub fn get_token(client: &Client) -> String {
let username = env::admin_dn();
let password = env::admin_password();
let base_url = env::http_url();
let response = client
.post(format!("{base_url}/auth/simple/login"))
.header(reqwest::header::CONTENT_TYPE, "application/json")
.body(
serde_json::to_string(&lldap_auth::login::ClientSimpleLoginRequest {
2023-04-10 22:35:46 +00:00
username,
password,
2023-04-10 21:38:07 +00:00
})
.expect("Failed to encode the username/password as json to log in"),
)
.send()
.expect("Failed to send auth request")
.error_for_status()
.expect("Auth attempt failed");
serde_json::from_str::<lldap_auth::login::ServerLoginResponse>(
&response.text().expect("Failed to get response as text"),
)
.expect("Failed to parse json")
.token
}