Skip to content

Commit

Permalink
fixed title builder and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoins committed Mar 23, 2021
1 parent 3087019 commit 891d7a5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/ldif_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBuildEntities(t *testing.T) {
Expand All @@ -30,3 +31,15 @@ func TestBuildEntities(t *testing.T) {
assert.Equal(t, 3, counter.c)
})
}

func TestBuildEntityWithEscapeChar(t *testing.T) {
rq := require.New(t)
var parser = NewLdifParser("../testdata/test_user_escape_char.ldif")

user, err := parser.BuildEntity("sAMAccountName", "myuser")
rq.NoError(err)
rq.False(user.IsEmpty())

_, worked := user.GetDN()
rq.True(worked)
}
14 changes: 13 additions & 1 deletion pkg/title_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@ func buildTitleObj(objParts []string) (string, error) {
return strings.Join(objComponents, ", "), nil
}

func splitDN(dnStr string) []string {
escSeq := "++"
dnClean := strings.ReplaceAll(dnStr, `\,`, escSeq)
dnParts := strings.Split(dnClean, ",")

for i := range dnParts {
dnParts[i] = strings.ReplaceAll(dnParts[i], escSeq, `\,`)
}

return dnParts
}

func BuildTitleLine(entity Entity) (string, error) {
dn, dnFound := entity.GetDN()
if !dnFound {
return "", errors.New("Unable to find DN in entity")
}

dnParts := strings.Split(dn.Value.GetSingleValue(), ",")
dnParts := splitDN(dn.Value.GetSingleValue())

domainParts := []string{}
objParts := []string{}
Expand Down
19 changes: 19 additions & 0 deletions pkg/title_builder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ldsview

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestBuildTitles(t *testing.T) {
rq := require.New(t)
var parser = NewLdifParser("../testdata/test_user_escape_char.ldif")

user, err := parser.BuildEntity("sAMAccountName", "myuser")
rq.NoError(err)

title, err := BuildTitleLine(user)
rq.NoError(err)
rq.NotEmpty(title)
}

0 comments on commit 891d7a5

Please sign in to comment.