-
Notifications
You must be signed in to change notification settings - Fork 69
Add tests for /make_knock and /send_knock (same as the join counterparts) for when the federation server is in the middle of a partial join
#447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+176
−7
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2f3a7f6
Drive-by correction
reivilibre bf76071
Add test for /make_knock and /send_knock
reivilibre f23be67
Add needed MakeRespMakeKnock
reivilibre f766d51
Fixes
reivilibre b196ba4
Update gomatrixserverlib
reivilibre 127095f
Merge branch 'main' into rei/frj_send_knock_during_partial_join
reivilibre 6ef95e0
Update gomatrixserverlib
reivilibre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1147,7 +1147,7 @@ func TestPartialStateJoin(t *testing.T) { | |
| t.Fatalf("MakeRespMakeJoin failed : %s", err) | ||
| } | ||
|
|
||
| // charlie then tries to /send_join via the homeserver under test | ||
| // daniel then tries to /send_join via the homeserver under test | ||
| joinEvent, err := makeJoinResp.JoinEvent.Build(time.Now(), gomatrixserverlib.ServerName(testServer2.ServerName()), testServer2.KeyID, testServer2.Priv, makeJoinResp.RoomVersion) | ||
| must.NotError(t, "JoinEvent.Build", err) | ||
|
|
||
|
|
@@ -1229,6 +1229,125 @@ func TestPartialStateJoin(t *testing.T) { | |
| }, | ||
| }) | ||
| }) | ||
|
|
||
| // when the server is in the middle of a partial state join, it should not accept | ||
| // /make_knock because it can't give a full answer. | ||
| t.Run("Rejects make_knock during partial join", func(t *testing.T) { | ||
| // In this test, we have 3 homeservers: | ||
| // hs1 (the server under test) with @alice:hs1 | ||
| // This is the server that will be in the middle of a partial join. | ||
| // testServer1 (a Complement test server) with @bob:<server name> | ||
| // This is the server that created the room originally. | ||
| // testServer2 (another Complement test server) with @charlie:<server name> | ||
| // This is the server that will try to make a knock via testServer1. | ||
| deployment := Deploy(t, b.BlueprintAlice) | ||
| defer deployment.Destroy(t) | ||
| alice := deployment.Client(t, "hs1", "@alice:hs1") | ||
|
|
||
| testServer1 := createTestServer(t, deployment) | ||
| cancel := testServer1.Listen() | ||
| defer cancel() | ||
| serverRoom := createTestRoom(t, testServer1, alice.GetDefaultRoomVersion(t)) | ||
| roomID := serverRoom.RoomID | ||
| psjResult := beginPartialStateJoin(t, testServer1, serverRoom, alice) | ||
| defer psjResult.Destroy() | ||
|
|
||
| // The partial join is now in progress. | ||
| // Let's have a new test server rock up and ask to join the room by making a | ||
| // /make_knock request. | ||
|
|
||
| testServer2 := createTestServer(t, deployment) | ||
| cancel2 := testServer2.Listen() | ||
| defer cancel2() | ||
|
|
||
| fedClient2 := testServer2.FederationClient(deployment) | ||
|
|
||
| // charlie sends a make_knock | ||
| _, err := fedClient2.MakeKnock(context.Background(), "hs1", roomID, testServer2.UserID("charlie"), federation.SupportedRoomVersions()) | ||
|
|
||
| if err == nil { | ||
| t.Errorf("MakeKnock returned 200, want 404") | ||
| } else if httpError, ok := err.(gomatrix.HTTPError); ok { | ||
| t.Logf("MakeKnock => %d/%s", httpError.Code, string(httpError.Contents)) | ||
| if httpError.Code != 404 { | ||
| t.Errorf("expected 404, got %d", httpError.Code) | ||
| } | ||
| errcode := must.GetJSONFieldStr(t, httpError.Contents, "errcode") | ||
| if errcode != "M_NOT_FOUND" { | ||
| t.Errorf("errcode: got %s, want M_NOT_FOUND", errcode) | ||
| } | ||
| } else { | ||
| t.Errorf("MakeKnock: non-HTTPError: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| // when the server is in the middle of a partial state join, it should not accept | ||
| // /send_knock because it can't give a full answer. | ||
| t.Run("Rejects send_knock during partial join", func(t *testing.T) { | ||
| // In this test, we have 3 homeservers: | ||
| // hs1 (the server under test) with @alice:hs1 | ||
| // This is the server that will be in the middle of a partial join. | ||
| // testServer1 (a Complement test server) with @charlie:<server name> | ||
| // This is the server that will create the room originally. | ||
| // testServer2 (another Complement test server) with @daniel:<server name> | ||
| // This is the server that will try to knock on the room via hs2, | ||
| // but only after using hs1 to /make_knock (as otherwise we have no way | ||
| // of being able to build a request to /send_knock) | ||
| // | ||
| deployment := Deploy(t, b.BlueprintAlice) | ||
| defer deployment.Destroy(t) | ||
| alice := deployment.Client(t, "hs1", "@alice:hs1") | ||
|
|
||
| testServer1 := createTestServer(t, deployment) | ||
| cancel := testServer1.Listen() | ||
| defer cancel() | ||
| serverRoom := createTestRoom(t, testServer1, alice.GetDefaultRoomVersion(t)) | ||
| psjResult := beginPartialStateJoin(t, testServer1, serverRoom, alice) | ||
| defer psjResult.Destroy() | ||
|
|
||
| // hs1's partial join is now in progress. | ||
| // Let's have a test server rock up and ask to /send_knock in the room via hs1. | ||
| // To do that, we need to /make_knock first. | ||
| // Asking hs1 to /make_knock won't work, because it should reject that request. | ||
| // To work around that, we /make_knock via hs2. | ||
|
|
||
| testServer2 := createTestServer(t, deployment) | ||
| cancel2 := testServer2.Listen() | ||
| defer cancel2() | ||
|
|
||
| fedClient2 := testServer2.FederationClient(deployment) | ||
|
|
||
| // Manually /make_knock via testServer1. | ||
| // This is permissible because testServer1 is fully joined to the room. | ||
| // We can't actually use /make_knock because host.docker.internal doesn't resolve, | ||
| // so compute it without making any requests: | ||
| makeKnockResp, err := federation.MakeRespMakeKnock(testServer1, serverRoom, testServer2.UserID("daniel")) | ||
| if err != nil { | ||
| t.Fatalf("MakeRespMakeKnock failed : %s", err) | ||
| } | ||
|
|
||
| // daniel then tries to /send_knock via the homeserver under test | ||
| knockEvent, err := makeKnockResp.KnockEvent.Build(time.Now(), gomatrixserverlib.ServerName(testServer2.ServerName()), testServer2.KeyID, testServer2.Priv, makeKnockResp.RoomVersion) | ||
| must.NotError(t, "KnockEvent.Build", err) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this just shorthand for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, seems to be // NotError will ensure `err` is nil else terminate the test with `msg`.
func NotError(t *testing.T, msg string, err error) {
t.Helper()
if err != nil {
t.Fatalf("MustNotError: %s -> %s", msg, err)
}
} |
||
|
|
||
| // SendKnock should return a 404 because the homeserver under test has not | ||
| // finished its partial join. | ||
| _, err = fedClient2.SendKnock(context.Background(), "hs1", knockEvent) | ||
| if err == nil { | ||
| t.Errorf("SendKnock returned 200, want 404") | ||
| } else if httpError, ok := err.(gomatrix.HTTPError); ok { | ||
| t.Logf("SendKnock => %d/%s", httpError.Code, string(httpError.Contents)) | ||
| if httpError.Code != 404 { | ||
| t.Errorf("expected 404, got %d", httpError.Code) | ||
| } | ||
| errcode := must.GetJSONFieldStr(t, httpError.Contents, "errcode") | ||
| if errcode != "M_NOT_FOUND" { | ||
| t.Errorf("errcode: got %s, want M_NOT_FOUND", errcode) | ||
| } | ||
| } else { | ||
| t.Errorf("SendKnock: non-HTTPError: %v", err) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| // test reception of an event over federation during a resync | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we implicitly returning
resp, errhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I find this weird but Go supports this old-school Pascal-ish style of assigning to a result variable rather than returning, except the result variable's names are declared in the function declaration.
I nicked this from what was already there; it's 'not my choice' but it seems like this may be idiomatic