test

package
v0.13.7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 38 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// ServerKeyFile is the name of the file holding the matrix server private key.
	ServerKeyFile = "server_key.pem"
	// TLSCertFile is the name of the file holding the TLS certificate used for federation.
	TLSCertFile = "tls_cert.pem"
	// TLSKeyFile is the name of the file holding the TLS key used for federation.
	TLSKeyFile = "tls_key.pem"
)

Variables

View Source
var (

	// private keys that tests can use
	PrivateKeyA = ed25519.NewKeyFromSeed([]byte{
		1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
		17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 77,
	})
	PrivateKeyB = ed25519.NewKeyFromSeed([]byte{
		1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
		17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 66,
	})
)
View Source
var Quiet = false
View Source
var Required = os.Getenv("DENDRITE_TEST_SKIP_NODB") == ""

Functions

func AssertEventIDsEqual

func AssertEventIDsEqual(t *testing.T, gotEventIDs []string, wants []*types.HeaderedEvent)

func AssertEventsEqual

func AssertEventsEqual(t *testing.T, gots, wants []*types.HeaderedEvent)

func GuestsCanJoin added in v0.10.9

func GuestsCanJoin(canJoin bool) roomModifier

func ListenAndServe added in v0.8.6

func ListenAndServe(t *testing.T, router http.Handler, withTLS bool) (apiURL string, cancel func())

ListenAndServe will listen on a random high-numbered port and attach the given router. Returns the base URL to send requests to. Call `cancel` to shutdown the server, which will block until it has closed.

func NewMatrixKey added in v0.8.6

func NewMatrixKey(matrixKeyPath string) (err error)

NewMatrixKey generates a new ed25519 matrix server key and writes it to a file.

func NewRequest added in v0.8.3

func NewRequest(t *testing.T, method, path string, opts ...HTTPRequestOpt) *http.Request

func NewTLSKey added in v0.8.6

func NewTLSKey(tlsKeyPath, tlsCertPath string, keySize int) error

NewTLSKey generates a new RSA TLS key and certificate and writes it to a file.

func NewTLSKeyWithAuthority added in v0.8.6

func NewTLSKeyWithAuthority(serverName, tlsKeyPath, tlsCertPath, authorityKeyPath, authorityCertPath string, keySize int) error

func PrepareDBConnectionString

func PrepareDBConnectionString(t *testing.T, dbType DBType) (connStr string, close func())

Prepare a sqlite or postgres connection string for testing. Returns the connection string to use and a close function which must be called when the test finishes. Calling this function twice will return the same database, which will have data from previous tests unless close() is called.

func Reversed

func Reversed(in []*types.HeaderedEvent) []*types.HeaderedEvent

Reverse a list of events

func RoomHistoryVisibility added in v0.9.2

func RoomHistoryVisibility(vis gomatrixserverlib.HistoryVisibility) roomModifier

func RoomPreset

func RoomPreset(p Preset) roomModifier

func RoomVersion

func RoomVersion(ver gomatrixserverlib.RoomVersion) roomModifier

func SaveMatrixKey added in v0.9.6

func SaveMatrixKey(matrixKeyPath string, data ed25519.PrivateKey) error

func UnsortedStringSliceEqual added in v0.8.6

func UnsortedStringSliceEqual(first, second []string) bool

UnsortedStringSliceEqual returns true if the slices have same length & elements. Does not modify the given slice.

func UserIDForSender added in v0.13.0

func UserIDForSender(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error)

func WithAllDatabases

func WithAllDatabases(t *testing.T, testFn func(t *testing.T, db DBType))

Creates subtests with each known DBType

func WithAuthIDs added in v0.10.3

func WithAuthIDs(evs []string) eventModifier

func WithKeyID added in v0.8.6

func WithKeyID(keyID gomatrixserverlib.KeyID) eventModifier

func WithOrigin added in v0.8.6

func WithOrigin(origin spec.ServerName) eventModifier

func WithPrivateKey added in v0.8.6

func WithPrivateKey(pkey ed25519.PrivateKey) eventModifier

func WithStateKey

func WithStateKey(skey string) eventModifier

func WithTimestamp

func WithTimestamp(ts time.Time) eventModifier

func WithUnsigned

func WithUnsigned(unsigned interface{}) eventModifier

Types

type DBType

type DBType int
var DBTypePostgres DBType = 2
var DBTypeSQLite DBType = 1

type HTTPRequestOpt added in v0.8.3

type HTTPRequestOpt func(req *http.Request)

func WithJSONBody added in v0.8.3

func WithJSONBody(t *testing.T, body interface{}) HTTPRequestOpt

func WithQueryParams added in v0.8.3

func WithQueryParams(qps map[string]string) HTTPRequestOpt

type InMemoryFederationDatabase added in v0.11.1

type InMemoryFederationDatabase struct {
	// contains filtered or unexported fields
}

