Diff comments:
> diff --git a/src/maasserver/websockets/tests/test_protocol.py
> b/src/maasserver/websockets/tests/test_protocol.py
> index 92dda5a..3ab1e23 100644
> --- a/src/maasserver/websockets/tests/test_protocol.py
> +++ b/src/maasserver/websockets/tests/test_protocol.py
> @@ -995,3 +996,59 @@ class TestWebSocketFactoryTransactional(
> controller.system_id,
> ),
> )
> +
> + @wait_for_reactor
> + @inlineCallbacks
> + def test_check_sessions(self):
> + factory = self.make_factory()
> +
> + session_engine = factory.getSessionEngine()
> + Session = session_engine.SessionStore.get_model_class()
> + key1 = maas_factory.make_string()
> + key2 = maas_factory.make_string()
> +
> + def make_sessions():
> + now = datetime.utcnow()
> + delta = timedelta(hours=1)
> + # first session is expired, second one is valid
> + return (
> + Session.objects.create(
> + session_key=key1, expire_date=now - delta
> + ),
> + Session.objects.create(
> + session_key=key2, expire_date=now + delta
> + ),
> + )
> +
> + session1, session2 = yield deferToDatabase(make_sessions)
> +
> + def make_protocol_with_session(session):
> + protocol = factory.buildProtocol(None)
> + protocol.transport = MagicMock()
> + protocol.transport.cookies = b""
> +
> + def authenticate(*args):
> + protocol.session = session
> + return defer.succeed(True)
> +
> + self.patch(protocol, "authenticate", authenticate)
> + self.patch(protocol, "loseConnection")
> + return protocol
> +
> + proto1 = make_protocol_with_session(session1)
> + proto2 = make_protocol_with_session(session2)
> +
> + yield proto1.connectionMade()
> + self.addCleanup(lambda: proto1.connectionLost(""))
> + yield proto2.connectionMade()
> + self.addCleanup(lambda: proto2.connectionLost(""))
> +
> + yield factory.startFactory()
> + factory.stopFactory()
> + # wait until it's stopped, sessions are checked
> + yield factory.session_checker_done
> + # the first client gets disconnected
> + proto1.loseConnection.assert_called_once_with(
> + STATUSES.GOING_AWAY, "Session expired"
In our initial discussions we opted for using a 1000 status code here, but I
think this makes sense. Also, providing the reason is very useful.
MA093 - Configurable session time out spec:
https://docs.google.com/document/d/16R14g_T1h7lL1tPP8umfWpdK6sxJPxypKEzmAnJDBsE/edit
> + )
> + proto2.loseConnection.assert_not_called()
--
https://code.launchpad.net/~ack/maas/+git/maas/+merge/438669
Your team MAAS Maintainers is requested to review the proposed merge of
~ack/maas:websocket-check-expired-sessions into maas:master.
--
Mailing list: https://launchpad.net/~sts-sponsors
Post to : sts-sponsors@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sts-sponsors
More help : https://help.launchpad.net/ListHelp