Description:
No-op integration of AuthenticationTokenHandler
This branch simply hooks up the AuthenticationTokenHandler everywhere it
needs to be. It isn't actually utilized yet. That will be the next
branch (which has been sketched but will not arrive within the next 30
minutes :-) ). No QA.
Affected files (+42, -9 lines):
A [revision details]
M server/guiserver/apps.py
M server/guiserver/auth.py
M server/guiserver/handlers.py
M server/guiserver/tests/test_apps.py
M server/guiserver/tests/test_auth.py
M server/guiserver/tests/test_handlers.py
M server/guiserver/tests/test_utils.py
Index: server/guiserver/apps.py
=== modified file 'server/guiserver/apps.py'
--- server/guiserver/apps.py 2013-11-14 14:08:23 +0000
+++ server/guiserver/apps.py 2013-11-22 15:53:02 +0000
@@ -44,6 +44,7 @@
# Set up handlers.
server_handlers = []
if not options.sandbox:
+ tokens = auth.AuthenticationTokenHandler() websocket_handler_options = {
# The Juju API backend url. 'apiurl': options.apiurl,
@@ -51,6 +52,8 @@ 'auth_backend': auth.get_backend(options.apiversion),
# The Juju deployer to use for importing bundles. 'deployer': deployer,
+ # The tokens collection for authentication token requests.
+ 'tokens': tokens,
} server_handlers.append(
# Handle WebSocket connections.
Index: server/guiserver/auth.py
=== modified file 'server/guiserver/auth.py'
--- server/guiserver/auth.py 2013-11-22 18:06:17 +0000
+++ server/guiserver/auth.py 2013-11-22 18:10:50 +0000
@@ -71,9 +71,11 @@
user logs out, there is no need to handle the log out process.
"""
Create a new WebSocket client and connect it to the Juju API.
@@ -85,11 +85,13 @@ self.juju_connected = False self._juju_message_queue = queue = deque()
# Set up the authentication infrastructure.
+ self.tokens = tokens
+ write_message = wrap_write_message(self)
self.user = User()
- self.auth = AuthMiddleware(self.user, auth_backend)
+ self.auth = AuthMiddleware(
+ self.user, auth_backend, tokens, write_message)
# Set up the bundle deployment infrastructure.
- self.deployment = DeployMiddleware(
- self.user, deployer, wrap_write_message(self))
+ self.deployment = DeployMiddleware(self.user, deployer,
write_message)
# Juju requires the Origin header to be included in the WebSocket
# client handshake request. Propagate the client origin if present;
# use the Juju API server as origin otherwise.
Reviewers: mp+196351_ code.launchpad. net,
Message:
Please take a look.
Description: okenHandler
No-op integration of AuthenticationT
This branch simply hooks up the AuthenticationT okenHandler everywhere it
needs to be. It isn't actually utilized yet. That will be the next
branch (which has been sketched but will not arrive within the next 30
minutes :-) ). No QA.
https:/ /code.launchpad .net/~gary/ charms/ precise/ juju-gui/ authtoken2/ +merge/ 196351
Requires: /code.launchpad .net/~gary/ charms/ precise/ juju-gui/ authtoken1/ +merge/ 196347
https:/
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/30980044/
Affected files (+42, -9 lines): guiserver/ apps.py guiserver/ auth.py guiserver/ handlers. py guiserver/ tests/test_ apps.py guiserver/ tests/test_ auth.py guiserver/ tests/test_ handlers. py guiserver/ tests/test_ utils.py
A [revision details]
M server/
M server/
M server/
M server/
M server/
M server/
M server/
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: server/ guiserver/ apps.py guiserver/ apps.py' guiserver/ apps.py 2013-11-14 14:08:23 +0000 guiserver/ apps.py 2013-11-22 15:53:02 +0000 handlers = [] tionTokenHandle r()
websocket_ handler_ options = {
'apiurl' : options.apiurl,
'auth_backend' : auth.get_ backend( options. apiversion) ,
'deployer' : deployer,
server_ handlers. append(
=== modified file 'server/
--- server/
+++ server/
@@ -44,6 +44,7 @@
# Set up handlers.
server_
if not options.sandbox:
+ tokens = auth.Authentica
# The Juju API backend url.
@@ -51,6 +52,8 @@
# The Juju deployer to use for importing bundles.
+ # The tokens collection for authentication token requests.
+ 'tokens': tokens,
}
# Handle WebSocket connections.
Index: server/ guiserver/ auth.py guiserver/ auth.py' guiserver/ auth.py 2013-11-22 18:06:17 +0000 guiserver/ auth.py 2013-11-22 18:10:50 +0000
=== modified file 'server/
--- server/
+++ server/
@@ -71,9 +71,11 @@
user logs out, there is no need to handle the log out process.
"""
- def __init__(self, user, backend):
self. _user = user
self. _backend = backend
self. _request_ id = None
+ def __init__(self, user, backend, tokens, write_message):
+ self._tokens = tokens
+ self._write_message = write_message
def in_progress(self):
Index: server/ guiserver/ handlers. py guiserver/ handlers. py' guiserver/ handlers. py 2013-11-07 18:04:32 +0000 guiserver/ handlers. py 2013-11-22 15:53:02 +0000
=== modified file 'server/
--- server/
+++ server/
@@ -69,7 +69,7 @@
"""
@ gen.coroutine
"""Initializ e the WebSocket server.
- def initialize(self, apiurl, auth_backend, deployer, io_loop=None):
+ def initialize(self, apiurl, auth_backend, deployer, tokens,
io_loop=None):
Create a new WebSocket client and connect it to the Juju API.
self. juju_connected = False
self. _juju_message_ queue = queue = deque() message( self) self.user, auth_backend) message( self)) e(self. user, deployer,
@@ -85,11 +85,13 @@
# Set up the authentication infrastructure.
+ self.tokens = tokens
+ write_message = wrap_write_
self.user = User()
- self.auth = AuthMiddleware(
+ self.auth = AuthMiddleware(
+ self.user, auth_backend, tokens, write_message)
# Set up the bundle deployment infrastructure.
- self.deployment = DeployMiddleware(
- self.user, deployer, wrap_write_
+ self.deployment = DeployMiddlewar
write_message)
# Juju requires the Origin header to be included in the WebSocket
# client handshake request. Propagate the client origin if present;
# use the Juju API server as origin otherwise.
Index: server/ guiserver/ tests/test_ apps.py guiserver/ tests/test_ apps.py' guiserver/ tests/test_ apps.py 2013-08-28 17:07:25 +0000 guiserver/ tests/test_ apps.py 2013-11-22 15:53:02 +0000 in_spec( spec, 'deployer')
self. assertIsInstanc e(deployer, base.Deployer)
=== modified file 'server/
--- server/
+++ server/
@@ -102,6 +102,13 @@
deployer = self.assert_
+ def test_tokens(self): url_spec( app, r'^/ws$') in_spec( spec, 'tokens') stance( tokens, auth.Authentica tionTokenHandle r) app(sandbox= True)
+ # The tokens instance is correctly passed to the WebSocket handler.
+ app = self.get_app()
+ spec = self.get_
+ tokens = self.assert_
+ self.assertIsIn
+
def test_sandbox(self):
# The WebSocket handler is excluded if sandbox mode is enabled.
app = self.get_
Index: server/ guiserver/ tests/test_ auth.py guiserver/ tests/test_ auth.py' guiserver/ tests/test_ auth.py 2013-11-22 18:06:17 +0000 guiserver/ tests/test_ auth.py 2013-11-22 18:11:53 +0000
=== modified file 'server/
--- server/
+++ server/
@@ -62,7 +62,12 @@
def setUp(self): ware(self. user, self.get_ auth_backend( )) tionTokenHandle r(io_loop= self.io_ loop) ware( auth_backend( ), self.tokens,
self.user = auth.User()
- self.auth = auth.AuthMiddle
+ self.io_loop = mock.Mock()
+ self.write_message = mock.Mock()
+ self.tokens = auth.Authentica
+ self.auth = auth.AuthMiddle
+ self.user, self.get_
+ self.write_message)
def assert_user(self, username, password, is_authenticated):
"""Ensure the current user reflects the given values."""
Index: server/ guiserver/ tests/test_ handlers. py guiserver/ tests/test_ handlers. py' guiserver/ tests/test_ handlers. py 2013-11-07 18:01:12 +0000 guiserver/ tests/test_ handlers. py 2013-11-22 15:53:02 +0000
self. api_close_ future = concurrent.Future()
self. deployer = base.Deployer(
self.apiurl, manage. DEFAULT_ API_VERSION, io_loop= self.io_ loop) tionTokenHandle r(io_loop= self.io_ loop)
echo_ options = {
'close_ future' : self.api_ close_future,
'io_loop' : self.io_loop,
'auth_backend' : self.auth_backend,
'deployer' : self.deployer,
'io_loop' : self.io_loop,
(r'/echo' , helpers. EchoWebSocketHa ndler, echo_options),
headers= headers, mock_protocol= mock_protocol)
=== modified file 'server/
--- server/
+++ server/
@@ -66,6 +66,7 @@
+ self.tokens = auth.Authentica
@@ -75,6 +76,7 @@
+ 'tokens': self.tokens,
}
return web.Application([
@@ -108,7 +110,8 @@
handler = self.make_handler(
yield handler.initialize(
- apiurl, self.auth_backend, self.deployer, self.io_loop)
+ apiurl, self.auth_backend, self.deployer, self.tokens,
+ self.io_loop)
raise gen.Return(handler)
@@ -228,7 +231,8 @@ clients. WebSocketClient Connection. write_message' mock_path) as mock_write_message:
initialization = handler.initialize( self.io_ loop)
handler. on_message( self.hello_ message)
self.assertFals e(mock_ write_message. called)
super( TestWebSocketHa ndlerAuthentica tion, self).setUp()
self. handler = self.make_ handler( mock_protocol= True) initialize( self.apiurl, self.auth_backend, initialize( self.io_ loop)
mock_path
= 'guiserver.
with mock.patch(
- self.apiurl, self.auth_backend, self.io_loop)
+ self.apiurl, self.auth_backend, self.deployer, self.tokens,
+ io_loop=
yield initialization
@@ -279,7 +283,9 @@
def setUp(self):
- self.handler.
self.io_loop)
+ self.handler.
+ self.apiurl, self.auth_backend, self.deployer, self.tokens,
+ io_loop=
def send_login_ request( self):
"""Create a login request and send it to the handler."""
Index: server/ guiserver/ tests/test_ utils.py guiserver/ tests/test_ utils.py' guiserver/ tests/test_ utils.py 2013-10-17 12:47:15 +0000 guiserver/ tests/test_ utils.py 2013-11-22 17:44:39 +0000
self.wrapped( 'hello' )
self. assertEqual( [], self.messages)
=== modified file 'server/
--- server/
+++ server/
@@ -158,6 +158,12 @@
+ def test_unicode(self): snowman) l(snowman, json.loads( self.messages[ 0]))
+ # It handles unicode properly.
+ snowman = u'{"Here is a snowman\u00a1": "\u2603"}'
+ self.wrapped(
+ self.assertEqua
+
class TestWsToHttp( unittest. TestCase) :