func NewInMemoryFederationDatabase added in v0.11.1

func NewInMemoryFederationDatabase() *InMemoryFederationDatabase

func (*InMemoryFederationDatabase) AddInboundPeek added in v0.11.1

func (d *InMemoryFederationDatabase) AddInboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string, renewalInterval int64) error

func (*InMemoryFederationDatabase) AddOutboundPeek added in v0.11.1

func (d *InMemoryFederationDatabase) AddOutboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string, renewalInterval int64) error

func (*InMemoryFederationDatabase) AddServerToBlacklist added in v0.11.1

func (d *InMemoryFederationDatabase) AddServerToBlacklist(
	serverName spec.ServerName,
) error

func (*InMemoryFederationDatabase) AssociateEDUWithDestinations added in v0.11.1

func (d *InMemoryFederationDatabase) AssociateEDUWithDestinations(
	ctx context.Context,
	destinations map[spec.ServerName]struct{},
	dbReceipt *receipt.Receipt,
	eduType string,
	expireEDUTypes map[string]time.Duration,
) error

func (*InMemoryFederationDatabase) AssociatePDUWithDestinations added in v0.11.1

func (d *InMemoryFederationDatabase) AssociatePDUWithDestinations(
	ctx context.Context,
	destinations map[spec.ServerName]struct{},
	dbReceipt *receipt.Receipt,
) error

func (*InMemoryFederationDatabase) CleanEDUs added in v0.11.1

func (d *InMemoryFederationDatabase) CleanEDUs(
	ctx context.Context,
	serverName spec.ServerName,
	receipts []*receipt.Receipt,
) error

func (*InMemoryFederationDatabase) CleanPDUs added in v0.11.1

func (d *InMemoryFederationDatabase) CleanPDUs(
	ctx context.Context,
	serverName spec.ServerName,
	receipts []*receipt.Receipt,
) error

func (*InMemoryFederationDatabase) DeleteExpiredEDUs added in v0.11.1

func (d *InMemoryFederationDatabase) DeleteExpiredEDUs(ctx context.Context) error

func (*InMemoryFederationDatabase) FetcherName added in v0.11.1

func (d *InMemoryFederationDatabase) FetcherName() string

func (*InMemoryFederationDatabase) GetAllJoinedHosts added in v0.11.1

func (d *InMemoryFederationDatabase) GetAllJoinedHosts(ctx context.Context) ([]spec.ServerName, error)

func (*InMemoryFederationDatabase) GetInboundPeek added in v0.11.1

func (d *InMemoryFederationDatabase) GetInboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string) (*types.InboundPeek, error)

func (*InMemoryFederationDatabase) GetInboundPeeks added in v0.11.1

func (d *InMemoryFederationDatabase) GetInboundPeeks(ctx context.Context, roomID string) ([]types.InboundPeek, error)

func (*InMemoryFederationDatabase) GetJoinedHosts added in v0.11.1

func (d *InMemoryFederationDatabase) GetJoinedHosts(ctx context.Context, roomID string) ([]types.JoinedHost, error)

func (*InMemoryFederationDatabase) GetJoinedHostsForRooms added in v0.11.1

func (d *InMemoryFederationDatabase) GetJoinedHostsForRooms(ctx context.Context, roomIDs []string, excludeSelf, excludeBlacklisted bool) ([]spec.ServerName, error)

func (*InMemoryFederationDatabase) GetNotaryKeys added in v0.11.1

func (*InMemoryFederationDatabase) GetOutboundPeek added in v0.11.1

func (d *InMemoryFederationDatabase) GetOutboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string) (*types.OutboundPeek, error)

func (*InMemoryFederationDatabase) GetOutboundPeeks added in v0.11.1

func (d *InMemoryFederationDatabase) GetOutboundPeeks(ctx context.Context, roomID string) ([]types.OutboundPeek, error)

func (*InMemoryFederationDatabase) GetPendingEDUCount added in v0.11.1

func (d *InMemoryFederationDatabase) GetPendingEDUCount(
	ctx context.Context,
	serverName spec.ServerName,
) (int64, error)

func (*InMemoryFederationDatabase) GetPendingEDUServerNames added in v0.11.1

func (d *InMemoryFederationDatabase) GetPendingEDUServerNames(
	ctx context.Context,
) ([]spec.ServerName, error)

func (*InMemoryFederationDatabase) GetPendingEDUs added in v0.11.1

func (d *InMemoryFederationDatabase) GetPendingEDUs(
	ctx context.Context,
	serverName spec.ServerName,
	limit int,
) (edus map[*receipt.Receipt]*gomatrixserverlib.EDU, err error)

func (*InMemoryFederationDatabase) GetPendingPDUCount added in v0.11.1

