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

Remove empty rooms #30

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
needs: build
steps:
- name: Add hosts for integration tests
run: sudo echo "127.0.0.1 localhost auth.example.com matrix.example.com matrix1.example.com matrix2.example.com matrix3.example.com federation.example.com" | sudo tee -a /etc/hosts
run: sudo echo "127.0.0.1 localhost auth.example.com matrix.example.com matrix1.example.com matrix2.example.com matrix3.example.com federation.example.com matrix.external.com" | sudo tee -a /etc/hosts
- uses: actions/checkout@v3
- name: Set up Node LTS
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ docker run -d -p 3000:3000 \
-e JITSI_PREFERRED_DOMAIN=meet.tom-dev.xyz \
-e MATRIX_SERVER=matrix.example.com \
-e MATRIX_DATABASE_ENGINE=pg \
-e MATRIX_DATABASE_HOST=synapse-db \
-e MATRIX_DATABASE_HOST=synapsedb \
-e MATRIX_DATABASE_NAME=synapse \
-e MATRIX_DATABASE_PASSWORD=synapse!1 \
-e MATRIX_DATABASE_USER=synapse \
Expand Down
178 changes: 89 additions & 89 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/federation-server/src/__testData__/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '3.8'
services:
postgresql:
image: postgres:13-bullseye
container_name: postgresql
volumes:
- ./synapse-data/matrix.example.com.log.config:/data/matrix.example.com.log.config
- ./db/init-synapse-db.sh:/docker-entrypoint-initdb.d/init-synapse-db.sh
Expand All @@ -23,6 +24,7 @@ services:

synapse-federation: &synapse_template
image: matrixdotorg/synapse:v1.89.0
container_name: synapse-federation
volumes:
- ./synapse-data:/data
- ./nginx/ssl/ca.pem:/etc/ssl/certs/ca.pem
Expand All @@ -44,6 +46,7 @@ services:

synapse-1:
<<: *synapse_template
container_name: synapse-1
environment:
- UID=${MYUID}
- VIRTUAL_PORT=8008
Expand All @@ -52,6 +55,7 @@ services:

synapse-2:
<<: *synapse_template
container_name: synapse-2
environment:
- UID=${MYUID}
- VIRTUAL_PORT=8008
Expand All @@ -60,6 +64,7 @@ services:

synapse-3:
<<: *synapse_template
container_name: synapse-3
environment:
- UID=${MYUID}
- VIRTUAL_PORT=8008
Expand Down Expand Up @@ -93,6 +98,7 @@ services:

federation-server:
image: federation-server
container_name: federation-server
build:
context: ../../../..
dockerfile: ./packages/federation-server/Dockerfile
Expand All @@ -117,6 +123,7 @@ services:

identity-server-1: &identity-server-template
image: identity-server
container_name: identity-server-1
build:
context: ../../../..
dockerfile: ./packages/federation-server/src/__testData__/identity-server/Dockerfile
Expand All @@ -139,6 +146,7 @@ services:

identity-server-2:
<<: *identity-server-template
container_name: identity-server-2
depends_on:
annuaire:
condition: service_started
Expand All @@ -156,6 +164,7 @@ services:

identity-server-3:
<<: *identity-server-template
container_name: identity-server-3
depends_on:
annuaire:
condition: service_started
Expand All @@ -173,6 +182,7 @@ services:

nginx-proxy:
image: nginxproxy/nginx-proxy
container_name: nginx-proxy
ports:
- 443:443
volumes:
Expand Down
81 changes: 23 additions & 58 deletions packages/federation-server/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Hash } from '@twake/crypto'
import dockerComposeV1, { v2 as dockerComposeV2 } from 'docker-compose'
import express from 'express'
import fs from 'fs'
import type * as http from 'http'
Expand Down Expand Up @@ -57,7 +56,6 @@ describe('Federation server', () => {
})

