mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-25 15:53:09 -06:00
Patchy fix for test
This commit is contained in:
parent
3b8da64592
commit
5e6afdce1a
|
|
@ -77,10 +77,11 @@ func (p *testEDUProducer) InputSendToDeviceEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
type testRoomserverAPI struct {
|
type testRoomserverAPI struct {
|
||||||
inputRoomEvents []api.InputRoomEvent
|
inputRoomEvents []api.InputRoomEvent
|
||||||
queryStateAfterEvents func(*api.QueryStateAfterEventsRequest) api.QueryStateAfterEventsResponse
|
queryMissingAuthPrevEvents func(*api.QueryMissingAuthPrevEventsRequest) api.QueryMissingAuthPrevEventsResponse
|
||||||
queryEventsByID func(req *api.QueryEventsByIDRequest) api.QueryEventsByIDResponse
|
queryStateAfterEvents func(*api.QueryStateAfterEventsRequest) api.QueryStateAfterEventsResponse
|
||||||
queryLatestEventsAndState func(*api.QueryLatestEventsAndStateRequest) api.QueryLatestEventsAndStateResponse
|
queryEventsByID func(req *api.QueryEventsByIDRequest) api.QueryEventsByIDResponse
|
||||||
|
queryLatestEventsAndState func(*api.QueryLatestEventsAndStateRequest) api.QueryLatestEventsAndStateResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testRoomserverAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI) {}
|
func (t *testRoomserverAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI) {}
|
||||||
|
|
@ -162,6 +163,20 @@ func (t *testRoomserverAPI) QueryStateAfterEvents(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Query the state after a list of events in a room from the room server.
|
||||||
|
func (t *testRoomserverAPI) QueryMissingAuthPrevEvents(
|
||||||
|
ctx context.Context,
|
||||||
|
request *api.QueryMissingAuthPrevEventsRequest,
|
||||||
|
response *api.QueryMissingAuthPrevEventsResponse,
|
||||||
|
) error {
|
||||||
|
response.RoomVersion = testRoomVersion
|
||||||
|
res := t.queryMissingAuthPrevEvents(request)
|
||||||
|
response.RoomExists = res.RoomExists
|
||||||
|
response.MissingAuthEventIDs = res.MissingAuthEventIDs
|
||||||
|
response.MissingPrevEventIDs = res.MissingPrevEventIDs
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Query a list of events by event ID.
|
// Query a list of events by event ID.
|
||||||
func (t *testRoomserverAPI) QueryEventsByID(
|
func (t *testRoomserverAPI) QueryEventsByID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
|
@ -453,11 +468,11 @@ func assertInputRoomEvents(t *testing.T, got []api.InputRoomEvent, want []gomatr
|
||||||
// to the roomserver. It's the most basic test possible.
|
// to the roomserver. It's the most basic test possible.
|
||||||
func TestBasicTransaction(t *testing.T) {
|
func TestBasicTransaction(t *testing.T) {
|
||||||
rsAPI := &testRoomserverAPI{
|
rsAPI := &testRoomserverAPI{
|
||||||
queryStateAfterEvents: func(req *api.QueryStateAfterEventsRequest) api.QueryStateAfterEventsResponse {
|
queryMissingAuthPrevEvents: func(req *api.QueryMissingAuthPrevEventsRequest) api.QueryMissingAuthPrevEventsResponse {
|
||||||
return api.QueryStateAfterEventsResponse{
|
return api.QueryMissingAuthPrevEventsResponse{
|
||||||
PrevEventsExist: true,
|
RoomExists: true,
|
||||||
RoomExists: true,
|
MissingAuthEventIDs: []string{},
|
||||||
StateEvents: fromStateTuples(req.StateToFetch, nil),
|
MissingPrevEventIDs: []string{},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -473,14 +488,11 @@ func TestBasicTransaction(t *testing.T) {
|
||||||
// as it does the auth check.
|
// as it does the auth check.
|
||||||
func TestTransactionFailAuthChecks(t *testing.T) {
|
func TestTransactionFailAuthChecks(t *testing.T) {
|
||||||
rsAPI := &testRoomserverAPI{
|
rsAPI := &testRoomserverAPI{
|
||||||
queryStateAfterEvents: func(req *api.QueryStateAfterEventsRequest) api.QueryStateAfterEventsResponse {
|
queryMissingAuthPrevEvents: func(req *api.QueryMissingAuthPrevEventsRequest) api.QueryMissingAuthPrevEventsResponse {
|
||||||
return api.QueryStateAfterEventsResponse{
|
return api.QueryMissingAuthPrevEventsResponse{
|
||||||
PrevEventsExist: true,
|
RoomExists: true,
|
||||||
RoomExists: true,
|
MissingAuthEventIDs: []string{"create_event"},
|
||||||
// omit the create event so auth checks fail
|
MissingPrevEventIDs: []string{},
|
||||||
StateEvents: fromStateTuples(req.StateToFetch, []gomatrixserverlib.StateKeyTuple{
|
|
||||||
{EventType: gomatrixserverlib.MRoomCreate, StateKey: ""},
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -504,28 +516,24 @@ func TestTransactionFetchMissingPrevEvents(t *testing.T) {
|
||||||
|
|
||||||
var rsAPI *testRoomserverAPI // ref here so we can refer to inputRoomEvents inside these functions
|
var rsAPI *testRoomserverAPI // ref here so we can refer to inputRoomEvents inside these functions
|
||||||
rsAPI = &testRoomserverAPI{
|
rsAPI = &testRoomserverAPI{
|
||||||
queryStateAfterEvents: func(req *api.QueryStateAfterEventsRequest) api.QueryStateAfterEventsResponse {
|
queryMissingAuthPrevEvents: func(req *api.QueryMissingAuthPrevEventsRequest) api.QueryMissingAuthPrevEventsResponse {
|
||||||
// we expect this to be called three times:
|
missingPrevEvent := []string{"missing_prev_event"}
|
||||||
// - first with input event to realise there's a gap
|
|
||||||
// - second with the prevEvent to realise there is no gap
|
|
||||||
// - third with the input event to realise there is no longer a gap
|
|
||||||
prevEventsExist := false
|
|
||||||
if len(req.PrevEventIDs) == 1 {
|
if len(req.PrevEventIDs) == 1 {
|
||||||
switch req.PrevEventIDs[0] {
|
switch req.PrevEventIDs[0] {
|
||||||
case haveEvent.EventID():
|
case haveEvent.EventID():
|
||||||
prevEventsExist = true
|
missingPrevEvent = []string{}
|
||||||
case prevEvent.EventID():
|
case prevEvent.EventID():
|
||||||
// we only have this event if we've been send prevEvent
|
// we only have this event if we've been send prevEvent
|
||||||
if len(rsAPI.inputRoomEvents) == 1 && rsAPI.inputRoomEvents[0].Event.EventID() == prevEvent.EventID() {
|
if len(rsAPI.inputRoomEvents) == 1 && rsAPI.inputRoomEvents[0].Event.EventID() == prevEvent.EventID() {
|
||||||
prevEventsExist = true
|
missingPrevEvent = []string{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return api.QueryStateAfterEventsResponse{
|
return api.QueryMissingAuthPrevEventsResponse{
|
||||||
PrevEventsExist: prevEventsExist,
|
RoomExists: true,
|
||||||
RoomExists: true,
|
MissingAuthEventIDs: []string{},
|
||||||
StateEvents: fromStateTuples(req.StateToFetch, nil),
|
MissingPrevEventIDs: missingPrevEvent,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
queryLatestEventsAndState: func(req *api.QueryLatestEventsAndStateRequest) api.QueryLatestEventsAndStateResponse {
|
queryLatestEventsAndState: func(req *api.QueryLatestEventsAndStateRequest) api.QueryLatestEventsAndStateResponse {
|
||||||
|
|
@ -626,6 +634,38 @@ func TestTransactionFetchMissingStateByStateIDs(t *testing.T) {
|
||||||
StateEvents: stateEvents,
|
StateEvents: stateEvents,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
queryMissingAuthPrevEvents: func(req *api.QueryMissingAuthPrevEventsRequest) api.QueryMissingAuthPrevEventsResponse {
|
||||||
|
askingForEvent := req.PrevEventIDs[0]
|
||||||
|
haveEventB := false
|
||||||
|
haveEventC := false
|
||||||
|
for _, ev := range rsAPI.inputRoomEvents {
|
||||||
|
switch ev.Event.EventID() {
|
||||||
|
case eventB.EventID():
|
||||||
|
haveEventB = true
|
||||||
|
case eventC.EventID():
|
||||||
|
haveEventC = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prevEventExists := false
|
||||||
|
if askingForEvent == eventC.EventID() {
|
||||||
|
prevEventExists = haveEventC
|
||||||
|
} else if askingForEvent == eventB.EventID() {
|
||||||
|
prevEventExists = haveEventB
|
||||||
|
}
|
||||||
|
|
||||||
|
var missingPrevEvent []string
|
||||||
|
if !prevEventExists {
|
||||||
|
missingPrevEvent = []string{"test"}
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.QueryMissingAuthPrevEventsResponse{
|
||||||
|
RoomExists: true,
|
||||||
|
MissingAuthEventIDs: []string{},
|
||||||
|
MissingPrevEventIDs: missingPrevEvent,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
queryLatestEventsAndState: func(req *api.QueryLatestEventsAndStateRequest) api.QueryLatestEventsAndStateResponse {
|
queryLatestEventsAndState: func(req *api.QueryLatestEventsAndStateRequest) api.QueryLatestEventsAndStateResponse {
|
||||||
omitTuples := []gomatrixserverlib.StateKeyTuple{
|
omitTuples := []gomatrixserverlib.StateKeyTuple{
|
||||||
{EventType: gomatrixserverlib.MRoomPowerLevels, StateKey: ""},
|
{EventType: gomatrixserverlib.MRoomPowerLevels, StateKey: ""},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue