lib/api: Allow BindDN to exclude any username formatting (fixes #8899) (#8900)

This allows a syncthing instance to be locked to exactly 1 user without
needing search capability on the LDAP instance.
This commit is contained in:
Will Rouesnel
2023-05-10 07:52:02 +02:00
committed by GitHub
parent e136d11dce
commit b2fb2ef276
2 changed files with 30 additions and 1 deletions
+20
View File
@@ -45,3 +45,23 @@ func TestStaticAuthPasswordFail(t *testing.T) {
t.Fatalf("should fail auth")
}
}
func TestAuthLDAPSendsCorrectBindDNWithTemplate(t *testing.T) {
t.Parallel()
templatedDn := ldapTemplateBindDN("cn=%s,dc=some,dc=example,dc=com", "username")
expectedDn := "cn=username,dc=some,dc=example,dc=com"
if expectedDn != templatedDn {
t.Fatalf("ldapTemplateBindDN should be %s != %s", expectedDn, templatedDn)
}
}
func TestAuthLDAPSendsCorrectBindDNWithNoTemplate(t *testing.T) {
t.Parallel()
templatedDn := ldapTemplateBindDN("cn=fixedusername,dc=some,dc=example,dc=com", "username")
expectedDn := "cn=fixedusername,dc=some,dc=example,dc=com"
if expectedDn != templatedDn {
t.Fatalf("ldapTemplateBindDN should be %s != %s", expectedDn, templatedDn)
}
}