-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4126f95
commit 0194eb2
Showing
6 changed files
with
117 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,31 @@ | ||
package ldsview_test | ||
package ldsview | ||
|
||
import ( | ||
"testing" | ||
|
||
ldsview "github.com/kgoins/ldsview/pkg" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLdifParser_CountEntities(t *testing.T) { | ||
parser := ldsview.NewLdifParser(TESTFILE) | ||
var parser = NewLdifParser(TESTFILE) | ||
|
||
count, err := parser.CountEntities() | ||
if err != nil { | ||
t.Fatalf("unable to parse test file") | ||
} | ||
func TestLdifParser(t *testing.T) { | ||
|
||
if count != 5 { | ||
t.Fatalf("Failed to count entities") | ||
} | ||
} | ||
|
||
func TestLdifParser_CountEntitiesWithFilter(t *testing.T) { | ||
parser := ldsview.NewLdifParser(TESTFILE) | ||
t.Run("counts the ldif objects correctly", func(t *testing.T) { | ||
want := 2 | ||
got, err := parser.CountEntities() | ||
assert.Equal(t, want, got) | ||
assert.Nil(t, err) | ||
}) | ||
|
||
entityFilterStr := []string{"objectClass:=computer"} | ||
entityFilter, _ := ldsview.BuildEntityFilter(entityFilterStr) | ||
parser.SetEntityFilter(entityFilter) | ||
t.Run("counts the filtered ldif objects correctly", func(t *testing.T) { | ||
entityFilterStr := []string{"objectClass:=computer"} | ||
entityFilter, _ := BuildEntityFilter(entityFilterStr) | ||
parser.SetEntityFilter(entityFilter) | ||
|
||
count, err := parser.CountEntities() | ||
if err != nil { | ||
t.Fatalf("unable to parse test file") | ||
} | ||
want := 1 | ||
got, err := parser.CountEntities() | ||
assert.Equal(t, want, got) | ||
assert.Nil(t, err) | ||
}) | ||
|
||
if count != 1 { | ||
t.Fatalf("Failed to count filtered entities") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package ldsview_test | ||
package ldsview | ||
|
||
const TESTFILE string = "../testdata/test_users.ldif" | ||
const TESTFILE = "../testdata/test_users.ldif" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# extended LDIF | ||
# | ||
# LDAPv3 | ||
# base <DC=contoso,DC=com> with scope subtree | ||
# filter: (objectclass=*) | ||
# requesting: ALL | ||
# with pagedResults control: size=5000 | ||
# | ||
|
||
# MYUSR, ContosoUsers, contoso.com | ||
dn: CN=MYUSR,OU=ContosoUsers,DC=contoso,DC=com | ||
objectClass: top | ||
objectClass: person | ||
objectClass: organizationalPerson | ||
objectClass: user | ||
cn: MYUSR | ||
givenName: MYUSR | ||
distinguishedName: CN=MYUSR,OU=ContosoUsers,DC=contoso,DC=com | ||
instanceType: 4 | ||
whenCreated: 20120423175240.0Z | ||
whenChanged: 20190225044802.0Z | ||
displayName: MYUSR | ||
uSNCreated: 793245 | ||
memberOf: CN=vault_users,OU=Global,OU=Security,OU=Groups,DC=contoso,DC=com | ||
memberOf: CN=PWD Complexity,OU=Security,OU=Groups,DC=contoso,DC=com | ||
uSNChanged: 1076364863 | ||
name: MYUSR | ||
objectGUID:: 7OBfD10nQkSVYY8UHCV2aQ== | ||
userAccountControl: 66048 | ||
codePage: 0 | ||
countryCode: 0 | ||
pwdLastSet: 129857191591306845 | ||
primaryGroupID: 805306368 | ||
objectSid:: AQUAAAAAAAUVAAAAa9ZiBBbA6jKDPStVYiIMAA== | ||
accountExpires: 9223372036854775807 | ||
sAMAccountName: MYUSR | ||
sAMAccountType: 805306368 | ||
userPrincipalName: MYUSR@contoso.com | ||
lockoutTime: 0 | ||
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=contoso,DC=com | ||
dSCorePropagationData: 20190827201429.0Z | ||
dSCorePropagationData: 20190529140155.0Z | ||
dSCorePropagationData: 20190407190910.0Z | ||
dSCorePropagationData: 20190311163932.0Z | ||
dSCorePropagationData: 16010714223649.0Z | ||
lastLogonTimestamp: 130674899604502606 | ||
|
||
# MYPC, ContosoUsers, contoso.com | ||
dn: CN=MYPC,OU=ContosoUsers,DC=contoso,DC=com | ||
objectClass: top | ||
objectClass: computer | ||
objectClass: organizationalPerson | ||
objectClass: user | ||
cn: MYPC | ||
givenName: MYPC | ||
distinguishedName: CN=MYPC,OU=ContosoUsers,DC=contoso,DC=com | ||
instanceType: 4 | ||
whenCreated: 20120423175240.0Z | ||
whenChanged: 20190225044802.0Z | ||
displayName: MYPC | ||
uSNCreated: 793245 | ||
memberOf: CN=vault_users,OU=Global,OU=Security,OU=Groups,DC=contoso,DC=com | ||
memberOf: CN=PWD Complexity,OU=Security,OU=Groups,DC=contoso,DC=com | ||
uSNChanged: 1076364863 | ||
name: MYPC | ||
objectGUID:: 7OBfD10nQkSVYY8UHCV2aQ== | ||
userAccountControl: 66048 | ||
codePage: 0 | ||
countryCode: 0 | ||
pwdLastSet: 129857191591306845 | ||
primaryGroupID: 805306368 | ||
objectSid:: AQUAAAAAAAUVAAAAa9ZiBBbA6jKDPStVYiIMAA== | ||
accountExpires: 9223372036854775807 | ||
sAMAccountName: MYPC | ||
sAMAccountType: 805306368 | ||
userPrincipalName: MYPC@contoso.com | ||
lockoutTime: 0 | ||
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=contoso,DC=com | ||
dSCorePropagationData: 20190827201429.0Z | ||
dSCorePropagationData: 20190529140155.0Z | ||
dSCorePropagationData: 20190407190910.0Z | ||
dSCorePropagationData: 20190311163932.0Z | ||
dSCorePropagationData: 16010714223649.0Z | ||
lastLogonTimestamp: 130674899604502606 | ||
|