Documentation
¶
Index ¶
- func WithAdminPassword(password string) testcontainers.CustomizeRequestOption
- func WithAdminUsername(username string) testcontainers.CustomizeRequestOption
- func WithInitialLdif(ldif string) testcontainers.CustomizeRequestOption
- func WithRoot(root string) testcontainers.CustomizeRequestOption
- type OpenLDAPContainer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAdminPassword ¶
func WithAdminPassword(password string) testcontainers.CustomizeRequestOption
WithAdminPassword sets the initial admin password of the user to be created when the container starts It is used in conjunction with WithAdminUsername to set a username and its password. It will set the admin password for OpenLDAP.
func WithAdminUsername ¶
func WithAdminUsername(username string) testcontainers.CustomizeRequestOption
WithAdminUsername sets the initial admin username to be created when the container starts It is used in conjunction with WithAdminPassword to set a username and its password. It will create the specified user with admin power.
func WithInitialLdif ¶
func WithInitialLdif(ldif string) testcontainers.CustomizeRequestOption
WithInitialLdif sets the initial ldif file to be loaded into the OpenLDAP container
Types ¶
type OpenLDAPContainer ¶
type OpenLDAPContainer struct { testcontainers.Container // contains filtered or unexported fields }
OpenLDAPContainer represents the OpenLDAP container type used in the module
func RunContainer ¶
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error)
RunContainer creates an instance of the OpenLDAP container type
Example ¶
// runOpenLDAPContainer { ctx := context.Background() openldapContainer, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) if err != nil { log.Fatalf("failed to start container: %s", err) } // Clean up the container defer func() { if err := openldapContainer.Terminate(ctx); err != nil { log.Fatalf("failed to terminate container: %s", err) } }() // } state, err := openldapContainer.State(ctx) if err != nil { log.Fatalf("failed to get container state: %s", err) // nolint:gocritic } fmt.Println(state.Running)
Output: true
Example (Connect) ¶
// connectToOpenLdap { ctx := context.Background() openldapContainer, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) if err != nil { log.Fatalf("failed to start container: %s", err) } // Clean up the container defer func() { if err := openldapContainer.Terminate(ctx); err != nil { log.Fatalf("failed to terminate container: %s", err) } }() connectionString, err := openldapContainer.ConnectionString(ctx) if err != nil { log.Fatalf("failed to get connection string: %s", err) // nolint:gocritic } client, err := ldap.DialURL(connectionString) if err != nil { log.Fatalf("failed to connect to LDAP server: %s", err) } defer client.Close() // First bind with a read only user err = client.Bind("cn=admin,dc=example,dc=org", "adminpassword") if err != nil { log.Fatalf("failed to bind to LDAP server: %s", err) } // Search for the given username searchRequest := ldap.NewSearchRequest( "dc=example,dc=org", ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, "(&(objectClass=organizationalPerson)(uid=user01))", []string{"dn"}, nil, ) sr, err := client.Search(searchRequest) if err != nil { log.Fatalf("failed to search LDAP server: %s", err) } if len(sr.Entries) != 1 { log.Fatal("User does not exist or too many entries returned") } fmt.Println(sr.Entries[0].DN)
Output: cn=user01,ou=users,dc=example,dc=org
func (*OpenLDAPContainer) ConnectionString ¶
ConnectionString returns the connection string for the OpenLDAP container