summary refs log tree commit diff
diff options
context:
space:
mode:
authorNeil Johnson <neil@matrix.org>2018-08-09 11:42:02 +0100
committerNeil Johnson <neil@matrix.org>2018-08-09 11:42:02 +0100
commit3dce9050cf4b175bc84b5fa45f4c480ac5ddeec9 (patch)
treec371df3e91aa4e6c9c6d573a690e1ab7748def44
parentMerge branch 'develop' of github.com:matrix-org/synapse into neilj/mau_sync_b... (diff)
parentMerge pull request #3655 from matrix-org/neilj/disable_hs (diff)
downloadsynapse-3dce9050cf4b175bc84b5fa45f4c480ac5ddeec9.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/mau_sync_block
-rw-r--r--changelog.d/3655.feature1
-rw-r--r--synapse/api/auth.py4
-rw-r--r--synapse/api/errors.py1
-rw-r--r--synapse/config/server.py4
-rw-r--r--tests/api/test_auth.py11
-rw-r--r--tests/utils.py2
6 files changed, 22 insertions, 1 deletions
diff --git a/changelog.d/3655.feature b/changelog.d/3655.feature
new file mode 100644
index 0000000000..1134e549e7
--- /dev/null
+++ b/changelog.d/3655.feature
@@ -0,0 +1 @@
+Ability to disable client/server Synapse via conf toggle
diff --git a/synapse/api/auth.py b/synapse/api/auth.py
index 91b23ff1d7..9c62ec4374 100644
--- a/synapse/api/auth.py
+++ b/synapse/api/auth.py
@@ -779,6 +779,10 @@ class Auth(object):
         """Checks if the user should be rejected for some external reason,
         such as monthly active user limiting or global disable flag
         """
+        if self.hs.config.hs_disabled:
+            raise AuthError(
+                403, self.hs.config.hs_disabled_message, errcode=Codes.HS_DISABLED
+            )
         if self.hs.config.limit_usage_by_mau is True:
             current_mau = yield self.store.get_monthly_active_count()
             if current_mau >= self.hs.config.max_mau_value:
diff --git a/synapse/api/errors.py b/synapse/api/errors.py
index 70400347bc..dc3bed5fcb 100644
--- a/synapse/api/errors.py
+++ b/synapse/api/errors.py
@@ -57,6 +57,7 @@ class Codes(object):
     CONSENT_NOT_GIVEN = "M_CONSENT_NOT_GIVEN"
     CANNOT_LEAVE_SERVER_NOTICE_ROOM = "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM"
     MAU_LIMIT_EXCEEDED = "M_MAU_LIMIT_EXCEEDED"
+    HS_DISABLED = "M_HS_DISABLED"
     UNSUPPORTED_ROOM_VERSION = "M_UNSUPPORTED_ROOM_VERSION"
     INCOMPATIBLE_ROOM_VERSION = "M_INCOMPATIBLE_ROOM_VERSION"
 
diff --git a/synapse/config/server.py b/synapse/config/server.py
index 114d7a9815..3b078d72ca 100644
--- a/synapse/config/server.py
+++ b/synapse/config/server.py
@@ -78,6 +78,10 @@ class ServerConfig(Config):
             "mau_limit_reserved_threepids", []
         )
 
+        # Options to disable HS
+        self.hs_disabled = config.get("hs_disabled", False)
+        self.hs_disabled_message = config.get("hs_disabled_message", "")
+
         # FIXME: federation_domain_whitelist needs sytests
         self.federation_domain_whitelist = None
         federation_domain_whitelist = config.get(
diff --git a/tests/api/test_auth.py b/tests/api/test_auth.py
index 5dc3398300..fbb96361a8 100644
--- a/tests/api/test_auth.py
+++ b/tests/api/test_auth.py
@@ -21,7 +21,7 @@ from twisted.internet import defer
 
 import synapse.handlers.auth
 from synapse.api.auth import Auth
-from synapse.api.errors import AuthError
+from synapse.api.errors import AuthError, Codes
 from synapse.types import UserID
 
 from tests import unittest
@@ -469,3 +469,12 @@ class AuthTestCase(unittest.TestCase):
             return_value=defer.succeed(small_number_of_users)
         )
         yield self.auth.check_auth_blocking()
+
+    @defer.inlineCallbacks
+    def test_hs_disabled(self):
+        self.hs.config.hs_disabled = True
+        self.hs.config.hs_disabled_message = "Reason for being disabled"
+        with self.assertRaises(AuthError) as e:
+            yield self.auth.check_auth_blocking()
+        self.assertEquals(e.exception.errcode, Codes.HS_DISABLED)
+        self.assertEquals(e.exception.code, 403)
diff --git a/tests/utils.py b/tests/utils.py
index 5d49692c58..3f17304934 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -74,6 +74,8 @@ def setup_test_homeserver(name="test", datastore=None, config=None, reactor=None
         config.media_storage_providers = []
         config.auto_join_rooms = []
         config.limit_usage_by_mau = False
+        config.hs_disabled = False
+        config.hs_disabled_message = ""
         config.max_mau_value = 50
         config.mau_limits_reserved_threepids = []