Documentation
¶
Index ¶
- Constants
- Variables
- func ConnectToManagementInterface(tb testing.TB, managementInterface net.Listener, openVPNClient *openvpn.Client) (net.Conn, <-chan error, error)
- func ExpectMessage(tb testing.TB, conn net.Conn, reader *bufio.Reader, expectMessage string)
- func ExpectVersionAndReleaseHold(tb testing.TB, conn net.Conn, reader *bufio.Reader)
- func GetGIDOfFile(fileName string) (int, error)
- func GetPermissionsOfFile(fileName string) (string, error)
- func ReadLine(tb testing.TB, conn net.Conn, reader *bufio.Reader) string
- func SendAndExpectMessage(tb testing.TB, conn net.Conn, reader *bufio.Reader, ...)
- func SendMessagef(tb testing.TB, conn net.Conn, sendMessage string, args ...any)
- func SetupOpenVPNOAuth2Clients(ctx context.Context, tb testing.TB, conf config.Config, logger *slog.Logger, ...) (*oauth2.Client, *openvpn.Client)
- func SetupResourceServer(tb testing.TB, clientListener net.Listener, logger *slog.Logger, ...) (*httptest.Server, types.URL, config.OAuth2Client, error)
- func WaitUntilListening(tb testing.TB, network, address string) (net.Conn, error)
- type FakeOpenVPNClient
- type FakeStorage
- type Logger
- type MockRoundTripper
- type RoundTripperFunc
- type SyncBuffer
Constants ¶
const ( Password = "password" Secret = "0123456789101112" )
Variables ¶
Functions ¶
func ConnectToManagementInterface ¶ added in v1.23.0
func ConnectToManagementInterface(tb testing.TB, managementInterface net.Listener, openVPNClient *openvpn.Client) (net.Conn, <-chan error, error)
ConnectToManagementInterface establishes a connection to the given management interface and returns the accepted net.Conn and an error channel for the OpenVPN client.
func ExpectMessage ¶
ExpectMessage reads from the connection and compares the output with the expected message.
func ExpectVersionAndReleaseHold ¶
ExpectVersionAndReleaseHold performs the initial handshake with the mocked management interface. It checks for a version query and hold release.
func GetGIDOfFile ¶ added in v1.22.6
GetGIDOfFile returns the numeric group ID of the given file.
func GetPermissionsOfFile ¶ added in v1.22.6
GetPermissionsOfFile returns the permission bits of the given file as a string, for example "drwxr-xr-x".
func SendAndExpectMessage ¶
func SendAndExpectMessage(tb testing.TB, conn net.Conn, reader *bufio.Reader, sendMessage, expectMessage string)
SendAndExpectMessage sends a message and immediately validates the response.
func SendMessagef ¶ added in v1.23.1
SendMessagef sends a formatted string to the management interface connection.
func SetupOpenVPNOAuth2Clients ¶ added in v1.22.6
func SetupOpenVPNOAuth2Clients( ctx context.Context, tb testing.TB, conf config.Config, logger *slog.Logger, httpClient *http.Client, tokenStorage tokenstorage.Storage, ) (*oauth2.Client, *openvpn.Client)
SetupOpenVPNOAuth2Clients creates mocked OpenVPN and OAuth2 clients using the provided configuration.
Types ¶
type FakeOpenVPNClient ¶ added in v1.22.6
type FakeOpenVPNClient struct{}
FakeOpenVPNClient implements the parts of the OpenVPN client interface used in tests. It does not perform any actions.
func NewFakeOpenVPNClient ¶ added in v1.22.6
func NewFakeOpenVPNClient() FakeOpenVPNClient
NewFakeOpenVPNClient returns a FakeOpenVPNClient.
func (FakeOpenVPNClient) AcceptClient ¶ added in v1.22.6
func (FakeOpenVPNClient) AcceptClient(_ *slog.Logger, _ state.ClientIdentifier, _ bool, _ string)
AcceptClient is a no-op implementation of the real method.
func (FakeOpenVPNClient) DenyClient ¶ added in v1.22.6
func (FakeOpenVPNClient) DenyClient(_ *slog.Logger, _ state.ClientIdentifier, _ string)
DenyClient is a no-op implementation of the real method.
type FakeStorage ¶ added in v1.22.6
type FakeStorage struct{}
FakeStorage is a no-op implementation of the token storage interface used in tests.
func NewFakeStorage ¶ added in v1.22.6
func NewFakeStorage() *FakeStorage
NewFakeStorage returns a new FakeStorage instance.
func (FakeStorage) Close ¶ added in v1.24.0
func (FakeStorage) Close() error
Close is a no-op for FakeStorage.
func (FakeStorage) Delete ¶ added in v1.22.6
func (FakeStorage) Delete(_ string) error
Delete is a no-op for FakeStorage.
func (FakeStorage) Get ¶ added in v1.22.6
func (FakeStorage) Get(_ string) (string, error)
Get returns an empty token.
func (FakeStorage) Set ¶ added in v1.22.6
func (FakeStorage) Set(_, _ string) error
Set is a no-op for FakeStorage.
type Logger ¶
type Logger struct { *slog.Logger *SyncBuffer }
Logger combines slog.Logger with a synchronized buffer used in tests.
func NewTestLogger ¶
func NewTestLogger() *Logger
NewTestLogger returns a logger that stores all logs in memory so tests can inspect them.
func SetupMockEnvironment ¶
func SetupMockEnvironment(ctx context.Context, tb testing.TB, conf config.Config, rt http.RoundTripper, opConf *op.Config) ( config.Config, *openvpn.Client, net.Listener, *oauth2.Client, *httptest.Server, *http.Client, *Logger, )
SetupMockEnvironment sets up an OpenVPN management interface and a mock OIDC provider. It returns the adjusted configuration and helper instances used in tests.
type MockRoundTripper ¶
type MockRoundTripper struct {
// contains filtered or unexported fields
}
MockRoundTripper mocks selected HTTP calls while delegating everything else to the provided RoundTripper.
func NewMockRoundTripper ¶
func NewMockRoundTripper(rt http.RoundTripper) *MockRoundTripper
NewMockRoundTripper creates a MockRoundTripper. If rt is nil the default transport is used.
type RoundTripperFunc ¶
type RoundTripperFunc struct {
// contains filtered or unexported fields
}
RoundTripperFunc wraps an http.RoundTripper and allows a custom function to intercept each request.
func NewRoundTripperFunc ¶
func NewRoundTripperFunc(rt http.RoundTripper, fn func(rt http.RoundTripper, req *http.Request) (*http.Response, error)) *RoundTripperFunc
NewRoundTripperFunc returns a RoundTripperFunc that calls fn with the wrapped RoundTripper for each request.
type SyncBuffer ¶ added in v1.22.4
type SyncBuffer struct {
// contains filtered or unexported fields
}
SyncBuffer is a bytes.Buffer protected by a mutex for concurrent writes.
func (*SyncBuffer) String ¶ added in v1.22.4
func (s *SyncBuffer) String() string
String returns the buffered data as a string.