func (d *InMemoryFederationDatabase) GetPendingPDUCount(
	ctx context.Context,
	serverName spec.ServerName,
) (int64, error)

func (*InMemoryFederationDatabase) GetPendingPDUServerNames added in v0.11.1

func (d *InMemoryFederationDatabase) GetPendingPDUServerNames(
	ctx context.Context,
) ([]spec.ServerName, error)

func (*InMemoryFederationDatabase) GetPendingPDUs added in v0.11.1

func (d *InMemoryFederationDatabase) GetPendingPDUs(
	ctx context.Context,
	serverName spec.ServerName,
	limit int,
) (pdus map[*receipt.Receipt]*rstypes.HeaderedEvent, err error)

func (*InMemoryFederationDatabase) IsServerAssumedOffline added in v0.11.1

func (d *InMemoryFederationDatabase) IsServerAssumedOffline(
	ctx context.Context,
	serverName spec.ServerName,
) (bool, error)

func (*InMemoryFederationDatabase) IsServerBlacklisted added in v0.11.1

func (d *InMemoryFederationDatabase) IsServerBlacklisted(
	serverName spec.ServerName,
) (bool, error)

func (*InMemoryFederationDatabase) P2PAddRelayServersForServer added in v0.11.1

func (d *InMemoryFederationDatabase) P2PAddRelayServersForServer(
	ctx context.Context,
	serverName spec.ServerName,
	relayServers []spec.ServerName,
) error

func (*InMemoryFederationDatabase) P2PGetRelayServersForServer added in v0.11.1

func (d *InMemoryFederationDatabase) P2PGetRelayServersForServer(
	ctx context.Context,
	serverName spec.ServerName,
) ([]spec.ServerName, error)

func (*InMemoryFederationDatabase) P2PRemoveAllRelayServersForServer added in v0.11.1

func (d *InMemoryFederationDatabase) P2PRemoveAllRelayServersForServer(ctx context.Context, serverName spec.ServerName) error

func (*InMemoryFederationDatabase) P2PRemoveRelayServersForServer added in v0.11.1

func (d *InMemoryFederationDatabase) P2PRemoveRelayServersForServer(
	ctx context.Context,
	serverName spec.ServerName,
	relayServers []spec.ServerName,
) error

func (*InMemoryFederationDatabase) PurgeRoom added in v0.11.1

func (d *InMemoryFederationDatabase) PurgeRoom(ctx context.Context, roomID string) error

func (*InMemoryFederationDatabase) RemoveAllServersAssumedOffine added in v0.11.1

func (d *InMemoryFederationDatabase) RemoveAllServersAssumedOffine(
	ctx context.Context,
) error

func (*InMemoryFederationDatabase) RemoveAllServersAssumedOffline added in v0.11.1

func (d *InMemoryFederationDatabase) RemoveAllServersAssumedOffline(ctx context.Context) error

func (*InMemoryFederationDatabase) RemoveAllServersFromBlacklist added in v0.11.1

func (d *InMemoryFederationDatabase) RemoveAllServersFromBlacklist() error

func (*InMemoryFederationDatabase) RemoveServerAssumedOffline added in v0.11.1

func (d *InMemoryFederationDatabase) RemoveServerAssumedOffline(
	ctx context.Context,
	serverName spec.ServerName,
) error

func (*InMemoryFederationDatabase) RemoveServerFromBlacklist added in v0.11.1

func (d *InMemoryFederationDatabase) RemoveServerFromBlacklist(
	serverName spec.ServerName,
) error

func (*InMemoryFederationDatabase) RenewInboundPeek added in v0.11.1

func (d *InMemoryFederationDatabase) RenewInboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string, renewalInterval int64) error

func (*InMemoryFederationDatabase) RenewOutboundPeek added in v0.11.1

func (d *InMemoryFederationDatabase) RenewOutboundPeek(ctx context.Context, serverName spec.ServerName, roomID, peekID string, renewalInterval int64) error

func (*InMemoryFederationDatabase) SetServerAssumedOffline added in v0.11.1

func (d *InMemoryFederationDatabase) SetServerAssumedOffline(
	ctx context.Context,
	serverName spec.ServerName,
) error

func (*InMemoryFederationDatabase) StoreJSON added in v0.11.1

func (d *InMemoryFederationDatabase) StoreJSON(
	ctx context.Context,
	js string,
) (*receipt.Receipt, error)

func (*InMemoryFederationDatabase) StoreKeys added in v0.11.1

func (*InMemoryFederationDatabase) UpdateNotaryKeys added in v0.11.1

func (d *InMemoryFederationDatabase) UpdateNotaryKeys(ctx context.Context, serverName spec.ServerName, serverKeys gomatrixserverlib.ServerKeys) error

func (*InMemoryFederationDatabase) UpdateRoom added in v0.11.1

