Fix other test cases
This commit is contained in:
parent
fba9000152
commit
327555dddf
|
@ -61,6 +61,9 @@ class MSC3861OAuthDelegation(TestCase):
|
||||||
**default_config("test"),
|
**default_config("test"),
|
||||||
"public_baseurl": BASE_URL,
|
"public_baseurl": BASE_URL,
|
||||||
"enable_registration": False,
|
"enable_registration": False,
|
||||||
|
"login_via_existing_session": {
|
||||||
|
"enabled": False,
|
||||||
|
},
|
||||||
"experimental_features": {
|
"experimental_features": {
|
||||||
"msc3861": {
|
"msc3861": {
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
|
|
|
@ -115,6 +115,9 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
|
||||||
config = super().default_config()
|
config = super().default_config()
|
||||||
config["public_baseurl"] = BASE_URL
|
config["public_baseurl"] = BASE_URL
|
||||||
config["disable_registration"] = True
|
config["disable_registration"] = True
|
||||||
|
config["login_via_existing_session"] = {
|
||||||
|
"enabled": False,
|
||||||
|
}
|
||||||
config["experimental_features"] = {
|
config["experimental_features"] = {
|
||||||
"msc3861": {
|
"msc3861": {
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
|
|
|
@ -36,8 +36,9 @@ from tests.test_utils import make_awaitable
|
||||||
from tests.unittest import override_config
|
from tests.unittest import override_config
|
||||||
|
|
||||||
# Login flows we expect to appear in the list after the normal ones.
|
# Login flows we expect to appear in the list after the normal ones.
|
||||||
ADDITIONAL_LOGIN_FLOWS = [
|
ADDITIONAL_LOGIN_FLOWS: List[Dict] = [
|
||||||
{"type": "m.login.application_service"},
|
{"type": "m.login.application_service"},
|
||||||
|
{"type": "m.login.token", "get_login_token": True},
|
||||||
]
|
]
|
||||||
|
|
||||||
# a mock instance which the dummy auth providers delegate to, so we can see what's going
|
# a mock instance which the dummy auth providers delegate to, so we can see what's going
|
||||||
|
@ -45,6 +46,10 @@ ADDITIONAL_LOGIN_FLOWS = [
|
||||||
mock_password_provider = Mock()
|
mock_password_provider = Mock()
|
||||||
|
|
||||||
|
|
||||||
|
def sort_flows(flows: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
||||||
|
return sorted(flows, key=lambda f: f["type"])
|
||||||
|
|
||||||
|
|
||||||
class LegacyPasswordOnlyAuthProvider:
|
class LegacyPasswordOnlyAuthProvider:
|
||||||
"""A legacy password_provider which only implements `check_password`."""
|
"""A legacy password_provider which only implements `check_password`."""
|
||||||
|
|
||||||
|
@ -184,7 +189,10 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
def password_only_auth_provider_login_test_body(self) -> None:
|
def password_only_auth_provider_login_test_body(self) -> None:
|
||||||
# login flows should only have m.login.password
|
# login flows should only have m.login.password
|
||||||
flows = self._get_login_flows()
|
flows = self._get_login_flows()
|
||||||
self.assertEqual(flows, [{"type": "m.login.password"}] + ADDITIONAL_LOGIN_FLOWS)
|
self.assertEqual(
|
||||||
|
sort_flows(flows),
|
||||||
|
sort_flows([{"type": "m.login.password"}] + ADDITIONAL_LOGIN_FLOWS),
|
||||||
|
)
|
||||||
|
|
||||||
# check_password must return an awaitable
|
# check_password must return an awaitable
|
||||||
mock_password_provider.check_password.return_value = make_awaitable(True)
|
mock_password_provider.check_password.return_value = make_awaitable(True)
|
||||||
|
@ -365,7 +373,7 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
"""password auth doesn't work if it's disabled across the board"""
|
"""password auth doesn't work if it's disabled across the board"""
|
||||||
# login flows should be empty
|
# login flows should be empty
|
||||||
flows = self._get_login_flows()
|
flows = self._get_login_flows()
|
||||||
self.assertEqual(flows, ADDITIONAL_LOGIN_FLOWS)
|
self.assertEqual(sort_flows(flows), sort_flows(ADDITIONAL_LOGIN_FLOWS))
|
||||||
|
|
||||||
# login shouldn't work and should be rejected with a 400 ("unknown login type")
|
# login shouldn't work and should be rejected with a 400 ("unknown login type")
|
||||||
channel = self._send_password_login("u", "p")
|
channel = self._send_password_login("u", "p")
|
||||||
|
@ -386,9 +394,11 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
# (password must come first, because reasons)
|
# (password must come first, because reasons)
|
||||||
flows = self._get_login_flows()
|
flows = self._get_login_flows()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
flows,
|
sort_flows(flows),
|
||||||
[{"type": "m.login.password"}, {"type": "test.login_type"}]
|
sort_flows(
|
||||||
+ ADDITIONAL_LOGIN_FLOWS,
|
[{"type": "m.login.password"}, {"type": "test.login_type"}]
|
||||||
|
+ ADDITIONAL_LOGIN_FLOWS
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# login with missing param should be rejected
|
# login with missing param should be rejected
|
||||||
|
@ -519,7 +529,10 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
self.register_user("localuser", "localpass")
|
self.register_user("localuser", "localpass")
|
||||||
|
|
||||||
flows = self._get_login_flows()
|
flows = self._get_login_flows()
|
||||||
self.assertEqual(flows, [{"type": "test.login_type"}] + ADDITIONAL_LOGIN_FLOWS)
|
self.assertEqual(
|
||||||
|
sort_flows(flows),
|
||||||
|
sort_flows([{"type": "test.login_type"}] + ADDITIONAL_LOGIN_FLOWS),
|
||||||
|
)
|
||||||
|
|
||||||
# login shouldn't work and should be rejected with a 400 ("unknown login type")
|
# login shouldn't work and should be rejected with a 400 ("unknown login type")
|
||||||
channel = self._send_password_login("localuser", "localpass")
|
channel = self._send_password_login("localuser", "localpass")
|
||||||
|
@ -554,7 +567,10 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
self.register_user("localuser", "localpass")
|
self.register_user("localuser", "localpass")
|
||||||
|
|
||||||
flows = self._get_login_flows()
|
flows = self._get_login_flows()
|
||||||
self.assertEqual(flows, [{"type": "test.login_type"}] + ADDITIONAL_LOGIN_FLOWS)
|
self.assertEqual(
|
||||||
|
sort_flows(flows),
|
||||||
|
sort_flows([{"type": "test.login_type"}] + ADDITIONAL_LOGIN_FLOWS),
|
||||||
|
)
|
||||||
|
|
||||||
# login shouldn't work and should be rejected with a 400 ("unknown login type")
|
# login shouldn't work and should be rejected with a 400 ("unknown login type")
|
||||||
channel = self._send_password_login("localuser", "localpass")
|
channel = self._send_password_login("localuser", "localpass")
|
||||||
|
@ -585,7 +601,10 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
self.register_user("localuser", "localpass")
|
self.register_user("localuser", "localpass")
|
||||||
|
|
||||||
flows = self._get_login_flows()
|
flows = self._get_login_flows()
|
||||||
self.assertEqual(flows, [{"type": "test.login_type"}] + ADDITIONAL_LOGIN_FLOWS)
|
self.assertEqual(
|
||||||
|
sort_flows(flows),
|
||||||
|
sort_flows([{"type": "test.login_type"}] + ADDITIONAL_LOGIN_FLOWS),
|
||||||
|
)
|
||||||
|
|
||||||
# login shouldn't work and should be rejected with a 400 ("unknown login type")
|
# login shouldn't work and should be rejected with a 400 ("unknown login type")
|
||||||
channel = self._send_password_login("localuser", "localpass")
|
channel = self._send_password_login("localuser", "localpass")
|
||||||
|
@ -690,7 +709,10 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
self.register_user("localuser", "localpass")
|
self.register_user("localuser", "localpass")
|
||||||
|
|
||||||
flows = self._get_login_flows()
|
flows = self._get_login_flows()
|
||||||
self.assertEqual(flows, [{"type": "test.login_type"}] + ADDITIONAL_LOGIN_FLOWS)
|
self.assertEqual(
|
||||||
|
sort_flows(flows),
|
||||||
|
sort_flows([{"type": "test.login_type"}] + ADDITIONAL_LOGIN_FLOWS),
|
||||||
|
)
|
||||||
|
|
||||||
# password login shouldn't work and should be rejected with a 400
|
# password login shouldn't work and should be rejected with a 400
|
||||||
# ("unknown login type")
|
# ("unknown login type")
|
||||||
|
@ -928,7 +950,7 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.json_body)
|
self.assertEqual(channel.code, HTTPStatus.OK, channel.json_body)
|
||||||
return channel.json_body
|
return channel.json_body
|
||||||
|
|
||||||
def _get_login_flows(self) -> JsonDict:
|
def _get_login_flows(self) -> List[JsonDict]:
|
||||||
channel = self.make_request("GET", "/_matrix/client/r0/login")
|
channel = self.make_request("GET", "/_matrix/client/r0/login")
|
||||||
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
|
||||||
return channel.json_body["flows"]
|
return channel.json_body["flows"]
|
||||||
|
|
|
@ -45,6 +45,7 @@ class JWKSTestCase(HomeserverTestCase):
|
||||||
@override_config(
|
@override_config(
|
||||||
{
|
{
|
||||||
"disable_registration": True,
|
"disable_registration": True,
|
||||||
|
"login_via_existing_session": {"enabled": False},
|
||||||
"experimental_features": {
|
"experimental_features": {
|
||||||
"msc3861": {
|
"msc3861": {
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
|
@ -65,6 +66,7 @@ class JWKSTestCase(HomeserverTestCase):
|
||||||
@override_config(
|
@override_config(
|
||||||
{
|
{
|
||||||
"disable_registration": True,
|
"disable_registration": True,
|
||||||
|
"login_via_existing_session": {"enabled": False},
|
||||||
"experimental_features": {
|
"experimental_features": {
|
||||||
"msc3861": {
|
"msc3861": {
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
|
|
|
@ -187,6 +187,7 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
|
||||||
for room_version in details["support"]:
|
for room_version in details["support"]:
|
||||||
self.assertTrue(room_version in KNOWN_ROOM_VERSIONS, str(room_version))
|
self.assertTrue(room_version in KNOWN_ROOM_VERSIONS, str(room_version))
|
||||||
|
|
||||||
|
@override_config({"login_via_existing_session": {"enabled": False}})
|
||||||
def test_get_get_token_login_fields_when_disabled(self) -> None:
|
def test_get_get_token_login_fields_when_disabled(self) -> None:
|
||||||
"""By default login via an existing session is disabled."""
|
"""By default login via an existing session is disabled."""
|
||||||
access_token = self.get_success(
|
access_token = self.get_success(
|
||||||
|
@ -201,7 +202,6 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, HTTPStatus.OK)
|
self.assertEqual(channel.code, HTTPStatus.OK)
|
||||||
self.assertFalse(capabilities["m.get_login_token"]["enabled"])
|
self.assertFalse(capabilities["m.get_login_token"]["enabled"])
|
||||||
|
|
||||||
@override_config({"login_via_existing_session": {"enabled": True}})
|
|
||||||
def test_get_get_token_login_fields_when_enabled(self) -> None:
|
def test_get_get_token_login_fields_when_enabled(self) -> None:
|
||||||
access_token = self.get_success(
|
access_token = self.get_success(
|
||||||
self.auth_handler.create_access_token_for_user_id(
|
self.auth_handler.create_access_token_for_user_id(
|
||||||
|
|
|
@ -446,6 +446,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
ApprovalNoticeMedium.NONE, channel.json_body["approval_notice_medium"]
|
ApprovalNoticeMedium.NONE, channel.json_body["approval_notice_medium"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@override_config({"login_via_existing_session": {"enabled": False}})
|
||||||
def test_get_login_flows_with_login_via_existing_disabled(self) -> None:
|
def test_get_login_flows_with_login_via_existing_disabled(self) -> None:
|
||||||
"""GET /login should return m.login.token without get_login_token"""
|
"""GET /login should return m.login.token without get_login_token"""
|
||||||
channel = self.make_request("GET", "/_matrix/client/r0/login")
|
channel = self.make_request("GET", "/_matrix/client/r0/login")
|
||||||
|
@ -454,7 +455,6 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
flows = {flow["type"]: flow for flow in channel.json_body["flows"]}
|
flows = {flow["type"]: flow for flow in channel.json_body["flows"]}
|
||||||
self.assertNotIn("m.login.token", flows)
|
self.assertNotIn("m.login.token", flows)
|
||||||
|
|
||||||
@override_config({"login_via_existing_session": {"enabled": True}})
|
|
||||||
def test_get_login_flows_with_login_via_existing_enabled(self) -> None:
|
def test_get_login_flows_with_login_via_existing_enabled(self) -> None:
|
||||||
"""GET /login should return m.login.token with get_login_token true"""
|
"""GET /login should return m.login.token with get_login_token true"""
|
||||||
channel = self.make_request("GET", "/_matrix/client/r0/login")
|
channel = self.make_request("GET", "/_matrix/client/r0/login")
|
||||||
|
|
|
@ -119,6 +119,7 @@ class WellKnownTests(unittest.HomeserverTestCase):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"disable_registration": True,
|
"disable_registration": True,
|
||||||
|
"login_via_existing_session": {"enabled": False},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
def test_client_well_known_msc3861_oauth_delegation(self) -> None:
|
def test_client_well_known_msc3861_oauth_delegation(self) -> None:
|
||||||
|
|
Loading…
Reference in New Issue