Skip to content

Commit 7e24309

Browse files
committed
Merge branch 'dev'
2 parents 8ae803f + 6383750 commit 7e24309

12 files changed

Lines changed: 105 additions & 67 deletions

File tree

.github/workflows/tests.yml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: [3.7, 3.8, 3.9, "3.10"]
16+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
1717

1818
steps:
1919
- uses: actions/checkout@v2
@@ -25,12 +25,14 @@ jobs:
2525
run: |
2626
sudo apt install build-essential python3-dev libffi-dev \
2727
sqlite3 libssl-dev libjpeg-dev libxslt1-dev \
28-
python3-venv libyaml-dev
28+
python3-venv libyaml-dev -y
2929
30-
mkdir -p synapse_test
31-
python3 -m venv synapse_test/env
32-
source synapse_test/env/bin/activate
33-
pip install --upgrade pip setuptools wheel flake8 pytest matrix-synapse pytest-rerunfailures .
30+
if [ ! -d synapse_test ]; then
31+
mkdir -p synapse_test
32+
python3 -m venv synapse_test/env
33+
source synapse_test/env/bin/activate
34+
pip install --upgrade flake8 pytest matrix-synapse .
35+
fi
3436
cd synapse_test
3537
python -m synapse.app.homeserver \
3638
--server-name localhost \
@@ -42,18 +44,24 @@ jobs:
4244
sudo wget -qO /usr/bin/yq "https://github.com/mikefarah/yq/releases/download/$latest_yq/yq_linux_amd64" && sudo chmod +x /usr/bin/yq
4345
4446
# Enable server notices
45-
sed -i '/#server_notices:/s/^#//' homeserver.yaml
46-
sed -i '/# system_mxid_localpart: notices/s/^#//' homeserver.yaml
47-
sed -i '/# system_mxid_display_name: "Server Notices"/s/^#//' homeserver.yaml
48-
sed -i '/# system_mxid_avatar_url:.*/s/^#//' homeserver.yaml
49-
sed -i '/# room_name: "Server Notices"/s/^#//' homeserver.yaml
50-
yq e -i '.rc_login.address.per_second = 0.1' homeserver.yaml
51-
yq e -i '.rc_login.address.burst_count = 20' homeserver.yaml
52-
yq e -i '.rc_login.account.per_second = 0.1' homeserver.yaml
53-
yq e -i '.rc_login.account.burst_count = 20' homeserver.yaml
54-
yq e -i '.rc_login.failed_attempts.per_second = 0.1' homeserver.yaml
55-
yq e -i '.rc_login.failed_attempts.burst_count = 20' homeserver.yaml
56-
echo -e "experimental_features:\n groups_enabled: true" >> homeserver.yaml
47+
cat << EOF >> homeserver.yaml
48+
49+
server_notices:
50+
system_mxid_localpart: notices
51+
system_mxid_display_name: "Server Notices"
52+
system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ"
53+
room_name: "Server Notices"
54+
rc_login:
55+
address:
56+
per_second: 0.1
57+
burst_count: 20
58+
account:
59+
per_second: 0.1
60+
burst_count: 20
61+
failed_attempts:
62+
per_second: 0.1
63+
burst_count: 20
64+
EOF
5765
5866
synctl start
5967
@@ -74,6 +82,7 @@ jobs:
7482
"initial_device_display_name":"Testing curl"}')
7583
echo "$login2" | grep -oP '(?<="access_token":").*?(?=")' > admin.token
7684
if [ ! -s admin.token ] | [ ! -s user.token ]; then
85+
echo "Error in retrieving access tokens. Could there be a Synapse instance running?"
7786
synctl stop
7887
exit 2
7988
fi
@@ -87,4 +96,4 @@ jobs:
8796
- name: Unit test
8897
run: |
8998
source synapse_test/env/bin/activate
90-
pytest -v --reruns 5
99+
pytest -v

TODO.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ This document describes what need to be changed or added due to the changes made
2020
### 1.68.0
2121
1. Add an admin API endpoint to fetch messages within a particular window of time. ([#13672](https://github.com/matrix-org/synapse/issues/13672))
2222
2. Add an admin API endpoint to find a user based on their external ID in an auth provider. ([#13810](https://github.com/matrix-org/synapse/issues/13810))
23+
24+
### 1.72.0
25+
1. Add an Admin API endpoint for user lookup based on third-party ID (3PID). Contributed by @ashfame. ([#14405](https://github.com/matrix-org/synapse/issues/14405))
26+

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
httpx>=0.21.1
1+
httpx>=0.23.3

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Programming Language :: Python :: 3.8",
2424
"Programming Language :: Python :: 3.9",
2525
"Programming Language :: Python :: 3.10",
26+
"Programming Language :: Python :: 3.11",
2627
"License :: OSI Approved :: MIT License",
2728
"Operating System :: OS Independent",
2829
"Development Status :: 4 - Beta",
@@ -33,6 +34,6 @@
3334
],
3435
python_requires='>=3.7',
3536
install_requires=[
36-
'httpx>=0.21.1'
37+
'httpx>=0.23.3'
3738
]
3839
)

synapse_admin/base.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from datetime import datetime
2828
from getpass import getpass
2929
from pathlib import Path
30+
from stat import S_IREAD, S_IWRITE
3031
from typing import Tuple, Any, Union
3132

3233

@@ -395,6 +396,35 @@ def _save_config(
395396
}
396397
with open(self.config_path, 'w') as configfile:
397398
config.write(configfile)
399+
400+
if os.name == "nt":
401+
import subprocess
402+
command = (
403+
"icacls <file> /reset && "
404+
"icacls <file> /grant <user:permission> && "
405+
"icacls <file> /inheritance:d && "
406+
"icacls <file> /remove *S-1-1-0 *S-1-5-11 "
407+
"*S-1-5-32-544 *S-1-5-32-545 *S-1-5-18"
408+
).split(" ")
409+
# Handle space
410+
command[7] = f"{os.getlogin()}:rw"
411+
command[1] = command[5] = self.config_path
412+
command[10] = command[14] = command[1]
413+
result = subprocess.run(command, shell=True)
414+
if result.returncode != 0:
415+
print(
416+
"[WARN] Error occur while setting "
417+
"configurion file's permission."
418+
)
419+
else:
420+
try:
421+
os.chmod(self.config_path, S_IREAD ^ S_IWRITE)
422+
except PermissionError:
423+
print(
424+
"[WARN] Got permission denied while "
425+
"setting configurion file's permission."
426+
)
427+
398428
return True
399429

400430
def modify_config(

synapse_admin/management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def announce(
134134
raise ValueError("Argument must be a non-empty str or True")
135135
if announcement is None and attachment is None:
136136
raise ValueError(
137-
"You must at least specify"
137+
"You must at least specify "
138138
"announcement or attachment"
139139
)
140140
userid = self.validate_username(userid)

synapse_admin/media.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def delete_local_media(
377377
Returns:
378378
str: the deletion is success or not
379379
"""
380+
# TODO: remove quarantine if needed
380381
if server_name is None:
381382
server_name = self.server_addr
382383
mediaid = self.extract_media_id(mediaid)
@@ -430,8 +431,8 @@ def delete_local_media_by_condition(
430431
resp = self.connection.request(
431432
"POST",
432433
self.admin_patterns(
433-
f"/media/{server_name}/delete?before_ts="
434-
f"{timestamp}&size_gt={size_gt}{optional_str}", 1
434+
f"/media/delete?before_ts={timestamp}"
435+
f"&size_gt={size_gt}{optional_str}", 1
435436
),
436437
json={},
437438
)

testing_env.sh

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ sudo apt install build-essential python3-dev libffi-dev \
44
sqlite3 libssl-dev libjpeg-dev libxslt1-dev \
55
python3-venv libyaml-dev -y
66

7-
mkdir -p synapse_test
8-
pip3 install --upgrade virtualenv
9-
python3 -m venv synapse_test/env
10-
source synapse_test/env/bin/activate
11-
pip install --upgrade pip setuptools wheel flake8 pytest matrix-synapse .
7+
if [ ! -d synapse_test ]; then
8+
mkdir -p synapse_test
9+
python3 -m venv synapse_test/env
10+
source synapse_test/env/bin/activate
11+
pip install --upgrade flake8 pytest matrix-synapse .
12+
fi
1213
cd synapse_test
1314
python -m synapse.app.homeserver \
1415
--server-name localhost \
@@ -21,18 +22,24 @@ latest_yq=$(wget -qO- https://github.com/mikefarah/yq/releases/latest | egrep -o
2122
sudo wget -qO /usr/bin/yq "https://github.com/mikefarah/yq/releases/download/$latest_yq/yq_linux_amd64" && sudo chmod +x /usr/bin/yq
2223

2324
# Enable server notices
24-
sed -i '/#server_notices:/s/^#//' homeserver.yaml
25-
sed -i '/# system_mxid_localpart: notices/s/^#//' homeserver.yaml
26-
sed -i '/# system_mxid_display_name: "Server Notices"/s/^#//' homeserver.yaml
27-
sed -i '/# system_mxid_avatar_url:.*/s/^#//' homeserver.yaml
28-
sed -i '/# room_name: "Server Notices"/s/^#//' homeserver.yaml
29-
yq e -i '.rc_login.address.per_second = 0.1' homeserver.yaml
30-
yq e -i '.rc_login.address.burst_count = 20' homeserver.yaml
31-
yq e -i '.rc_login.account.per_second = 0.1' homeserver.yaml
32-
yq e -i '.rc_login.account.burst_count = 20' homeserver.yaml
33-
yq e -i '.rc_login.failed_attempts.per_second = 0.1' homeserver.yaml
34-
yq e -i '.rc_login.failed_attempts.burst_count = 20' homeserver.yaml
35-
echo -e "experimental_features:\n groups_enabled: true" >> homeserver.yaml
25+
cat << EOF >> homeserver.yaml
26+
27+
server_notices:
28+
system_mxid_localpart: notices
29+
system_mxid_display_name: "Server Notices"
30+
system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ"
31+
room_name: "Server Notices"
32+
rc_login:
33+
address:
34+
per_second: 0.1
35+
burst_count: 20
36+
account:
37+
per_second: 0.1
38+
burst_count: 20
39+
failed_attempts:
40+
per_second: 0.1
41+
burst_count: 20
42+
EOF
3643

3744

3845
synctl start
@@ -54,6 +61,7 @@ login2=$(curl -s 'http://localhost:8008/_matrix/client/r0/login' --compressed \
5461
"initial_device_display_name":"Testing curl"}')
5562
echo "$login2" | grep -oP '(?<="access_token":").*?(?=")' > admin.token
5663
if [ ! -s admin.token ] | [ ! -s user.token ]; then
64+
echo "Error in retrieving access tokens. Could there be a Synapse instance running?"
5765
synctl stop
5866
exit 2
5967
fi

tests/test_1_user.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ def test_user_registration_tokens_lists():
324324
assert user_handler.registration_tokens.create()
325325
assert len(user_handler.registration_tokens.lists()) == 2
326326
assert user_handler.registration_tokens.create(
327-
expiry_time=Utility.get_current_time(10)
327+
expiry_time=Utility.get_current_time(3000)
328328
)
329-
time.sleep(10)
329+
time.sleep(5)
330330
assert len(user_handler.registration_tokens.lists(True)) == 2
331331
assert len(user_handler.registration_tokens.lists(False)) == 1
332332
assert len(user_handler.registration_tokens.lists()) == 3
@@ -358,7 +358,7 @@ def test_user_registration_tokens_create():
358358
)
359359
assert len(result["token"]) == 10
360360
assert result["uses_allowed"] == 10
361-
expiry = Utility.get_current_time(10)
361+
expiry = Utility.get_current_time(1000)
362362
result = user_handler.registration_tokens.create(
363363
expiry_time=expiry
364364
)

0 commit comments

Comments
 (0)