-
-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
outposts/ldap: add more tests (#6188)
* outposts/ldap: add tests Signed-off-by: Jens Langhammer <[email protected]> * fix missing posixAccount Signed-off-by: Jens Langhammer <[email protected]> * attempt to expand attributes Signed-off-by: Jens Langhammer <[email protected]> * fix routing without base DN Signed-off-by: Jens Langhammer <[email protected]> * more logging Signed-off-by: Jens Langhammer <[email protected]> * remove our custom attribute filtering since this is done by the ldap library Signed-off-by: Jens Langhammer <[email protected]> * add test for schema Signed-off-by: Jens Langhammer <[email protected]> * fix tests Signed-off-by: Jens Langhammer <[email protected]> --------- Signed-off-by: Jens Langhammer <[email protected]>
- Loading branch information
Showing
8 changed files
with
96 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ldap_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"beryju.io/ldap" | ||
"github.com/stretchr/testify/assert" | ||
"goauthentik.io/api/v3" | ||
) | ||
|
||
func Test_UserEntry(t *testing.T) { | ||
pi := ProviderInstance() | ||
u := api.User{ | ||
Username: "foo", | ||
Name: "bar", | ||
} | ||
entry := pi.UserEntry(u) | ||
assert.Equal(t, "cn=foo,ou=users,dc=ldap,dc=goauthentik,dc=io", entry.DN) | ||
assert.Contains(t, entry.Attributes, &ldap.EntryAttribute{ | ||
Name: "cn", | ||
Values: []string{u.Username}, | ||
}) | ||
assert.Contains(t, entry.Attributes, &ldap.EntryAttribute{ | ||
Name: "displayName", | ||
Values: []string{u.Name}, | ||
}) | ||
} |
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,31 @@ | ||
package ldap_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"beryju.io/ldap" | ||
"github.com/stretchr/testify/assert" | ||
oldap "goauthentik.io/internal/outpost/ldap" | ||
) | ||
|
||
func ProviderInstance() *oldap.ProviderInstance { | ||
return &oldap.ProviderInstance{ | ||
BaseDN: "dc=ldap,dc=goauthentik,dc=io", | ||
UserDN: "ou=users,dc=ldap,dc=goauthentik,dc=io", | ||
VirtualGroupDN: "ou=virtual-groups,dc=ldap,dc=goauthentik,dc=io", | ||
GroupDN: "ou=groups,dc=ldap,dc=goauthentik,dc=io", | ||
} | ||
} | ||
|
||
func AssertLDAPAttributes(t *testing.T, attrs []*ldap.EntryAttribute, expected *ldap.EntryAttribute) { | ||
found := false | ||
for _, attr := range attrs { | ||
if attr.Name == expected.Name { | ||
assert.Equal(t, expected.Values, attr.Values) | ||
found = true | ||
} | ||
} | ||
if !found { | ||
t.Fatalf("Key %s not found in ldap attributes", expected.Name) | ||
} | ||
} |
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
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