Merge lp:~rvb/maas/tunnel-ws into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 4045
Proposed branch: lp:~rvb/maas/tunnel-ws
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 159 lines (+26/-53)
6 files modified
contrib/maas-http.conf (+1/-0)
src/maasserver/static/js/angular/factories/region.js (+9/-1)
src/maasserver/static/js/angular/factories/tests/test_region.js (+15/-0)
src/maasserver/templates/maasserver/index.html (+1/-1)
src/maasserver/views/index.py (+0/-11)
src/maasserver/views/tests/test_index.py (+0/-40)
To merge this branch: bzr merge lp:~rvb/maas/tunnel-ws
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+263094@code.launchpad.net

Commit message

Proxy the websocket connections through apache.

Description of the change

Needs https://code.launchpad.net/~rvb/maas/packaging-ws-tunnel/+merge/263097 on the packaging side.
Also support using wss (websocket over SSL) if the original connection uses SSL.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good other than the one comment below.

review: Approve
Revision history for this message
Raphaël Badin (rvb) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/maas-http.conf'
2--- contrib/maas-http.conf 2015-02-16 16:37:36 +0000
3+++ contrib/maas-http.conf 2015-06-26 13:07:44 +0000
4@@ -26,6 +26,7 @@
5
6 <IfModule proxy_module>
7 ProxyPreserveHost on
8+ ProxyPass /MAAS/ws "ws://localhost:5240/MAAS/ws"
9 ProxyPass /MAAS/static/ !
10 ProxyPass /MAAS/ http://localhost:5240/MAAS/
11 ProxyPass /MAAS http://localhost:5240/MAAS/
12
13=== modified file 'src/maasserver/static/js/angular/factories/region.js'
14--- src/maasserver/static/js/angular/factories/region.js 2015-04-21 13:32:05 +0000
15+++ src/maasserver/static/js/angular/factories/region.js 2015-06-26 13:07:44 +0000
16@@ -158,12 +158,20 @@
17 this.websocket = null;
18 };
19
20+ RegionConnection.prototype._getProtocol = function() {
21+ return $window.location.protocol;
22+ };
23+
24 // Return connection url to websocket from current location and
25 // html options.
26 RegionConnection.prototype._buildUrl = function() {
27 var host = $window.location.hostname;
28 var port = $window.location.port;
29 var path = $window.location.pathname;
30+ var proto = 'ws';
31+ if (this._getProtocol() === 'https:') {
32+ proto = 'wss';
33+ }
34
35 // Port can be overridden by data-websocket-port in the base
36 // element.
37@@ -180,7 +188,7 @@
38 path += '/';
39 }
40
41- url = "ws://" + host + ":" + port + path + "ws";
42+ url = proto + "://" + host + ":" + port + path + "ws";
43
44 // Include the csrftoken in the URL if it's defined.
45 csrftoken = $cookies.csrftoken;
46
47=== modified file 'src/maasserver/static/js/angular/factories/tests/test_region.js'
48--- src/maasserver/static/js/angular/factories/tests/test_region.js 2015-04-21 15:02:56 +0000
49+++ src/maasserver/static/js/angular/factories/tests/test_region.js 2015-06-26 13:07:44 +0000
50@@ -309,6 +309,13 @@
51 });
52 });
53
54+ describe("_getProtocol", function() {
55+ it("returns window protocol", function() {
56+ expect(RegionConnection._getProtocol()).toBe(
57+ $window.location.protocol);
58+ });
59+ });
60+
61 describe("_buildUrl", function() {
62
63 it("returns url from $window.location", function() {
64@@ -317,6 +324,14 @@
65 $window.location.port + $window.location.pathname + "/ws");
66 });
67
68+ it("uses wss connection if https protocol", function() {
69+ spyOn(RegionConnection, "_getProtocol").and.returnValue("https:");
70+ $window.location.protocol = 'https:';
71+ expect(RegionConnection._buildUrl()).toBe(
72+ "wss://" + $window.location.hostname + ":" +
73+ $window.location.port + $window.location.pathname + "/ws");
74+ });
75+
76 it("uses port from data-websocket-port", function() {
77 var port = "8888";
78 var fakeElement = {
79
80=== modified file 'src/maasserver/templates/maasserver/index.html'
81--- src/maasserver/templates/maasserver/index.html 2015-05-12 09:23:06 +0000
82+++ src/maasserver/templates/maasserver/index.html 2015-06-26 13:07:44 +0000
83@@ -1,7 +1,7 @@
84 <!DOCTYPE html>
85 <html class="no-js" lang="en" data-ng-app="MAAS">
86 <head>
87- <base href="{% url 'index' %}" data-websocket-port="{{ webapp_port }}">
88+ <base href="{% url 'index' %}">
89 <title data-ng-bind="title + ' | ' + site + ' MAAS'"></title>
90
91 <meta charset="UTF-8" />
92
93=== modified file 'src/maasserver/views/index.py'
94--- src/maasserver/views/index.py 2015-02-17 13:45:34 +0000
95+++ src/maasserver/views/index.py 2015-06-26 13:07:44 +0000
96@@ -17,18 +17,7 @@
97 ]
98
99 from django.views.generic.base import TemplateView
100-from maasserver.eventloop import services
101
102
103 class IndexView(TemplateView):
104 template_name = 'maasserver/index.html'
105-
106- def get_context_data(self, **kwargs):
107- """Return context data that is passed into the template."""
108- context = super(IndexView, self).get_context_data(**kwargs)
109- try:
110- port = services.getServiceNamed("web").endpoint.port
111- except KeyError:
112- port = None
113- context['webapp_port'] = port
114- return context
115
116=== removed file 'src/maasserver/views/tests/test_index.py'
117--- src/maasserver/views/tests/test_index.py 2015-02-17 13:45:34 +0000
118+++ src/maasserver/views/tests/test_index.py 1970-01-01 00:00:00 +0000
119@@ -1,40 +0,0 @@
120-# Copyright 2015 Canonical Ltd. This software is licensed under the
121-# GNU Affero General Public License version 3 (see the file LICENSE).
122-
123-"""Test maasserver index view."""
124-
125-from __future__ import (
126- absolute_import,
127- print_function,
128- unicode_literals,
129- )
130-
131-str = None
132-
133-__metaclass__ = type
134-__all__ = []
135-
136-
137-import random
138-
139-from django.core.urlresolvers import reverse
140-from lxml.html import fromstring
141-from maasserver.testing.testcase import MAASServerTestCase
142-from maasserver.views import index as index_module
143-from mock import MagicMock
144-
145-
146-class TestIndexView(MAASServerTestCase):
147-
148- def test__adds_port_number_to_context(self):
149- self.client_log_in()
150- port = random.randint(1024, 2048)
151- fake = MagicMock()
152- fake.endpoint.port = port
153- mock_getServiceNamed = self.patch(
154- index_module.services, "getServiceNamed")
155- mock_getServiceNamed.return_value = fake
156- response = self.client.get(reverse('index'))
157- doc = fromstring(response.content)
158- self.assertEquals(
159- port, int(doc.head.find("base").get("data-websocket-port")))