func (d *InMemoryFederationDatabase) UpdateRoom(ctx context.Context, roomID string, addHosts []types.JoinedHost, removeHosts []string, purgeRoomFirst bool) (joinedHosts []types.JoinedHost, err error)

type InMemoryRelayDatabase added in v0.11.1

type InMemoryRelayDatabase struct {
	// contains filtered or unexported fields
}

func NewInMemoryRelayDatabase added in v0.11.1

func NewInMemoryRelayDatabase() *InMemoryRelayDatabase

func (*InMemoryRelayDatabase) DeleteQueueEntries added in v0.11.1

func (d *InMemoryRelayDatabase) DeleteQueueEntries(
	ctx context.Context,
	txn *sql.Tx,
	serverName spec.ServerName,
	jsonNIDs []int64,
) error

func (*InMemoryRelayDatabase) DeleteQueueJSON added in v0.11.1

func (d *InMemoryRelayDatabase) DeleteQueueJSON(
	ctx context.Context,
	txn *sql.Tx,
	nids []int64,
) error

func (*InMemoryRelayDatabase) InsertQueueEntry added in v0.11.1

func (d *InMemoryRelayDatabase) InsertQueueEntry(
	ctx context.Context,
	txn *sql.Tx,
	transactionID gomatrixserverlib.TransactionID,
	serverName spec.ServerName,
	nid int64,
) error

func (*InMemoryRelayDatabase) InsertQueueJSON added in v0.11.1

func (d *InMemoryRelayDatabase) InsertQueueJSON(
	ctx context.Context,
	txn *sql.Tx,
	json string,
) (int64, error)

func (*InMemoryRelayDatabase) SelectQueueEntries added in v0.11.1

func (d *InMemoryRelayDatabase) SelectQueueEntries(
	ctx context.Context,
	txn *sql.Tx, serverName spec.ServerName,
	limit int,
) ([]int64, error)

func (*InMemoryRelayDatabase) SelectQueueEntryCount added in v0.11.1

func (d *InMemoryRelayDatabase) SelectQueueEntryCount(
	ctx context.Context,
	txn *sql.Tx,
	serverName spec.ServerName,
) (int64, error)

func (*InMemoryRelayDatabase) SelectQueueJSON added in v0.11.1

func (d *InMemoryRelayDatabase) SelectQueueJSON(
	ctx context.Context,
	txn *sql.Tx,
	jsonNIDs []int64,
) (map[int64][]byte, error)

type NopJSONVerifier added in v0.8.6

type NopJSONVerifier struct {
}

NopJSONVerifier is a JSONVerifier that verifies nothing and returns no errors.

func (*NopJSONVerifier) VerifyJSONs added in v0.8.6

type Preset

type Preset int
var (
	PresetNone               Preset = 0
	PresetPrivateChat        Preset = 1
	PresetPublicChat         Preset = 2
	PresetTrustedPrivateChat Preset = 3
)

type Room

type Room struct {
	ID      string
	Version gomatrixserverlib.RoomVersion
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(t *testing.T, creator *User, modifiers ...roomModifier) *Room

Create a new test room. Automatically creates the initial create events.

func (*Room) CreateAndInsert

func (r *Room) CreateAndInsert(t *testing.T, creator *User, eventType string, content interface{}, mods ...eventModifier) *rstypes.HeaderedEvent

func (*Room) CreateEvent

func (r *Room) CreateEvent(t *testing.T, creator *User, eventType string, content interface{}, mods ...eventModifier) *rstypes.HeaderedEvent

Create an event in this room but do not insert it. Does not modify the room in any way (depth, fwd extremities, etc) so is thread-safe.

func (*Room) CurrentState added in v0.8.6

func (r *Room) CurrentState() []*rstypes.HeaderedEvent

func (*Room) Events

func (r *Room) Events() []*rstypes.HeaderedEvent

func (*Room) ForwardExtremities added in v0.8.6

func (r *Room) ForwardExtremities() []string

func (*Room) InsertEvent

func (r *Room) InsertEvent(t *testing.T, he *rstypes.HeaderedEvent)

Add a new event to this room DAG. Not thread-safe.

func (*Room) MustGetAuthEventRefsForEvent added in v0.8.6

func (r *Room) MustGetAuthEventRefsForEvent(t *testing.T, needed gomatrixserverlib.StateNeeded) []string

type User

type User struct {
	ID          string
	Localpart   string
	AccountType api.AccountType
	// contains filtered or unexported fields
}

func NewUser

func NewUser(t *testing.T, opts ...UserOpt) *User

type UserOpt added in v0.8.6

type UserOpt func(*User)

func WithAccountType added in v0.9.2

func WithAccountType(accountType api.AccountType) UserOpt

func WithSigningServer added in v0.8.6

func WithSigningServer(srvName spec.ServerName, keyID gomatrixserverlib.KeyID, privKey ed25519.PrivateKey) UserOpt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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