Skip to content

Commit

Permalink
Prepare nginx for queryAdmin command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MTRNord committed Oct 24, 2023
1 parent 5f3c400 commit 48824f4
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 23 deletions.
2 changes: 1 addition & 1 deletion mx-tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ up:
# Wait until postgresql is ready
- until psql postgres://mjolnir-tester:mjolnir-test@127.0.0.1:8083/mjolnir-test-db -c ""; do echo "Waiting for psql..."; sleep 1s; done
# Launch the reverse proxy, listening for connections *only* on the local host.
- docker run --rm --network host --name mjolnir-test-reverse-proxy -p 127.0.0.1:8081:80 -v $MX_TEST_CWD/test/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
- docker run --rm --network host --name mjolnir-test-reverse-proxy -p 127.0.0.1:8084:8084 -p 127.0.0.1:8085:8085 -p 127.0.0.1:8086:8086 -p 127.0.0.1:8081:8081 -v $MX_TEST_CWD/test/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
- yarn install
- npx ts-node src/appservice/cli.ts -r -u "http://host.docker.internal:9000"
- cp mjolnir-registration.yaml $MX_TEST_SYNAPSE_DIR/data/
Expand Down
89 changes: 67 additions & 22 deletions test/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,74 @@ events {

http {
server {
listen [::]:8081 ipv6only=off;

location ~ ^/_matrix/client/(r0|v3)/rooms/([^/]*)/report/(.*)$ {
# Abuse reports should be sent to Mjölnir.
# The r0 endpoint is deprecated but still used by many clients.
# As of this writing, the v3 endpoint is the up-to-date version.

# Add CORS, otherwise a browser will refuse this request.
add_header 'Access-Control-Allow-Origin' '*' always; # Note: '*' is for testing purposes. For your own server, you probably want to tighten this.
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header 'Access-Control-Max-Age' 1728000; # cache preflight value for 20 days

# Alias the regexps, to ensure that they're not rewritten.
set $room_id $2;
set $event_id $3;
proxy_pass http://127.0.0.1:8082/api/1/report/$room_id/$event_id;
listen [::]:8081 ipv6only=off;

location ~ ^/_matrix/client/(r0|v3)/rooms/([^/]*)/report/(.*)$ {
# Abuse reports should be sent to Mjölnir.
# The r0 endpoint is deprecated but still used by many clients.
# As of this writing, the v3 endpoint is the up-to-date version.

# Add CORS, otherwise a browser will refuse this request.
add_header 'Access-Control-Allow-Origin' '*' always; # Note: '*' is for testing purposes. For your own server, you probably want to tighten this.
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
add_header 'Access-Control-Max-Age' 1728000; # cache preflight value for 20 days

# Alias the regexps, to ensure that they're not rewritten.
set $room_id $2;
set $event_id $3;
proxy_pass http://127.0.0.1:8082/api/1/report/$room_id/$event_id;
}
# MSC1929 Test in best-case
location /.well-known/matrix/support {
default_type application/json;
return 200 '{
"contacts": [{
"matrix_id": "@admin:localhost",
"role": "admin"
}],
"support_page": "http://localhost"
}';
}
location / {
# Everything else should be sent to Synapse.
proxy_pass http://127.0.0.1:9999;
}
}
server {
listen [::]:8084 ipv6only=off;

# MSC1929 Test in worst-case
location /.well-known/matrix/support {
default_type application/json;
return 404 '{}';
}
}
server {
listen [::]:8085 ipv6only=off;

# MSC1929 Test in supportpage_only-case
location /.well-known/matrix/support {
default_type application/json;
return 200 '{
"support_page": "http://localhost"
}';
}
}
location / {
# Everything else should be sent to Synapse.
proxy_pass http://127.0.0.1:9999;
server {
listen [::]:8086 ipv6only=off;

# MSC1929 Test in contacts-case
location /.well-known/matrix/support {
default_type application/json;
return 200 '{
"contacts": [{
"matrix_id": "@admin:localhost",
"role": "admin"
}],
}';
}
}
}

0 comments on commit 48824f4

Please sign in to comment.