Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic ldif reader #49

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ldif/ldif.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
"encoding/base64"
"errors"
"fmt"
"gopkg.in/ldap.v2"
"io"
"io/ioutil"
"net/url"

"gopkg.in/ldap.v2"
// "os"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

"strconv"
"strings"
Expand Down Expand Up @@ -98,6 +99,9 @@ func Unmarshal(r io.Reader, l *LDIF) (err error) {
if len(line) == 0 && err == io.EOF {
return nil
}
if len(line) == 0 && len(lines) == 0 {
continue
}
lines = append(lines, line)
entry, perr := l.parseEntry(lines)
if perr != nil {
Expand Down
29 changes: 27 additions & 2 deletions ldif/ldif_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ldif_test

import (
"gopkg.in/ldap.v2/ldif"
"io/ioutil"
"os"
"testing"

"gopkg.in/ldap.v2/ldif"
)

var ldifRFC2849Example = `version: 1
Expand Down Expand Up @@ -181,4 +182,28 @@ func TestLDIFURL(t *testing.T) {
}
}

// vim: ts=4 sw=4 noexpandtab nolist
var ldifMultiBlankLines = `# Organization Units
dn: ou=users,dc=example,dc=com
objectClass: organizationalUnit
objectClass: top
ou: users


# searches for above empty line for dn but fails and errors out in this PR
# Even though this is a valid LDIF file for ldapadd
Copy link

@enochtsang enochtsang Aug 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looked a little familiar haha, these two comments aren't necessary anymore I don't think. Thanks for the fix!

dn: ou=groups,dc=example,dc=com
objectClass: organizationalUnit
objectClass: top
ou: groups
`

func TestLDIFMultiBlankLines(t *testing.T) {
l, err := ldif.Parse(ldifMultiBlankLines)
if err != nil {
t.Errorf("Failed to parse LDIF: %s", err)
}
ou := l.Entries[1].Entry.GetAttributeValue("ou")
if ou != "groups" {
t.Errorf("wrong ou in second entry: %s", ou)
}
}