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 Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error)
Run creates an instance of the OpenLDAP container type
Example ¶
// runOpenLDAPContainer { ctx := context.Background() openldapContainer, err := openldap.Run(ctx, "bitnami/openldap:2.6.6") defer func() { if err := testcontainers.TerminateContainer(openldapContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // } state, err := openldapContainer.State(ctx) if err != nil { log.Printf("failed to get container state: %s", err) return } fmt.Println(state.Running)
Output: true
Example (Connect) ¶
// connectToOpenLdap { ctx := context.Background() openldapContainer, err := openldap.Run(ctx, "bitnami/openldap:2.6.6") defer func() { if err := testcontainers.TerminateContainer(openldapContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } connectionString, err := openldapContainer.ConnectionString(ctx) if err != nil { log.Printf("failed to get connection string: %s", err) return } client, err := ldap.DialURL(connectionString) if err != nil { log.Printf("failed to connect to LDAP server: %s", err) return } defer client.Close() // First bind with a read only user err = client.Bind("cn=admin,dc=example,dc=org", "adminpassword") if err != nil { log.Printf("failed to bind to LDAP server: %s", err) return } // 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.Printf("failed to search LDAP server: %s", err) return } if len(sr.Entries) != 1 { log.Print("User does not exist or too many entries returned") return } fmt.Println(sr.Entries[0].DN)
Output: cn=user01,ou=users,dc=example,dc=org
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the OpenLDAP container type
func (*OpenLDAPContainer) ConnectionString ¶
ConnectionString returns the connection string for the OpenLDAP container