mirror of
https://github.com/ViViDboarder/bitwarden_rs_ldap.git
synced 2024-11-22 11:16:27 +00:00
added test configurations
This commit is contained in:
parent
0b25b61caf
commit
60b8e0059c
23
Makefile
23
Makefile
@ -56,6 +56,29 @@ itest-stop:
|
||||
.PHONY: itest
|
||||
itest: itest-up itest-run itest-stop
|
||||
|
||||
# Run bootstrapped integration test for anonymous bind
|
||||
.PHONY: itest-up-anon
|
||||
itest-up-anon:
|
||||
docker compose -f docker-compose.yml \
|
||||
-f itest/docker-compose.itest.yml \
|
||||
build
|
||||
docker compose -f docker-compose.yml \
|
||||
-f itest/docker-compose.itest.yml \
|
||||
up -d vaultwarden ldap
|
||||
|
||||
.PHONY: itest-run-anon
|
||||
itest-run-anon:
|
||||
docker compose -f docker-compose.yml \
|
||||
-f itest/docker-compose.itest.yml \
|
||||
run ldap_sync
|
||||
|
||||
.PHONY: itest-stop-anon
|
||||
itest-stop-anon:
|
||||
docker compose stop
|
||||
|
||||
.PHONY: itest-anon
|
||||
itest: itest-up-anon itest-run-anon itest-stop-anon
|
||||
|
||||
# Run bootstrapped integration test using env for config
|
||||
.PHONY: itest-env
|
||||
itest-env:
|
||||
|
20
itest/docker-compose.itest-anon-env.yml
Normal file
20
itest/docker-compose.itest-anon-env.yml
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
services:
|
||||
ldap_sync:
|
||||
environment:
|
||||
CONFIG_PATH: ""
|
||||
APP_VAULTWARDEN_URL: "http://vaultwarden:80"
|
||||
APP_VAULTWARDEN_ADMIN_TOKEN: "admin"
|
||||
APP_LDAP_HOST: "ldap"
|
||||
# APP_LDAP_BIND_DN: "cn=admin,dc=example,dc=org"
|
||||
# APP_LDAP_BIND_PASSWORD: "admin"
|
||||
APP_LDAP_SEARCH_BASE_DN: "dc=example,dc=org"
|
||||
APP_LDAP_SEARCH_FILTER: "(&(objectClass=*)(uid=*))"
|
||||
APP_LDAP_SYNC_LOOP: "false"
|
||||
|
||||
vaultwarden: {}
|
||||
|
||||
ldap:
|
||||
command: ["--copy-service"]
|
||||
volumes:
|
||||
- ./itest/50-seed-user.ldif:/container/service/slapd/assets/config/bootstrap/ldif/custom/50-seed-user.ldif
|
12
itest/docker-compose.itest-anon.yml
Normal file
12
itest/docker-compose.itest-anon.yml
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
services:
|
||||
ldap_sync:
|
||||
volumes:
|
||||
- ./itest/config-anon.toml:/config.toml:ro
|
||||
|
||||
vaultwarden: {}
|
||||
|
||||
ldap:
|
||||
command: ["--copy-service"]
|
||||
volumes:
|
||||
- ./itest/50-seed-user.ldif:/container/service/slapd/assets/config/bootstrap/ldif/custom/50-seed-user.ldif
|
14
src/main.rs
14
src/main.rs
@ -85,11 +85,19 @@ fn ldap_client(
|
||||
let mut ldap = LdapConn::with_settings(settings, ldap_url.as_str())
|
||||
.context("Failed to connect to LDAP server")?;
|
||||
|
||||
if bind_dn.is_some() && bind_pw.is_some() {
|
||||
ldap.simple_bind(&bind_dn.unwrap(), &bind_pw.unwrap())
|
||||
.context("Could not bind to LDAP server")?;
|
||||
match (bind_dn, bind_pw) {
|
||||
(None, None) => println!("Anonymously binding"),
|
||||
(Some(bind_dn), Some(bind_pw)) => {
|
||||
println!("Attempting to bind");
|
||||
ldap.simple_bind(&bind_dn, &bind_pw)
|
||||
.context("Could nott bind to LDAP server")?;
|
||||
}
|
||||
|
||||
// Invalid authentication paths
|
||||
(None, Some(_)) => Err(anyhow::anyhow!("Unable to bind without username"))?,
|
||||
(Some(_), None) => Err(anyhow::anyhow!("Unable to bind without username"))?,
|
||||
};
|
||||
|
||||
Ok(ldap)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user