test

package
v0.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package test runs tests against LDAP directories, OpenLDAP, 389 DS and SMB LDS, with a manager connected to each. Each directory is in a container which starts when a test first needs it, and is shared by the package's tests, until they've all run. They need docker, and are skipped with -short. LDAP_TEST_SERVER chooses some of them, separated by commas, such as "openldap,389ds".

Index

Constants

View Source
const ServerEnv = "LDAP_TEST_SERVER"

ServerEnv chooses the servers, by name, separated by commas

Variables

This section is empty.

Functions

func Attribute

func Attribute(t *testing.T, server Server, dn, name string) []string

Attribute returns the entry's values of the attribute, as the started server has them, read with go-ldap, not the manager, which hides some

func ForEach

func ForEach(t *testing.T, fn func(t *testing.T, ctx context.Context, server Server, manager *manager.Manager), opts ...manager.Opt)

ForEach runs the test against each chosen directory, as a subtest, with a new manager, bound as the server's user, with the options, which is disconnected after it. It's skipped with -short.

func Main

func Main(m *testing.M)

Main runs the tests, then stops the containers they started. It's called from a package's TestMain.

func Manager

func Manager(t *testing.T, ctx context.Context, server Server, opts ...manager.Opt) *manager.Manager

Manager returns a manager of the started server, bound as its user, with the options, which is disconnected when the test ends

func OU

func OU(t *testing.T, ctx context.Context, m *manager.Manager) string

OU creates an organizational unit for the test, with a random name, under the base DN, and returns its DN. It's deleted when the test ends, with the entries under it.

func Subschema

func Subschema(t *testing.T, server Server) (classes, attrs []string)

Subschema returns the definitions of the started server's object classes and attribute types, as it has them, read with go-ldap, not the manager

Types

type Fake

type Fake struct {
	sync.Mutex

	// When they're set, BeforeAdd and BeforeModify are called before an add
	// or modify of the DN is answered, and Stall stops a request of the
	// operation, such as ldap.ApplicationBindRequest, being answered
	BeforeAdd    func(dn string)
	BeforeModify func(dn string)
	Stall        func(op uint8, dn string) bool
	// contains filtered or unexported fields
}

Fake is an LDAP directory in memory, which answers binds, searches of one entry, by its DN, or of the entries directly under it, adds, modifies, deletes and password modifies, so tests can make a request stall, or another manager change something first, every time. It has no schema, filters, paging, renames or extended operations, so the directories in containers are for everything else.

func NewFake

func NewFake(t *testing.T, secure bool) *Fake

NewFake returns a directory listening on localhost, with TLS, whose certificate isn't trusted, when secure is true, which is closed when the test ends

func (*Fake) Connections

func (d *Fake) Connections() int

Connections returns how many connections the directory has accepted

func (*Fake) Drop

func (d *Fake) Drop()

Drop closes the connections the directory has accepted, as a directory which goes away does

func (*Fake) Entry

func (d *Fake) Entry(dn string) map[string][]string

Entry returns an entry's attributes, or nil

func (*Fake) Requests

func (d *Fake) Requests(op string) []string

Requests returns the requests of the operation, as their DNs: "bind", "search", "add", "modify", "delete", "password" or "whoami"

func (*Fake) Set

func (d *Fake) Set(dn string, attrs map[string][]string)

Set sets an entry's attributes

func (*Fake) URL

func (d *Fake) URL(scheme string) string

URL returns the directory's URL, with the user and password

type Server

type Server struct {
	Name         string
	Image        string
	TLSPort      string
	BaseDN       string
	BindDN       string
	BindPassword string
	UserDN       string
	GroupDN      string
	Env          map[string]string

	// URL is the ldaps URL of the server's container, when it's started.
	// Its certificate isn't trusted.
	URL string

	// ActiveDirectory is true when the directory is Active Directory, or
	// like it, whose users have the "user" class, and unicodePwd passwords
	ActiveDirectory bool

	// KeepsOldPassword is true when a user's old password still binds for
	// a while after it's changed, as Samba's "old password allowed period"
	// does, for an hour
	KeepsOldPassword bool

	// ConnectTimeout is how long the directory can take to accept a bind,
	// once its container has started
	ConnectTimeout time.Duration
	// contains filtered or unexported fields
}

Server is a directory which the tests run against

func Servers

func Servers(t *testing.T) []Server

Servers returns the servers which LDAP_TEST_SERVER names, or all of them, when it's not set

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL