# README
gldap.testdirectory
The testdirectory
package provides an in-memory test LDAP service with support
for capabilities which make writing tests that depend on an LDAP service much
easier.
testdirectory
is also a great working example of how you can use gldap
to build a custom
ldap server to meet your specific needs.
Example:
// this example demonstrates how can start a test directory for your
// unit tests which will automatically stop when the test is complete.
func TestDirectory_SimpleBindResponse(t *testing.T) {
// start a test directory running ldaps on an available free port (defaults)
// that allows anon binds (a default override)
td := testdirectory.Start(t,
testdirectory.WithDefaults(&testdirectory.Defaults{AllowAnonymousBind: true}),
)
// create some test new user entries (using defaults for ou, password, etc)
users := testdirectory.NewUsers(t, []string{"alice", "bob"})
// set the test directories user entries
td.SetUsers(users...)
}
# Functions
FreePort just returns an available free localhost port.
supports WithMTLS.
NewGroup creates a group entry.
NewLogger makes a new TestingLogger.
NewMemberOf creates memberOf attributes which can be assigned to user entries.
NewUsers creates user entries.
Start creates and starts a running Directory ldap server.
WithDefaults provides an option to provide a set of defaults to Directory.Start(...) which make it much more composable.
No description provided by the author
WithHost provides an optional hostname for the directory.
WithLogger provides the optional logger for the directory.
WithMembersOf specifies optional memberOf attributes for user entries.
WithMTLS provides the option to use mTLS for the directory.
WithNoTLS provides the option to not use TLS for the directory.
WithPort provides an optional port for the directory.
WithTokenGroups specifies optional test tokenGroups SID attributes for user entries.
# Constants
DefaultGroupAttr for the ClientConfig.GroupAttr.
DefaultGroupDN defines a default base distinguished name to use when searching for groups for the Directory.
DefaultUserAttr is the "username" attribute of the entry's DN and is typically either the cn in ActiveDirectory or uid in openLDAP (default: cn).
DefaultUserDN defines a default base distinguished name to use when searching for users for the Directory.
# Structs
Defaults define a type for composing all the defaults for Directory.Start(...).
Directory is a local ldap directory that supports test ldap capabilities which makes writing tests much easier.
Logger defines a logger that will implement the TestingT interface so it can be used with Directory.Start(...) as its t TestingT parameter.
# Interfaces
CleanupT defines an single function interface for a testing.Cleanup(func()).
HelperT defines a single function interface for a testing.Helper().
InfofT defines a single function interface for a Info(format string, args ...interface{}).
TestingT defines a very slim interface required by a Directory and any test functions it uses.
# Type aliases
Option defines a common functional options type which can be used in a variadic parameter pattern.