Skip to content
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

feat: matrix-admin and e2e tests #1

Merged
merged 14 commits into from
Nov 20, 2023
Merged
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Commune
#
# The shared secret is used to authenticate the registration requests.
#
# This is explicitly passed here for development purposes, it should match the
# same as on `fixtures/synapse/homeserver.yaml` for CI.
COMMUNE_REGISTRATION_SHARED_SECRET='m@;wYOUOh0f:CH5XA65sJB1^q01~DmIriOysRImot,OR_vzN&B'
COMMUNE_SYNAPSE_HOST='http://0.0.0.0:8008'

# Matrix Client
MATRIX_HOST=http://localhost:8008
MATRIX_ADMIN_TOKEN=secret
Expand Down
27 changes: 27 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
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.
-->
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: 'cargo'
directory: '/'
schedule:
interval: 'weekly'
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Continuous Integration

on:
push:
branches:
- main
pull_request:
branches: [main]
paths:
- "**"
- "!/*.md"
- "!/**.md"

concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true

jobs:
ci:
name: CI
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Rust Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --check

- name: Check clippy
run: cargo clippy --workspace -- -D warnings

- name: Unit Tests
run: cargo test -p matrix

# - name: Install Just
# uses: extractions/setup-just@v1

# - name: Generate Configuration
# run: just gen_synapse_conf

# - name: Prepare Data for Tests
# run: docker compose up -d

# - name: E2E Tests
# env:
# COMMUNE_SYNAPSE_HOST: 'http://0.0.0.0:8008'
# run: cargo test -p test -- --test-threads=1
21 changes: 21 additions & 0 deletions .github/workflows/dependabot-auto-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Dependabot auto-approve
on: pull_request_target

permissions:
pull-requests: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve a PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
23 changes: 23 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Dependabot auto-merge
on: pull_request_target

permissions:
pull-requests: write
contents: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-merge for Dependabot PRs
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[workspace]
members = [
"crates/matrix",
"crates/test"
]
resolver = "1"

[workspace.dependencies]
serde = "1.0.192"
url = { version = "2.4.1", features = ["serde"] }
13 changes: 13 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ gen_synapse_conf: dotenv
--env-file .env \
matrixdotorg/synapse:v1.96.1 generate

# Generates a de-facto admin user
gen_synapse_admin: dotenv
docker compose exec -it synapse \
register_new_matrix_user http://localhost:8008 \
-c /data/homeserver.yaml \
-u admin \
-p admin \
-a

# Runs backend dependency services
backend: dotenv
docker compose up --build
Expand All @@ -27,3 +36,7 @@ stop:
clear: stop
docker compose rm --all --force --volumes --stop
docker volume rm commune_synapse_database || true

# Runs all the tests from the `test` package. Optionally runs a single one if name pattern is provided
e2e *args='':
cargo test --package test -- --test-threads=1 $1
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@

### Getting Started

1. Generate `Synapse` server configuration
1. Create a copy of `.env.example` on `.env`

```bash
cp .env.example .env
```

2. Generate `Synapse` server configuration

```bash
just gen_synapse_conf
```

2. Run Synapse Server (and other containerized services) using Docker Compose
3. Run Synapse Server (and other containerized services) using Docker Compose
via:

```bash
Expand All @@ -35,6 +41,46 @@ use `just clear`.

> **Warning** `just clear` will remove all containers and images.

### Testing

This application has 2 layers for tests:

- `Unit`: Are usually inlined inside crates, and dont depend on any integration
- `E2E`: Lives in `test` crate and counts with the services that run the application

#### Unit

Unit tests can be executed via `cargo test -p <crate name>`, this will run
every unit test.

#### E2E

You must run Docker services as for development. In order to avoid messing up
the development environment, its recommended to use the synapse setup from
`crates/test/fixtures/synapse` replacing it with `docker/synapse`.

The only difference should be the `database` section, which uses SQLite instead.

```diff
database:
+ name: psycopg2
+ args:
+ database: /data/homeserver.db
- name: psycopg2
- txn_limit: 10000
- allow_unsafe_locale: true
- args:
- user: synapse_user
- password: secretpassword
- database: synapse
- host: synapse_database
- port: 5432
- cp_min: 5
- cp_max: 10
```

> Make sure the `.env` file is created from the contents on `.env.example`

### Application Layout

<div align="center">
Expand Down
20 changes: 20 additions & 0 deletions crates/matrix/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "matrix"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
anyhow = "1.0.75"
async-trait = "0.1.74"
hex = "0.4.3"
hmac = "0.12.1"
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", rev = "e43a25a" }
reqwest = { version = "0.11.22", features = ["json"] }
serde_path_to_error = "0.1.14"
serde_qs = "0.12.0"
sha1 = "0.10.6"

# Workspace Dependencies
serde = { workspace = true }
url = { workspace = true }
Loading
Loading