Skip to content

Commit

Permalink
Merge pull request #27 from openstandia/fix
Browse files Browse the repository at this point in the history
fix: runtime panic error when association replacement with empty
  • Loading branch information
wadahiro authored Sep 27, 2021
2 parents 73f577e + b35a9c9 commit 8386036
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
100 changes: 100 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion repo_hybrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8386036

Please sign in to comment.