-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8653451
commit d4c1270
Showing
3 changed files
with
119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# This file is licensed under the Affero General Public License (AGPL) version 3. | ||
# | ||
# Copyright (C) 2024 New Vector, Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# See the GNU Affero General Public License for more details: | ||
# <https://www.gnu.org/licenses/agpl-3.0.html>. |
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,12 @@ | ||
# | ||
# This file is licensed under the Affero General Public License (AGPL) version 3. | ||
# | ||
# Copyright (C) 2024 New Vector, Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# See the GNU Affero General Public License for more details: | ||
# <https://www.gnu.org/licenses/agpl-3.0.html>. |
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,95 @@ | ||
# | ||
# This file is licensed under the Affero General Public License (AGPL) version 3. | ||
# | ||
# Copyright (C) 2024 New Vector, Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# See the GNU Affero General Public License for more details: | ||
# <https://www.gnu.org/licenses/agpl-3.0.html>. | ||
|
||
from typing import Dict | ||
|
||
from twisted.web.resource import Resource | ||
|
||
from synapse.rest import admin | ||
from synapse.rest.client import login | ||
from synapse.rest.synapse.client import build_synapse_client_resource_tree | ||
|
||
from tests import unittest | ||
|
||
|
||
class FederationWhitelistTests(unittest.HomeserverTestCase): | ||
servlets = [ | ||
admin.register_servlets_for_client_rest_resource, | ||
login.register_servlets, | ||
] | ||
|
||
def create_resource_dict(self) -> Dict[str, Resource]: | ||
base = super().create_resource_dict() | ||
base.update(build_synapse_client_resource_tree(self.hs)) | ||
return base | ||
|
||
def test_default(self) -> None: | ||
"By default the endpoint should 404" | ||
channel = self.make_request( | ||
"GET", "/_synapse/client/config/federation_whitelist", shorthand=False | ||
) | ||
|
||
self.assertEqual(channel.code, 404) | ||
|
||
@unittest.override_config({"extension_federation_whitelist_endpoint": True}) | ||
def test_no_auth(self) -> None: | ||
"Endpoint requires auth when enabled" | ||
|
||
channel = self.make_request( | ||
"GET", "/_synapse/client/config/federation_whitelist", shorthand=False | ||
) | ||
|
||
self.assertEqual(channel.code, 401) | ||
|
||
@unittest.override_config({"extension_federation_whitelist_endpoint": True}) | ||
def test_no_whitelist(self) -> None: | ||
"Test when there is no whitelist configured" | ||
|
||
self.register_user("user", "password") | ||
tok = self.login("user", "password") | ||
|
||
channel = self.make_request( | ||
"GET", | ||
"/_synapse/client/config/federation_whitelist", | ||
shorthand=False, | ||
access_token=tok, | ||
) | ||
|
||
self.assertEqual(channel.code, 200) | ||
self.assertEqual( | ||
channel.json_body, {"whitelist_enabled": False, "whitelist": []} | ||
) | ||
|
||
@unittest.override_config( | ||
{ | ||
"extension_federation_whitelist_endpoint": True, | ||
"federation_domain_whitelist": ["example.com"], | ||
} | ||
) | ||
def test_whitelist(self) -> None: | ||
"Test when there is a whitelist configured" | ||
|
||
self.register_user("user", "password") | ||
tok = self.login("user", "password") | ||
|
||
channel = self.make_request( | ||
"GET", | ||
"/_synapse/client/config/federation_whitelist", | ||
shorthand=False, | ||
access_token=tok, | ||
) | ||
|
||
self.assertEqual(channel.code, 200) | ||
self.assertEqual( | ||
channel.json_body, {"whitelist_enabled": True, "whitelist": ["example.com"]} | ||
) |