-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into s7evink/eventsize
- Loading branch information
Showing
143 changed files
with
5,580 additions
and
1,757 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Contributing to Complement | ||
|
||
Thank you for taking the time to contribute to Matrix! | ||
|
||
This is the repository for Complement, a black box integration testing framework for Matrix homeservers. | ||
|
||
## Sign off | ||
|
||
We ask that everybody who contributes to this project signs off their contributions, as explained below. | ||
|
||
We follow a simple 'inbound=outbound' model for contributions: the act of submitting an 'inbound' contribution means that the contributor agrees to license their contribution under the same terms as the project's overall 'outbound' license - in our case, this is Apache Software License v2 (see [LICENSE](./LICENSE)). | ||
|
||
In order to have a concrete record that your contribution is intentional and you agree to license it under the same terms as the project's license, we've adopted the same lightweight approach used by the [Linux Kernel](https://www.kernel.org/doc/html/latest/process/submitting-patches.html), [Docker](https://github.com/docker/docker/blob/master/CONTRIBUTING.md), and many other projects: the [Developer Certificate of Origin](https://developercertificate.org/) (DCO). This is a simple declaration that you wrote the contribution or otherwise have the right to contribute it to Matrix: | ||
|
||
``` | ||
Developer Certificate of Origin | ||
Version 1.1 | ||
Copyright (C) 2004, 2006 The Linux Foundation and its contributors. | ||
660 York Street, Suite 102, | ||
San Francisco, CA 94110 USA | ||
Everyone is permitted to copy and distribute verbatim copies of this | ||
license document, but changing it is not allowed. | ||
Developer's Certificate of Origin 1.1 | ||
By making a contribution to this project, I certify that: | ||
(a) The contribution was created in whole or in part by me and I | ||
have the right to submit it under the open source license | ||
indicated in the file; or | ||
(b) The contribution is based upon previous work that, to the best | ||
of my knowledge, is covered under an appropriate open source | ||
license and I have the right under that license to submit that | ||
work with modifications, whether created in whole or in part | ||
by me, under the same open source license (unless I am | ||
permitted to submit under a different license), as indicated | ||
in the file; or | ||
(c) The contribution was provided directly to me by some other | ||
person who certified (a), (b) or (c) and I have not modified | ||
it. | ||
(d) I understand and agree that this project and the contribution | ||
are public and that a record of the contribution (including all | ||
personal information I submit with it, including my sign-off) is | ||
maintained indefinitely and may be redistributed consistent with | ||
this project or the open source license(s) involved. | ||
``` | ||
|
||
If you agree to this for your contribution, then all that's needed is to include the line in your commit or pull request comment: | ||
|
||
``` | ||
Signed-off-by: Your Name <[email protected]> | ||
``` | ||
|
||
Git allows you to add this signoff automatically when using the `-s` flag to `git commit`, which uses the name and email set in your `user.name` and `user.email` git configs. |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
## How to run tests out-of-repo | ||
|
||
- Make a new go project: `go mod init some.package.name`. | ||
- Get the latest version of Complement: `go get github.com/matrix-org/complement@main` | ||
- Add a tests directory and file: `mkdir ./tests; touch ./tests/something_test.go` | ||
|
||
*something_test.go* | ||
```go | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/matrix-org/complement" | ||
"github.com/matrix-org/complement/client" | ||
"github.com/matrix-org/complement/helpers" | ||
"github.com/matrix-org/complement/match" | ||
"github.com/matrix-org/complement/must" | ||
) | ||
|
||
func TestCannotKickNonPresentUser(t *testing.T) { | ||
deployment := complement.Deploy(t, 1) | ||
defer deployment.Destroy(t) | ||
|
||
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) | ||
bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) | ||
|
||
roomID := alice.MustCreateRoom(t, map[string]interface{}{ | ||
"preset": "public_chat", | ||
}) | ||
|
||
resp := alice.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "kick"}, | ||
client.WithJSONBody(t, map[string]interface{}{ | ||
"user_id": bob.UserID, | ||
"reason": "testing", | ||
}), | ||
) | ||
|
||
must.MatchResponse(t, resp, match.HTTPResponse{ | ||
StatusCode: 403, | ||
}) | ||
} | ||
``` | ||
|
||
Complement needs to be bootstrapped in when running `go test`. This is doing via a `./tests/main_test.go` file: | ||
```go | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/matrix-org/complement" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
complement.TestMain(m, "some_namespace_for_these_tests") | ||
} | ||
``` | ||
If you are only running these tests and no other Complement tests (e.g the main ones in the Complement repo) *in parallel* (i.e `go test ./complement/tests ./myrepo/tests`) then the namespace value doesn't matter. If you _are_ running other tests in parallel the namespace needs to be unique for all possible Complement test packages, otherwise you will get container conflicts. So don't call it "fed" or "csapi" as they are used by the main Complement tests. | ||
|
||
Now set up a `COMPLEMENT_BASE_IMAGE` and run `COMPLEMENT_BASE_IMAGE=homeserver:latest go test -v ./tests`: | ||
``` | ||
2023/10/25 14:39:51 config: &{BaseImageURI:homeserver:latest DebugLoggingEnabled:false AlwaysPrintServerLogs:false EnvVarsPropagatePrefix: SpawnHSTimeout:30s KeepBlueprints:[] HostMounts:[] BaseImageURIs:map[] PackageNamespace:oor CACertificate:0x14000cea580 CAPrivateKey:0x14000cf5300 BestEffort:false HostnameRunningComplement:host.docker.internal EnableDirtyRuns:false HSPortBindingIP:127.0.0.1 PostTestScript:} | ||
=== RUN TestCannotKickNonPresentUser | ||
foo_test.go:14: Deploy times: 4.543523667s blueprints, 3.352760416s containers | ||
client.go:621: [CSAPI] POST hs1/_matrix/client/v3/register => 200 OK (16.544958ms) | ||
client.go:621: [CSAPI] POST hs1/_matrix/client/v3/register => 200 OK (13.813708ms) | ||
client.go:621: [CSAPI] POST hs1/_matrix/client/v3/createRoom => 200 OK (56.164792ms) | ||
client.go:621: [CSAPI] POST hs1/_matrix/client/v3/rooms/!ajUaasESMwLZSTpzkq:hs1/kick => 403 Forbidden (19.165125ms) | ||
--- PASS: TestCannotKickNonPresentUser (8.31s) | ||
PASS | ||
ok oor/tests 8.829s | ||
``` | ||
|
||
|
||
NOTE: You currently cannot set up mock federation servers as that package is still internal. You can test CSAPI and deploy >1 HS though. |
This file contains 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 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
Oops, something went wrong.