describe('Integration tests', () => {
let containerNameSuffix: string
let startedCompose: StartedDockerComposeEnvironment
let identity1IPAddress: string
let identity2IPAddress: string
Expand Down Expand Up @@ -172,43 +170,17 @@ describe('Federation server', () => {
syswideCas.addCAs(
path.join(pathToTestDataFolder, 'nginx', 'ssl', 'ca.pem')
)
Promise.allSettled([dockerComposeV1.version(), dockerComposeV2.version()])
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((results) => {
const promiseSucceededIndex = results.findIndex(
(res) => res.status === 'fulfilled'
)
if (promiseSucceededIndex === -1) {
throw new Error('Docker compose is not installed')
}
containerNameSuffix = promiseSucceededIndex === 0 ? '_' : '-'
return new DockerComposeEnvironment(
path.join(pathToTestDataFolder),
'docker-compose.yml'
)
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
.withWaitStrategy(
`postgresql${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse-federation${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse-1${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse-2${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse-3${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.up()
})
new DockerComposeEnvironment(
path.join(pathToTestDataFolder),
'docker-compose.yml'
)
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
.withWaitStrategy('postgresql', Wait.forHealthCheck())
.withWaitStrategy('synapse-federation', Wait.forHealthCheck())
.withWaitStrategy('synapse-1', Wait.forHealthCheck())
.withWaitStrategy('synapse-2', Wait.forHealthCheck())
.withWaitStrategy('synapse-3', Wait.forHealthCheck())
.up()
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((upResult) => {
startedCompose = upResult
Expand Down Expand Up @@ -275,10 +247,10 @@ describe('Federation server', () => {

beforeAll((done) => {
identity1IPAddress = startedCompose
.getContainer(`identity-server-1${containerNameSuffix}1`)
.getContainer(`identity-server-1`)
.getIpAddress('test')
identity2IPAddress = startedCompose
.getContainer(`identity-server-2${containerNameSuffix}1`)
.getContainer(`identity-server-2`)
.getIpAddress('test')

confOriginalContent = fs.readFileSync(
Expand All @@ -295,9 +267,8 @@ describe('Federation server', () => {
'utf-8'
)

federationServerContainer = startedCompose.getContainer(
`federation-server${containerNameSuffix}1`
)
federationServerContainer =
startedCompose.getContainer('federation-server')

federationServerContainer
.restart()
Expand Down Expand Up @@ -746,25 +717,19 @@ describe('Federation server', () => {
'Certificates files for federation server has not been created'
)
return Promise.all([
startedCompose
.getContainer(`identity-server-1${containerNameSuffix}1`)
.restart(),
startedCompose
.getContainer(`identity-server-2${containerNameSuffix}1`)
.restart(),
startedCompose
.getContainer(`identity-server-3${containerNameSuffix}1`)
.restart()
startedCompose.getContainer('identity-server-1').restart(),
startedCompose.getContainer('identity-server-2').restart(),
startedCompose.getContainer('identity-server-3').restart()
])
})
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then(() => {
identity1IPAddress = startedCompose
.getContainer(`identity-server-1${containerNameSuffix}1`)
.getContainer(`identity-server-1`)
.getIpAddress('test')

identity2IPAddress = startedCompose
.getContainer(`identity-server-2${containerNameSuffix}1`)
.getContainer(`identity-server-2`)
.getIpAddress('test')

const testConfig: Config = {
Expand All @@ -776,16 +741,16 @@ describe('Federation server', () => {
database_user: 'twake',
database_password: 'twake!1',
database_host: `${startedCompose
.getContainer(`postgresql${containerNameSuffix}1`)
.getContainer(`postgresql`)
.getHost()}:5432`,
database_name: 'federation',
ldap_base: 'dc=example,dc=com',
ldap_uri: `ldap://${startedCompose
.getContainer(`postgresql${containerNameSuffix}1`)
.getContainer(`postgresql`)
.getHost()}:389`,
matrix_database_engine: 'pg',
matrix_database_host: `${startedCompose
.getContainer(`postgresql${containerNameSuffix}1`)
.getContainer(`postgresql`)
.getHost()}:5432`,
matrix_database_name: 'synapsefederation',
matrix_database_user: 'synapse',
Expand Down
57 changes: 26 additions & 31 deletions packages/matrix-application-server/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ export default class MASRouter {
* 500:
* $ref: '#/components/responses/InternalServerError'
*/
this.routes
.route('/_matrix/app/v1/transactions/:txnId')
.put(
this._middlewares(
transaction(this._appServer),
validation(Endpoints.TRANSACTIONS),
this.defaultAuthMiddleware
)
)
.all(allowCors, methodNotAllowed, errorMiddleware)
this.addRoute(
this.routes,
'/_matrix/app/v1/transactions/:txnId',
EHttpMethod.PUT,
transaction(this._appServer),
validation(Endpoints.TRANSACTIONS),
this.defaultAuthMiddleware
)

/**
* @openapi
Expand Down Expand Up @@ -119,16 +117,14 @@ export default class MASRouter {
* 500:
* $ref: '#/components/responses/InternalServerError'
*/
this.routes
.route('/_matrix/app/v1/users/:userId')
.get(
this._middlewares(
query,
validation(Endpoints.USERS),
this.defaultAuthMiddleware
)
)
.all(allowCors, methodNotAllowed, errorMiddleware)
this.addRoute(
this.routes,
'/_matrix/app/v1/users/:userId',
EHttpMethod.GET,
query,
validation(Endpoints.USERS),
this.defaultAuthMiddleware
)

/**
* @openapi
Expand Down Expand Up @@ -160,16 +156,14 @@ export default class MASRouter {
* 500:
* $ref: '#/components/responses/InternalServerError'
*/
this.routes
.route('/_matrix/app/v1/rooms/:roomAlias')
.get(
this._middlewares(
query,
validation(Endpoints.ROOMS),
this.defaultAuthMiddleware
)
)
.all(allowCors, methodNotAllowed, errorMiddleware)
this.addRoute(
this.routes,
'/_matrix/app/v1/rooms/:roomAlias',
EHttpMethod.GET,
query,
validation(Endpoints.ROOMS),
this.defaultAuthMiddleware
)

this.routes
.route(/^\/(users|rooms|transactions)\/[a-zA-Z0-9]*/g)
Expand All @@ -195,13 +189,14 @@ export default class MASRouter {
}

public addRoute(
router: Router,
path: string,
method: EHttpMethod,
controller: expressAppHandler,
validators: ValidationChain[],
authMiddleware?: expressAppHandler
): void {
const route: IRoute = this.routes.route(path)
const route: IRoute = router.route(path)
switch (method) {
case EHttpMethod.DELETE:
route.delete(this._middlewares(controller, validators, authMiddleware))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('MASRouter', () => {
const keys = Object.keys(newRoutes)
keys.forEach((method) => {
router.addRoute(
router.routes,
newRoutes[method].path,
method as EHttpMethod,
(req, res, next) => {},
Expand Down
11 changes: 11 additions & 0 deletions packages/matrix-identity-server/src/matrixDb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ type Match = (
*/
type GetAll = (table: Collections, fields: string[]) => Promise<DbGetResult>

type Insert = (
table: Collections,
values: Record<string, string | number>
) => Promise<DbGetResult>

export interface MatrixDBBackend {
ready: Promise<void>
get: Get
getAll: GetAll
insert: Insert
// match: Match
close: () => void
}
Expand Down Expand Up @@ -79,6 +85,11 @@ class MatrixDB implements MatrixDBBackend {
return await this.db.get(table, fields, filterFields)
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/promise-function-async
insert(table: Collections, values: Record<string, string | number>) {
return this.db.insert(table, values)
}

close(): void {
this.db.close()
}
Expand Down
7 changes: 3 additions & 4 deletions packages/matrix-identity-server/src/matrixDb/sql/sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Collections } from '../../db'
import { type MatrixDBBackend } from '../'
import { type Config } from '../../types'
import { type Collections } from '../../db'
import SQLite from '../../db/sql/sqlite'
import { type Config } from '../../types'

class MatrixDBSQLite extends SQLite implements MatrixDBBackend {
// eslint-disable-next-line @typescript-eslint/promise-function-async
Expand All @@ -21,8 +21,7 @@ class MatrixDBSQLite extends SQLite implements MatrixDBBackend {
/* istanbul ignore next */ // @ts-ignore
if (sqlite3.Database == null) sqlite3 = sqlite3.default
const db = (this.db = new sqlite3.Database(
conf.matrix_database_host as string,
sqlite3.OPEN_READONLY
conf.matrix_database_host as string
))
/* istanbul ignore if */
if (db == null) {
Expand Down
Loading
Loading