ldap: test fixup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2023-03-02 15:44:11 +01:00
parent 7e12788c60
commit 1a14696a5c

View File

@ -36,19 +36,19 @@ impl Drop for GlauthServer {
} }
} }
fn authenticate(con: &LdapConnection, user: &str, pass: &str) -> Result<(), Error> { fn authenticate(con: &Connection, user: &str, pass: &str) -> Result<(), Error> {
proxmox_async::runtime::block_on(con.authenticate_user(user, pass)) proxmox_async::runtime::block_on(con.authenticate_user(user, pass))
} }
fn default_config() -> LdapConfig { fn default_config() -> Config {
LdapConfig { Config {
servers: vec!["localhost".into()], servers: vec!["localhost".into()],
port: Some(3893), port: Some(3893),
user_attr: "cn".into(), user_attr: "cn".into(),
base_dn: "dc=example,dc=com".into(), base_dn: "dc=example,dc=com".into(),
bind_dn: Some("cn=serviceuser,ou=svcaccts,dc=example,dc=com".into()), bind_dn: Some("cn=serviceuser,ou=svcaccts,dc=example,dc=com".into()),
bind_password: Some("password".into()), bind_password: Some("password".into()),
tls_mode: LdapConnectionMode::Ldap, tls_mode: ConnectionMode::Ldap,
verify_certificate: false, verify_certificate: false,
additional_trusted_certificates: None, additional_trusted_certificates: None,
certificate_store_path: Some("/etc/ssl/certs".into()), certificate_store_path: Some("/etc/ssl/certs".into()),
@ -60,7 +60,7 @@ fn default_config() -> LdapConfig {
fn test_authentication() -> Result<(), Error> { fn test_authentication() -> Result<(), Error> {
let _glauth = GlauthServer::new("tests/assets/glauth.cfg")?; let _glauth = GlauthServer::new("tests/assets/glauth.cfg")?;
let connection = LdapConnection::new(default_config()); let connection = Connection::new(default_config());
assert!(authenticate(&connection, "test1", "password").is_ok()); assert!(authenticate(&connection, "test1", "password").is_ok());
assert!(authenticate(&connection, "test2", "password").is_ok()); assert!(authenticate(&connection, "test2", "password").is_ok());
@ -76,12 +76,12 @@ fn test_authentication() -> Result<(), Error> {
fn test_authentication_via_ipv6() -> Result<(), Error> { fn test_authentication_via_ipv6() -> Result<(), Error> {
let _glauth = GlauthServer::new("tests/assets/glauth_v6.cfg")?; let _glauth = GlauthServer::new("tests/assets/glauth_v6.cfg")?;
let settings = LdapConfig { let settings = Config {
servers: vec!["[::1]".into()], servers: vec!["[::1]".into()],
..default_config() ..default_config()
}; };
let connection = LdapConnection::new(settings); let connection = Connection::new(settings);
assert!(authenticate(&connection, "test1", "password").is_ok()); assert!(authenticate(&connection, "test1", "password").is_ok());
@ -91,9 +91,9 @@ fn test_authentication_via_ipv6() -> Result<(), Error> {
#[test] #[test]
#[ignore] #[ignore]
fn test_authentication_via_ldaps() -> Result<(), Error> { fn test_authentication_via_ldaps() -> Result<(), Error> {
let settings = LdapConfig { let settings = Config {
port: Some(3894), port: Some(3894),
tls_mode: LdapConnectionMode::Ldaps, tls_mode: ConnectionMode::Ldaps,
verify_certificate: true, verify_certificate: true,
additional_trusted_certificates: Some(vec!["tests/assets/glauth.crt".into()]), additional_trusted_certificates: Some(vec!["tests/assets/glauth.crt".into()]),
..default_config() ..default_config()
@ -101,7 +101,7 @@ fn test_authentication_via_ldaps() -> Result<(), Error> {
let _glauth = GlauthServer::new("tests/assets/glauth.cfg")?; let _glauth = GlauthServer::new("tests/assets/glauth.cfg")?;
let connection = LdapConnection::new(settings); let connection = Connection::new(settings);
assert!(authenticate(&connection, "test1", "password").is_ok()); assert!(authenticate(&connection, "test1", "password").is_ok());
assert!(authenticate(&connection, "test1", "invalid").is_err()); assert!(authenticate(&connection, "test1", "invalid").is_err());
@ -112,14 +112,14 @@ fn test_authentication_via_ldaps() -> Result<(), Error> {
#[test] #[test]
#[ignore] #[ignore]
fn test_fallback() -> Result<(), Error> { fn test_fallback() -> Result<(), Error> {
let settings = LdapConfig { let settings = Config {
servers: vec!["invalid.host".into(), "localhost".into()], servers: vec!["invalid.host".into(), "localhost".into()],
..default_config() ..default_config()
}; };
let _glauth = GlauthServer::new("tests/assets/glauth.cfg")?; let _glauth = GlauthServer::new("tests/assets/glauth.cfg")?;
let connection = LdapConnection::new(settings); let connection = Connection::new(settings);
assert!(authenticate(&connection, "test1", "password").is_ok()); assert!(authenticate(&connection, "test1", "password").is_ok());
Ok(()) Ok(())
@ -130,7 +130,7 @@ fn test_fallback() -> Result<(), Error> {
fn test_search() -> Result<(), Error> { fn test_search() -> Result<(), Error> {
let _glauth = GlauthServer::new("tests/assets/glauth.cfg")?; let _glauth = GlauthServer::new("tests/assets/glauth.cfg")?;
let connection = LdapConnection::new(default_config()); let connection = Connection::new(default_config());
let params = SearchParameters { let params = SearchParameters {
attributes: vec!["cn".into(), "mail".into(), "sn".into()], attributes: vec!["cn".into(), "mail".into(), "sn".into()],