testutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockDialer

func NewMockDialer() func(ctx context.Context, network, addr string) (*MockLDAPConn, error)

NewMockDialer creates a dialer function that returns mock connections

func SetupTestUsersAndGroups

func SetupTestUsersAndGroups(mock *MockLDAPConn)

SetupTestUsersAndGroups creates standard test data for mock LDAP connections

Types

type AddCall

type AddCall struct {
	Request *ldap.AddRequest
	Error   error
}

AddCall records an add operation

type BindCall

type BindCall struct {
	Username string
	Password string
	Error    error
}

BindCall records a bind operation

type DelCall

type DelCall struct {
	Request *ldap.DelRequest
	Error   error
}

DelCall records a delete operation

type MockGroup

type MockGroup struct {
	DN          string
	CN          string
	Description string
	Members     []string
}

MockGroup represents a mock LDAP group

type MockLDAPConn

type MockLDAPConn struct {

	// Configuration
	BindFunc             func(username, password string) error
	SearchFunc           func(req *ldap.SearchRequest) (*ldap.SearchResult, error)
	SearchWithPagingFunc func(req *ldap.SearchRequest, pageSize uint32) (*ldap.SearchResult, error)
	ModifyFunc           func(req *ldap.ModifyRequest) error
	AddFunc              func(req *ldap.AddRequest) error
	DelFunc              func(req *ldap.DelRequest) error
	CloseFunc            func() error

	// State tracking
	BindCalls   []BindCall
	SearchCalls []SearchCall
	ModifyCalls []ModifyCall
	AddCalls    []AddCall
	DelCalls    []DelCall
	Closed      bool

	// Default data
	Users              map[string]*MockUser
	Groups             map[string]*MockGroup
	DefaultSearchLimit int
	// contains filtered or unexported fields
}

MockLDAPConn is a comprehensive mock implementation of the LDAP connection interface

func NewMockLDAPConn

func NewMockLDAPConn() *MockLDAPConn

NewMockLDAPConn creates a new mock LDAP connection with default behavior

func (*MockLDAPConn) Add

func (m *MockLDAPConn) Add(req *ldap.AddRequest) error

Add implements ldap.Conn interface

func (*MockLDAPConn) AddGroup

func (m *MockLDAPConn) AddGroup(group *MockGroup)

AddGroup adds a group to the mock data

func (*MockLDAPConn) AddUser

func (m *MockLDAPConn) AddUser(user *MockUser)

AddUser adds a user to the mock data

func (*MockLDAPConn) Bind

func (m *MockLDAPConn) Bind(username, password string) error

Bind implements ldap.Conn interface

func (*MockLDAPConn) Close

func (m *MockLDAPConn) Close() error

Close implements ldap.Conn interface

func (*MockLDAPConn) Compare

func (m *MockLDAPConn) Compare(dn, attribute, value string) (bool, error)

Compare performs an LDAP compare operation (mock implementation)

func (*MockLDAPConn) Del

func (m *MockLDAPConn) Del(req *ldap.DelRequest) error

Del implements ldap.Conn interface

func (*MockLDAPConn) DirSync

func (m *MockLDAPConn) DirSync(searchRequest *ldap.SearchRequest, flags, maxAttrCount int64, cookie []byte) (*ldap.SearchResult, error)

DirSync performs a directory synchronization search (not implemented in mock)

func (*MockLDAPConn) DirSyncAsync

func (m *MockLDAPConn) DirSyncAsync(ctx context.Context, searchRequest *ldap.SearchRequest, bufferSize int, flags, maxAttrCount int64, cookie []byte) ldap.Response

DirSyncAsync performs an asynchronous directory synchronization search (not implemented in mock)

func (*MockLDAPConn) GetBindCallCount

func (m *MockLDAPConn) GetBindCallCount() int

GetBindCallCount returns the number of bind calls made

func (*MockLDAPConn) GetSearchCallCount

func (m *MockLDAPConn) GetSearchCallCount() int

GetSearchCallCount returns the number of search calls made

func (*MockLDAPConn) Modify

func (m *MockLDAPConn) Modify(req *ldap.ModifyRequest) error

Modify implements ldap.Conn interface

func (*MockLDAPConn) Reset

func (m *MockLDAPConn) Reset()

Reset clears all recorded calls

func (*MockLDAPConn) Search

func (m *MockLDAPConn) Search(req *ldap.SearchRequest) (*ldap.SearchResult, error)

Search implements ldap.Conn interface

func (*MockLDAPConn) SearchWithPaging

func (m *MockLDAPConn) SearchWithPaging(req *ldap.SearchRequest, pageSize uint32) (*ldap.SearchResult, error)

SearchWithPaging implements ldap.Conn interface

func (*MockLDAPConn) SetBindError

func (m *MockLDAPConn) SetBindError(err error)

SetBindError sets a specific error for bind operations

func (*MockLDAPConn) SetSearchError

func (m *MockLDAPConn) SetSearchError(err error)

SetSearchError sets a specific error for search operations

func (*MockLDAPConn) SetSearchResult

func (m *MockLDAPConn) SetSearchResult(result *ldap.SearchResult)

SetSearchResult sets a specific result for search operations

type MockUser

type MockUser struct {
	DN             string
	CN             string
	SAMAccountName string
	Mail           string
	Description    string
	Groups         []string
	Password       string
	Enabled        bool
}

MockUser represents a mock LDAP user

type ModifyCall

type ModifyCall struct {
	Request *ldap.ModifyRequest
	Error   error
}

ModifyCall records a modify operation

type SearchCall

type SearchCall struct {
	Request *ldap.SearchRequest
	Result  *ldap.SearchResult
	Error   error
}

SearchCall records a search operation

Jump to

Keyboard shortcuts

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