Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: request mapped attributes during LDAP test sign-in
Dannyf6e832df43c6
diff --git a/backend/plugin/idp/ldap/ldap.go b/backend/plugin/idp/ldap/ldap.goindex bd4d7cb3c1..cffb36a16b 100644--- a/backend/plugin/idp/ldap/ldap.go+++ b/backend/plugin/idp/ldap/ldap.go@@ -141,8 +141,12 @@ func (p *IdentityProvider) Authenticate(username, password string) (*storepb.Ide// attribute of the matched entry, returning them alongside the mapped user// info so admins can verify their field mapping against real directory data.func (p *IdentityProvider) TestAuthenticate(username, password string) (*storepb.IdentityProviderUserInfo, map[string]string, error) {- // A nil attribute list requests all user attributes (RFC 4511).- entry, err := p.searchAndBind(username, password, nil)+ // "*" requests all user attributes for the discovery view, but operational+ // attributes (e.g. OpenLDAP entryUUID) are only returned when named explicitly.+ // Append the mapped attributes so a mapping onto an operational attribute is+ // still returned here, matching what real Authenticate requests — otherwise the+ // test could report a mapped value as missing when sign-in would actually work.+ entry, err := p.searchAndBind(username, password, append([]string{"*"}, p.mappedAttributes()...))if err != nil {return nil, nil, err}diff --git a/backend/plugin/idp/ldap/ldap_test.go b/backend/plugin/idp/ldap/ldap_test.goindex 81c088e965..76d495027a 100644--- a/backend/plugin/idp/ldap/ldap_test.go+++ b/backend/plugin/idp/ldap/ldap_test.go@@ -129,7 +129,7 @@ func TestNewIdentityProvider(t *testing.T) {}}-func newMockServer(t *testing.T, uid, displayName, mail, phone string) (host string, port int) {+func newMockServer(t *testing.T, uid, displayName, mail, phone string) (host string, port int, searchAttrs *[][]string) {// localhostCert is a PEM-encoded TLS cert with SAN IPs// "127.0.0.1" and "[::1]", expiring at Jan 29 16:00:00 2084 GMT.// generated from src/crypto/tls:@@ -191,12 +191,19 @@ ZboOWVe3icTy64BT3OQhmg==ServerName: "127.0.0.1",}+ var searches [][]stringserver := ldapserver.NewServer()routes := ldapserver.NewRouteMux()routes.Bind(func(w ldapserver.ResponseWriter, _ *ldapserver.Message) {w.Write(ldapserver.NewBindResponse(ldapserver.LDAPResultSuccess))})- routes.Search(func(w ldapserver.ResponseWriter, _ *ldapserver.Message) {+ routes.Search(func(w ldapserver.ResponseWriter, m *ldapserver.Message) {+ req := m.GetSearchRequest()+ requested := make([]string, 0, len(req.Attributes()))+ for _, a := range req.Attributes() {+ requested = append(requested, string(a))+ }+ searches = append(searches, requested)e := ldapserver.NewSearchResultEntry(uid)e.AddAttribute("uid", message.AttributeValue(uid))e.AddAttribute("displayName", message.AttributeValue(displayName))@@ -220,7 +227,7 @@ ZboOWVe3icTy64BT3OQhmg==// Give a second for the server to starttime.Sleep(time.Second)- return "127.0.0.1", 10389+ return "127.0.0.1", 10389, &searches}func TestIdentityProvider(t *testing.T) {@@ -230,7 +237,7 @@ func TestIdentityProvider(t *testing.T) {testMail = "[email protected]"testPhone = "+14155550100")- host, port := newMockServer(t, testUID, testDisplayName, testMail, testPhone)+ host, port, searches := newMockServer(t, testUID, testDisplayName, testMail, testPhone)ldap, err := NewIdentityProvider(IdentityProviderConfig{Host: host,@@ -270,6 +277,15 @@ func TestIdentityProvider(t *testing.T) {"mail": testMail,"telephoneNumber": testPhone,}, attributes)++ // Authenticate requests only the mapped attributes; TestAuthenticate must also+ // request "*" so the discovery view is complete, while still naming the mapped+ // attributes so an operational-attribute mapping (e.g. entryUUID) is returned.+ require.Len(t, *searches, 2)+ authSearch, testSearch := (*searches)[0], (*searches)[1]+ assert.NotContains(t, authSearch, "*")+ assert.Subset(t, authSearch, []string{"uid", "displayName", "telephoneNumber"})+ assert.Subset(t, testSearch, []string{"*", "uid", "displayName", "telephoneNumber"})}func TestUserInfoFromEntry(t *testing.T) {