From b35a9c9413a9fd39e1b2e902a293912c628aa0c0 Mon Sep 17 00:00:00 2001 From: Hiroyuki Wada Date: Mon, 27 Sep 2021 11:13:06 +0900 Subject: [PATCH] fix: runtime panic error when association replacement with empty --- go.mod | 2 +- go.sum | 2 + integration_test.go | 100 ++++++++++++++++++++++++++++++++++++++++++++ repo_hybrid.go | 6 ++- 4 files changed, 108 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 70e9675..60d75e8 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/jsimonetti/pwscheme v0.0.0-20160922125227-76804708ecad github.com/lib/pq v1.10.3 github.com/openstandia/goldap/message v0.0.0-20191227184744-b5528a3af20f - github.com/openstandia/ldapserver v0.0.0-20201119170447-bba3b0e7edad + github.com/openstandia/ldapserver v0.0.0-20210927020601-ef76358cbc4f golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d ) diff --git a/go.sum b/go.sum index 79bcbef..32c3b08 100644 --- a/go.sum +++ b/go.sum @@ -24,6 +24,8 @@ github.com/openstandia/goldap/message v0.0.0-20191227184744-b5528a3af20f h1:TSRC github.com/openstandia/goldap/message v0.0.0-20191227184744-b5528a3af20f/go.mod h1:RQfGYY+kPtrURUIm38HydsiwWCcozfzbFs7FRnzkx04= github.com/openstandia/ldapserver v0.0.0-20201119170447-bba3b0e7edad h1:/umnpqbw7xxzN+PoVxGN9136DzRhm39pGkH8/cMfpmw= github.com/openstandia/ldapserver v0.0.0-20201119170447-bba3b0e7edad/go.mod h1:X82folgu0A/IROMFz9VA4HzFT59ZR0MZ9uLkA0VcGKI= +github.com/openstandia/ldapserver v0.0.0-20210927020601-ef76358cbc4f h1:GWhSrGgPB6JCEXgVK1ctZNVO624a35Mqj2F+PPj3b5E= +github.com/openstandia/ldapserver v0.0.0-20210927020601-ef76358cbc4f/go.mod h1:X82folgu0A/IROMFz9VA4HzFT59ZR0MZ9uLkA0VcGKI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM= golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/integration_test.go b/integration_test.go index f7bf494..5f86beb 100644 --- a/integration_test.go +++ b/integration_test.go @@ -1395,6 +1395,106 @@ func TestAssociation(t *testing.T) { runTestCases(t, tcs) } +func TestAssociationWithCustomSchema(t *testing.T) { + customSchema = []string{ + "objectClasses: ( 2.5.6.9 NAME 'groupOfNames' DESC 'RFC2256: a group of names (DNs)' SUP top STRUCTURAL MUST cn MAY ( businessCategory $ seeAlso $ owner $ ou $ o $ description $ member $ uniqueMember $ displayName ) )", + } + testServer.LoadSchema() + defer func() { + customSchema = []string{} + testServer.LoadSchema() + }() + + type A []string + type M map[string][]string + + tcs := []Command{ + Conn{}, + Bind{"cn=Manager", "secret", &AssertResponse{}}, + AddDC("example", "dc=com"), + AddOU("Groups"), + AddOU("Users"), + Add{ + "uid=user1", "ou=Users", + M{ + "objectClass": A{"inetOrgPerson"}, + "cn": A{"user1"}, + "sn": A{"user1"}, + "userPassword": A{SSHA("password1")}, + }, + &AssertEntry{}, + }, + Add{ + "cn=A1", "ou=Groups", + M{ + "objectClass": A{"groupOfNames"}, + }, + &AssertEntry{ + expectAttrs: M{ + "member": A{}, + }, + }, + }, + ModifyAdd{ + "cn=A1", "ou=Groups", + M{ + "member": A{ + "uid=user1,ou=Users," + testServer.GetSuffix(), + }, + }, + &AssertEntry{ + expectAttrs: M{ + "member": A{ + "uid=user1,ou=Users," + testServer.GetSuffix(), + }, + }, + }, + }, + ModifyDelete{ + "cn=A1", "ou=Groups", + M{ + "member": A{ + "uid=user1,ou=Users," + testServer.GetSuffix(), + }, + }, + &AssertEntry{ + expectAttrs: M{ + "member": A{}, + }, + }, + }, + ModifyAdd{ + "cn=A1", "ou=Groups", + M{ + "member": A{ + "uid=user1,ou=Users," + testServer.GetSuffix(), + }, + }, + &AssertEntry{ + expectAttrs: M{ + "member": A{ + "uid=user1,ou=Users," + testServer.GetSuffix(), + }, + }, + }, + }, + // Test case for replacement + ModifyReplace{ + "cn=A1", "ou=Groups", + M{ + "member": A{}, + }, + &AssertEntry{ + expectAttrs: M{ + "member": A{}, + }, + }, + }, + } + + runTestCases(t, tcs) +} + func TestSearchByAssociation(t *testing.T) { type A []string type M map[string][]string diff --git a/repo_hybrid.go b/repo_hybrid.go index 7977cbc..1f2644d 100644 --- a/repo_hybrid.go +++ b/repo_hybrid.go @@ -2330,7 +2330,11 @@ func (r *HybridRepository) resolveDNMap(tx *sqlx.Tx, dnMap map[string]StringSet) func (r *HybridRepository) calcAssociationDiff(tx *sqlx.Tx, entry *ModifyEntry, attrName string, addAssociation, delAssociation map[string][]int64) error { if old, ok := entry.old[attrName]; ok { - add, del := diffDN(old.Norm(), entry.attributes[attrName].Norm()) + var newMember []interface{} + if newSV, ok := entry.attributes[attrName]; ok { + newMember = newSV.Norm() + } + add, del := diffDN(old.Norm(), newMember) addMember, err := r.dnArrayToIDArray(tx, map[string][]interface{}{attrName: add}, attrName) if err != nil {