Merge lp:~ralsina/ubuntu-push/merge-automatic into lp:ubuntu-push

Proposed by Roberto Alsina
Status: Merged
Approved by: Roberto Alsina
Approved revision: no longer in the source branch.
Merged at revision: 131
Proposed branch: lp:~ralsina/ubuntu-push/merge-automatic
Merge into: lp:ubuntu-push
Diff against target: 934 lines (+296/-151)
23 files modified
bus/unitygreeter/unitygreeter.go (+52/-0)
client/service/postal.go (+14/-0)
client/service/postal_test.go (+15/-11)
client/session/session_test.go (+4/-25)
debian/changelog (+7/-0)
docs/example-client/main.qml (+8/-0)
docs/example-client/manifest.json (+2/-2)
sampleconfigs/dev.json (+1/-1)
server/acceptance/acceptance_test.go (+1/-1)
server/acceptance/ssl/README (+1/-1)
server/acceptance/ssl/testing.cert (+7/-7)
server/acceptance/ssl/testing.key (+7/-7)
server/acceptance/suites/broadcast.go (+1/-1)
server/acceptance/suites/suite.go (+1/-1)
server/config_test.go (+12/-11)
server/dev/server.go (+2/-2)
server/listener/listener.go (+4/-13)
server/listener/listener_test.go (+9/-17)
server/runner_devices.go (+2/-29)
server/runner_http.go (+6/-1)
server/runner_test.go (+45/-6)
server/tlsconfig.go (+53/-0)
testing/tls.go (+42/-15)
To merge this branch: bzr merge lp:~ralsina/ubuntu-push/merge-automatic
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Review via email: mp+234136@code.launchpad.net

Commit message

Updates from the automatic branch

Description of the change

Updates from the automatic branch

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve
131. By Roberto Alsina

Updates from the automatic branch
Approved by: Roberto Alsina

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'bus/unitygreeter'
2=== added file 'bus/unitygreeter/unitygreeter.go'
3--- bus/unitygreeter/unitygreeter.go 1970-01-01 00:00:00 +0000
4+++ bus/unitygreeter/unitygreeter.go 2014-09-10 15:12:43 +0000
5@@ -0,0 +1,52 @@
6+/*
7+ Copyright 2014 Canonical Ltd.
8+
9+ This program is free software: you can redistribute it and/or modify it
10+ under the terms of the GNU General Public License version 3, as published
11+ by the Free Software Foundation.
12+
13+ This program is distributed in the hope that it will be useful, but
14+ WITHOUT ANY WARRANTY; without even the implied warranties of
15+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16+ PURPOSE. See the GNU General Public License for more details.
17+
18+ You should have received a copy of the GNU General Public License along
19+ with this program. If not, see <http://www.gnu.org/licenses/>.
20+*/
21+
22+// Package unitygreeter retrieves information about the Unity Greeter
23+// using Unity's dbus interface
24+package unitygreeter
25+
26+import (
27+ "launchpad.net/ubuntu-push/bus"
28+ "launchpad.net/ubuntu-push/logger"
29+)
30+
31+// Well known address for the UnityGreeter API
32+var BusAddress bus.Address = bus.Address{
33+ Interface: "com.canonical.UnityGreeter",
34+ Path: "/",
35+ Name: "com.canonical.UnityGreeter",
36+}
37+
38+// UnityGreeter encapsulates info needed to call out to the UnityGreeter API
39+type UnityGreeter struct {
40+ bus bus.Endpoint
41+ log logger.Logger
42+}
43+
44+// New returns a new UnityGreeter that'll use the provided bus.Endpoint
45+func New(endp bus.Endpoint, log logger.Logger) *UnityGreeter {
46+ return &UnityGreeter{endp, log}
47+}
48+
49+// GetUnityGreeter returns the window stack state
50+func (greeter *UnityGreeter) IsActive() bool {
51+ result, err := greeter.bus.GetProperty("IsActive")
52+ if err != nil {
53+ greeter.log.Errorf("GetUnityGreeter call returned %v", err)
54+ return false
55+ }
56+ return result.(bool)
57+}
58
59=== modified file 'client/service/postal.go'
60--- client/service/postal.go 2014-08-21 19:05:15 +0000
61+++ client/service/postal.go 2014-09-10 15:12:43 +0000
62@@ -27,6 +27,7 @@
63 "launchpad.net/ubuntu-push/bus/emblemcounter"
64 "launchpad.net/ubuntu-push/bus/haptic"
65 "launchpad.net/ubuntu-push/bus/notifications"
66+ "launchpad.net/ubuntu-push/bus/unitygreeter"
67 "launchpad.net/ubuntu-push/bus/windowstack"
68 "launchpad.net/ubuntu-push/click"
69 "launchpad.net/ubuntu-push/click/cblacklist"
70@@ -76,6 +77,7 @@
71 EmblemCounterEndp bus.Endpoint
72 HapticEndp bus.Endpoint
73 NotificationsEndp bus.Endpoint
74+ UnityGreeterEndp bus.Endpoint
75 WindowStackEndp bus.Endpoint
76 // presenters:
77 Presenters []Presenter
78@@ -85,6 +87,7 @@
79 sound *sounds.Sound
80 // the url dispatcher, used for stuff.
81 urlDispatcher urldispatcher.URLDispatcher
82+ unityGreeter *unitygreeter.UnityGreeter
83 windowStack *windowstack.WindowStack
84 // fallback values for simplified notification usage
85 fallbackVibration *launch_helper.Vibration
86@@ -115,6 +118,7 @@
87 svc.NotificationsEndp = bus.SessionBus.Endpoint(notifications.BusAddress, log)
88 svc.EmblemCounterEndp = bus.SessionBus.Endpoint(emblemcounter.BusAddress, log)
89 svc.HapticEndp = bus.SessionBus.Endpoint(haptic.BusAddress, log)
90+ svc.UnityGreeterEndp = bus.SessionBus.Endpoint(unitygreeter.BusAddress, log)
91 svc.WindowStackEndp = bus.SessionBus.Endpoint(windowstack.BusAddress, log)
92 svc.msgHandler = svc.messageHandler
93 svc.launchers = launch_helper.DefaultLaunchers(log)
94@@ -169,6 +173,7 @@
95 } else {
96 svc.HelperPool = launch_helper.NewHelperPool(svc.launchers, svc.Log)
97 }
98+ svc.unityGreeter = unitygreeter.New(svc.UnityGreeterEndp, svc.Log)
99 svc.windowStack = windowstack.New(svc.WindowStackEndp, svc.Log)
100
101 go svc.consumeHelperResults(svc.HelperPool.Start())
102@@ -224,6 +229,7 @@
103 {"notifications", svc.NotificationsEndp},
104 {"emblemcounter", svc.EmblemCounterEndp},
105 {"haptic", svc.HapticEndp},
106+ {"unitygreeter", svc.UnityGreeterEndp},
107 {"windowstack", svc.WindowStackEndp},
108 }
109 for _, endp := range endps {
110@@ -414,6 +420,14 @@
111 // no need to log, (it's been logged already)
112 return false
113 }
114+
115+ if output.Notification.Card != nil && output.Notification.Card.Popup {
116+ if svc.unityGreeter.IsActive() {
117+ // Screen is locked, ensure popup is false
118+ output.Notification.Card.Popup = false
119+ }
120+ }
121+
122 if !svc.windowStack.IsAppFocused(app) {
123 if isBlacklisted(app) {
124 svc.Log.Debugf("notification skipped (except emblem counter) because app is blacklisted")
125
126=== modified file 'client/service/postal_test.go'
127--- client/service/postal_test.go 2014-09-01 14:32:51 +0000
128+++ client/service/postal_test.go 2014-09-10 15:12:43 +0000
129@@ -161,17 +161,18 @@
130 }
131
132 type postalSuite struct {
133- log *helpers.TestLogger
134- cfg *PostalServiceSetup
135- bus bus.Endpoint
136- notifBus bus.Endpoint
137- counterBus bus.Endpoint
138- hapticBus bus.Endpoint
139- winStackBus bus.Endpoint
140- fakeLauncher *fakeHelperLauncher
141- getTempDir func(string) (string, error)
142- oldIsBlisted func(*click.AppId) bool
143- blacklisted bool
144+ log *helpers.TestLogger
145+ cfg *PostalServiceSetup
146+ bus bus.Endpoint
147+ notifBus bus.Endpoint
148+ counterBus bus.Endpoint
149+ hapticBus bus.Endpoint
150+ unityGreeterBus bus.Endpoint
151+ winStackBus bus.Endpoint
152+ fakeLauncher *fakeHelperLauncher
153+ getTempDir func(string) (string, error)
154+ oldIsBlisted func(*click.AppId) bool
155+ blacklisted bool
156 }
157
158 type ualPostalSuite struct {
159@@ -194,6 +195,7 @@
160 ps.notifBus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true))
161 ps.counterBus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true))
162 ps.hapticBus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true))
163+ ps.unityGreeterBus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), false)
164 ps.winStackBus = testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), []windowstack.WindowsInfo{})
165 ps.fakeLauncher = &fakeHelperLauncher{ch: make(chan []byte)}
166 ps.blacklisted = false
167@@ -226,6 +228,7 @@
168 pst.NotificationsEndp = ps.notifBus
169 pst.EmblemCounterEndp = ps.counterBus
170 pst.HapticEndp = ps.hapticBus
171+ pst.UnityGreeterEndp = ps.unityGreeterBus
172 pst.WindowStackEndp = ps.winStackBus
173 pst.launchers = map[string]launch_helper.HelperLauncher{}
174 return pst
175@@ -543,6 +546,7 @@
176 svc.EmblemCounterEndp = endp
177 svc.HapticEndp = endp
178 svc.NotificationsEndp = endp
179+ svc.UnityGreeterEndp = ps.unityGreeterBus
180 svc.WindowStackEndp = ps.winStackBus
181 svc.launchers = map[string]launch_helper.HelperLauncher{}
182 svc.fallbackVibration = &launch_helper.Vibration{Pattern: []uint32{1}}
183
184=== modified file 'client/session/session_test.go'
185--- client/session/session_test.go 2014-08-26 16:05:28 +0000
186+++ client/session/session_test.go 2014-09-10 15:12:43 +0000
187@@ -1489,14 +1489,7 @@
188
189 func (cs *clientSessionSuite) TestDialBadServerName(c *C) {
190 // a borked server name
191- cert, err := tls.X509KeyPair(helpers.TestCertPEMBlock, helpers.TestKeyPEMBlock)
192- c.Assert(err, IsNil)
193- tlsCfg := &tls.Config{
194- Certificates: []tls.Certificate{cert},
195- SessionTicketsDisabled: true,
196- }
197-
198- lst, err := tls.Listen("tcp", "localhost:0", tlsCfg)
199+ lst, err := tls.Listen("tcp", "localhost:0", helpers.TestTLSServerConfig)
200 c.Assert(err, IsNil)
201 // advertise
202 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
203@@ -1541,19 +1534,12 @@
204
205 func (cs *clientSessionSuite) TestDialWorks(c *C) {
206 // happy path thoughts
207- cert, err := tls.X509KeyPair(helpers.TestCertPEMBlock, helpers.TestKeyPEMBlock)
208- c.Assert(err, IsNil)
209- tlsCfg := &tls.Config{
210- Certificates: []tls.Certificate{cert},
211- SessionTicketsDisabled: true,
212- }
213-
214- lst, err := tls.Listen("tcp", "localhost:0", tlsCfg)
215+ lst, err := tls.Listen("tcp", "localhost:0", helpers.TestTLSServerConfig)
216 c.Assert(err, IsNil)
217 // advertise
218 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
219 b, err := json.Marshal(map[string]interface{}{
220- "domain": "localhost",
221+ "domain": "push-delivery",
222 "hosts": []string{"nowhere", lst.Addr().String()},
223 })
224 if err != nil {
225@@ -1649,14 +1635,7 @@
226
227 func (cs *clientSessionSuite) TestDialWorksDirect(c *C) {
228 // happy path thoughts
229- cert, err := tls.X509KeyPair(helpers.TestCertPEMBlock, helpers.TestKeyPEMBlock)
230- c.Assert(err, IsNil)
231- tlsCfg := &tls.Config{
232- Certificates: []tls.Certificate{cert},
233- SessionTicketsDisabled: true,
234- }
235-
236- lst, err := tls.Listen("tcp", "localhost:0", tlsCfg)
237+ lst, err := tls.Listen("tcp", "localhost:0", helpers.TestTLSServerConfig)
238 c.Assert(err, IsNil)
239 sess, err := NewSession(lst.Addr().String(), dialTestConf, "wah", cs.lvls, cs.log)
240 c.Assert(err, IsNil)
241
242=== modified file 'debian/changelog'
243--- debian/changelog 2014-09-08 18:05:12 +0000
244+++ debian/changelog 2014-09-10 15:12:43 +0000
245@@ -1,3 +1,10 @@
246+ubuntu-push (0.64.1) UNRELEASED; urgency=medium
247+
248+ [ Roberto Alsina ]
249+ * Don't show popups if the screen is locked.
250+
251+ -- Roberto Alsina <ralsina@yoga> Wed, 10 Sep 2014 12:08:36 -0300
252+
253 ubuntu-push (0.64+14.10.20140908-0ubuntu1) utopic; urgency=medium
254
255 [ Roberto Alsina ]
256
257=== modified file 'docs/example-client/main.qml'
258--- docs/example-client/main.qml 2014-09-05 14:40:39 +0000
259+++ docs/example-client/main.qml 2014-09-10 15:12:43 +0000
260@@ -46,6 +46,7 @@
261 id: nickEdit
262 focus: true
263 placeholderText: "Your nickname"
264+ inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText | Qt.ImhPreferLowercase
265 anchors.left: parent.left
266 anchors.right: loginButton.left
267 anchors.top: parent.top
268@@ -85,6 +86,7 @@
269
270 TextField {
271 id: messageEdit
272+ inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText | Qt.ImhPreferLowercase
273 anchors.right: parent.right
274 anchors.left: parent.left
275 anchors.top: nickEdit.bottom
276@@ -223,6 +225,7 @@
277 text: "Enable Notifications"
278 control: Switch {
279 id: annoyingSwitch
280+ checked: true
281 }
282 }
283 ListItem.Standard {
284@@ -230,6 +233,7 @@
285 enabled: annoyingSwitch.checked
286 control: Switch {
287 id: popupSwitch
288+ checked: true
289 }
290 }
291 ListItem.Standard {
292@@ -237,6 +241,7 @@
293 enabled: annoyingSwitch.checked
294 control: Switch {
295 id: persistSwitch
296+ checked: true
297 }
298 }
299 ListItem.Standard {
300@@ -244,6 +249,7 @@
301 enabled: annoyingSwitch.checked
302 control: Switch {
303 id: soundSwitch
304+ checked: true
305 }
306 }
307 ListItem.Standard {
308@@ -251,6 +257,7 @@
309 enabled: annoyingSwitch.checked
310 control: Switch {
311 id: vibrateSwitch
312+ checked: true
313 }
314 }
315 ListItem.Standard {
316@@ -258,6 +265,7 @@
317 enabled: annoyingSwitch.checked
318 control: Slider {
319 id: counterSlider
320+ value: 42
321 }
322 }
323 }
324
325=== modified file 'docs/example-client/manifest.json'
326--- docs/example-client/manifest.json 2014-09-05 14:40:39 +0000
327+++ docs/example-client/manifest.json 2014-09-10 15:12:43 +0000
328@@ -14,6 +14,6 @@
329 },
330 "maintainer": "Roberto Alsina <roberto.alsina@canonical.com>",
331 "name": "com.ubuntu.developer.ralsina.hello",
332- "title": "ubuntu-push-example",
333- "version": "0.4"
334+ "title": "Hello",
335+ "version": "0.4.2"
336 }
337
338=== modified file 'sampleconfigs/dev.json'
339--- sampleconfigs/dev.json 2014-07-15 17:14:07 +0000
340+++ sampleconfigs/dev.json 2014-09-10 15:12:43 +0000
341@@ -10,5 +10,5 @@
342 "http_read_timeout": "5s",
343 "http_write_timeout": "5s",
344 "max_notifications_per_app": 25,
345- "delivery_domain": "localhost"
346+ "delivery_domain": "push-delivery"
347 }
348
349=== modified file 'server/acceptance/acceptance_test.go'
350--- server/acceptance/acceptance_test.go 2014-05-02 09:56:49 +0000
351+++ server/acceptance/acceptance_test.go 2014-09-10 15:12:43 +0000
352@@ -34,7 +34,7 @@
353 cfg := make(map[string]interface{})
354 suites.FillServerConfig(cfg, addr)
355 suites.FillHTTPServerConfig(cfg, httpAddr)
356- cfg["delivery_domain"] = "localhost"
357+ cfg["delivery_domain"] = "push-delivery"
358 return cfg
359 }
360
361
362=== modified file 'server/acceptance/ssl/README'
363--- server/acceptance/ssl/README 2014-02-21 16:17:28 +0000
364+++ server/acceptance/ssl/README 2014-09-10 15:12:43 +0000
365@@ -3,6 +3,6 @@
366
367 Generated with:
368
369- go run /usr/lib/go/src/pkg/crypto/tls/generate_cert.go -ca -host localhost -rsa-bits 512 -duration 87600h
370+ go run /usr/lib/go/src/pkg/crypto/tls/generate_cert.go -ca -host push-delivery -rsa-bits 512 -duration 87600h
371
372 and then renamed.
373
374=== modified file 'server/acceptance/ssl/testing.cert'
375--- server/acceptance/ssl/testing.cert 2014-01-14 15:35:20 +0000
376+++ server/acceptance/ssl/testing.cert 2014-09-10 15:12:43 +0000
377@@ -1,10 +1,10 @@
378 -----BEGIN CERTIFICATE-----
379 MIIBYzCCAQ+gAwIBAgIBADALBgkqhkiG9w0BAQUwEjEQMA4GA1UEChMHQWNtZSBD
380-bzAeFw0xMzEyMTkyMDU1NDNaFw0yMzEyMTcyMDU1NDNaMBIxEDAOBgNVBAoTB0Fj
381-bWUgQ28wWjALBgkqhkiG9w0BAQEDSwAwSAJBAPw+niki17X2qALE2A2AzE1q5dvK
382-9CI4OduRtT9IgbFLC6psqAT21NA+QbY17nWSSpyP65zkMkwKXrbDzstwLPkCAwEA
383-AaNUMFIwDgYDVR0PAQH/BAQDAgCkMBMGA1UdJQQMMAoGCCsGAQUFBwMBMA8GA1Ud
384-EwEB/wQFMAMBAf8wGgYDVR0RBBMwEYIJbG9jYWxob3N0hwR/AAABMAsGCSqGSIb3
385-DQEBBQNBAFqiVI+Km2XPSO+pxITaPvhmuzg+XG3l1+2di3gL+HlDobocjBqRctRU
386-YySO32W07acjGJmCHUKpCJuq9X8hpmk=
387+bzAeFw0xNDA4MjkxMjQyMDFaFw0yNDA4MjYxMjQyMDFaMBIxEDAOBgNVBAoTB0Fj
388+bWUgQ28wXDANBgkqhkiG9w0BAQEFAANLADBIAkEA1FT6lkow0eky+Dnj2Z4nTrTF
389+DgcKOt9Wr4B4gRH1bWmRqScOPxyHA5YodN7O1w8X8sdWko9puf59I1sWWr5LNwID
390+AQABo1IwUDAOBgNVHQ8BAf8EBAMCAKQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDwYD
391+VR0TAQH/BAUwAwEB/zAYBgNVHREEETAPgg1wdXNoLWRlbGl2ZXJ5MAsGCSqGSIb3
392+DQEBBQNBABtWCdMFkhIO8+oM3vugOWle9WJZ1FCRWD+cMl76mI1lhmNF4lvEZG47
393+xUjekA1+heU39WpOEzZSybrOdiEaGbI=
394 -----END CERTIFICATE-----
395
396=== modified file 'server/acceptance/ssl/testing.key'
397--- server/acceptance/ssl/testing.key 2014-01-14 15:35:20 +0000
398+++ server/acceptance/ssl/testing.key 2014-09-10 15:12:43 +0000
399@@ -1,9 +1,9 @@
400 -----BEGIN RSA PRIVATE KEY-----
401-MIIBPAIBAAJBAPw+niki17X2qALE2A2AzE1q5dvK9CI4OduRtT9IgbFLC6psqAT2
402-1NA+QbY17nWSSpyP65zkMkwKXrbDzstwLPkCAwEAAQJAKwXbIBULScP6QA6m8xam
403-wgWbkvN41GVWqPafPV32kPBvKwSc+M1e+JR7g3/xPZE7TCELcfYi4yXEHZZI3Pbh
404-oQIhAP/UsgJbsfH1GFv8Y8qGl5l/kmwwkwHhuKvEC87Yur9FAiEA/GlQv3ZfaXnT
405-lcCFT0aL02O0RDiRYyMUG/JAZQJs6CUCIQCHO5SZYIUwxIGK5mCNxxXOAzyQSiD7
406-hqkKywf+4FvfDQIhALa0TLyqJFom0t7c4iIGAIRc8UlIYQSPiajI64+x9775AiEA
407-0v4fgSK/Rq059zW1753JjuB6aR0Uh+3RqJII4dUR1Wg=
408+MIIBOgIBAAJBANRU+pZKMNHpMvg549meJ060xQ4HCjrfVq+AeIER9W1pkaknDj8c
409+hwOWKHTeztcPF/LHVpKPabn+fSNbFlq+SzcCAwEAAQJBAIOO+4xu/3yv/rKqO7C0
410+Oyqa+pVMa1w60R0AfqmKFQTqiTgevM77uqjpW1+t0hpK20nyj6MUIPaL+9kZgp7t
411+mnECIQDqw79PXSzudf10XGy9ve5bRazINHxQYgJ7FvlTT6JhdQIhAOeJxq9zcKni
412+69ueO1ualz0hn8w6uHPsG9FlZ8C+7Jh7AiAWJgebjjfZ+4nA+6NKt2uQct9dOA5u
413+awC+6ij1ojK4rQIgNEqAbcWDj0qpe8sLms+aEntSjJxCZiPP0IW3XeeApZsCIDwo
414+x+YyxXQWJlf9L5TNYPRo+KFEdk3Cew0lv6QNs+xe
415 -----END RSA PRIVATE KEY-----
416
417=== modified file 'server/acceptance/suites/broadcast.go'
418--- server/acceptance/suites/broadcast.go 2014-08-15 09:33:48 +0000
419+++ server/acceptance/suites/broadcast.go 2014-09-10 15:12:43 +0000
420@@ -261,7 +261,7 @@
421 host, err := gh.Get()
422 c.Assert(err, IsNil)
423 expected := &gethosts.Host{
424- Domain: "localhost",
425+ Domain: "push-delivery",
426 Hosts: []string{s.ServerAddr},
427 }
428 c.Check(host, DeepEquals, expected)
429
430=== modified file 'server/acceptance/suites/suite.go'
431--- server/acceptance/suites/suite.go 2014-08-27 21:19:51 +0000
432+++ server/acceptance/suites/suite.go 2014-09-10 15:12:43 +0000
433@@ -111,7 +111,7 @@
434 }
435
436 func testClientSession(addr string, deviceId, model, imageChannel string, reportPings bool) *acceptance.ClientSession {
437- tlsConfig, err := kit.MakeTLSConfig("", false, helpers.SourceRelative("../ssl/testing.cert"), "")
438+ tlsConfig, err := kit.MakeTLSConfig("push-delivery", false, helpers.SourceRelative("../ssl/testing.cert"), "")
439 if err != nil {
440 panic(fmt.Sprintf("could not read ssl/testing.cert: %v", err))
441 }
442
443=== modified file 'server/config_test.go'
444--- server/config_test.go 2014-02-10 23:19:08 +0000
445+++ server/config_test.go 2014-09-10 15:12:43 +0000
446@@ -26,6 +26,7 @@
447 . "launchpad.net/gocheck"
448
449 "launchpad.net/ubuntu-push/config"
450+ helpers "launchpad.net/ubuntu-push/testing"
451 )
452
453 type configSuite struct{}
454@@ -52,22 +53,22 @@
455 c.Check(cfg.Addr(), Equals, "127.0.0.1:9999")
456 }
457
458-func (s *configSuite) TestDevicesParsedConfigLoadFinish(c *C) {
459+func (s *configSuite) TestTLSParsedConfigLoadPEMs(c *C) {
460 tmpDir := c.MkDir()
461- cfg := &DevicesParsedConfig{
462+ cfg := &TLSParsedConfig{
463 ParsedKeyPEMFile: "key.key",
464 ParsedCertPEMFile: "cert.cert",
465 }
466- err := cfg.FinishLoad(tmpDir)
467+ err := cfg.LoadPEMs(tmpDir)
468 c.Check(err, ErrorMatches, "reading key_pem_file:.*no such file.*")
469- err = ioutil.WriteFile(filepath.Join(tmpDir, "key.key"), []byte("KeY"), os.ModePerm)
470+ err = ioutil.WriteFile(filepath.Join(tmpDir, "key.key"), helpers.TestKeyPEMBlock, os.ModePerm)
471 c.Assert(err, IsNil)
472- err = cfg.FinishLoad(tmpDir)
473+ err = cfg.LoadPEMs(tmpDir)
474 c.Check(err, ErrorMatches, "reading cert_pem_file:.*no such file.*")
475- err = ioutil.WriteFile(filepath.Join(tmpDir, "cert.cert"), []byte("CeRt"), os.ModePerm)
476- c.Assert(err, IsNil)
477- err = cfg.FinishLoad(tmpDir)
478- c.Assert(err, IsNil)
479- c.Check(string(cfg.KeyPEMBlock()), Equals, "KeY")
480- c.Check(string(cfg.CertPEMBlock()), Equals, "CeRt")
481+ err = ioutil.WriteFile(filepath.Join(tmpDir, "cert.cert"), helpers.TestCertPEMBlock, os.ModePerm)
482+ c.Assert(err, IsNil)
483+ err = cfg.LoadPEMs(tmpDir)
484+ c.Assert(err, IsNil)
485+ tlsCfg := cfg.TLSServerConfig()
486+ c.Check(tlsCfg.Certificates, HasLen, 1)
487 }
488
489=== modified file 'server/dev/server.go'
490--- server/dev/server.go 2014-07-08 15:08:52 +0000
491+++ server/dev/server.go 2014-09-10 15:12:43 +0000
492@@ -64,7 +64,7 @@
493 if err != nil {
494 server.BootLogFatalf("reading config: %v", err)
495 }
496- err = cfg.DevicesParsedConfig.FinishLoad(filepath.Dir(cfgFpaths[len(cfgFpaths)-1]))
497+ err = cfg.DevicesParsedConfig.LoadPEMs(filepath.Dir(cfgFpaths[len(cfgFpaths)-1]))
498 if err != nil {
499 server.BootLogFatalf("reading config: %v", err)
500 }
501@@ -95,7 +95,7 @@
502 })
503 })
504 handler := api.PanicTo500Handler(mux, logger)
505- go server.HTTPServeRunner(nil, handler, &cfg.HTTPServeParsedConfig)()
506+ go server.HTTPServeRunner(nil, handler, &cfg.HTTPServeParsedConfig, nil)()
507 // listen for device connections
508 server.DevicesRunner(lst, func(conn net.Conn) error {
509 track := session.NewTracker(logger)
510
511=== modified file 'server/listener/listener.go'
512--- server/listener/listener.go 2014-03-06 19:21:44 +0000
513+++ server/listener/listener.go 2014-09-10 15:12:43 +0000
514@@ -30,10 +30,8 @@
515 type DeviceListenerConfig interface {
516 // Addr to listen on.
517 Addr() string
518- // TLS key
519- KeyPEMBlock() []byte
520- // TLS cert
521- CertPEMBlock() []byte
522+ // TLS config
523+ TLSServerConfig() *tls.Config
524 }
525
526 // DeviceListener listens and setup sessions from device connections.
527@@ -52,15 +50,8 @@
528 return nil, err
529 }
530 }
531- cert, err := tls.X509KeyPair(cfg.CertPEMBlock(), cfg.KeyPEMBlock())
532- if err != nil {
533- return nil, err
534- }
535- tlsCfg := &tls.Config{
536- Certificates: []tls.Certificate{cert},
537- SessionTicketsDisabled: true,
538- }
539- return &DeviceListener{tls.NewListener(lst, tlsCfg)}, err
540+ tlsCfg := cfg.TLSServerConfig()
541+ return &DeviceListener{tls.NewListener(lst, tlsCfg)}, nil
542 }
543
544 // handleTemporary checks and handles if the error is just a temporary network
545
546=== modified file 'server/listener/listener_test.go'
547--- server/listener/listener_test.go 2014-08-04 14:47:00 +0000
548+++ server/listener/listener_test.go 2014-09-10 15:12:43 +0000
549@@ -18,7 +18,6 @@
550
551 import (
552 "crypto/tls"
553- "crypto/x509"
554 "net"
555 "os/exec"
556 "regexp"
557@@ -68,12 +67,8 @@
558 return cfg.addr
559 }
560
561-func (cfg *testDevListenerCfg) KeyPEMBlock() []byte {
562- return helpers.TestKeyPEMBlock
563-}
564-
565-func (cfg *testDevListenerCfg) CertPEMBlock() []byte {
566- return helpers.TestCertPEMBlock
567+func (cfg *testDevListenerCfg) TLSServerConfig() *tls.Config {
568+ return helpers.TestTLSServerConfig
569 }
570
571 func (s *listenerSuite) TestDeviceListen(c *C) {
572@@ -130,11 +125,8 @@
573 return err
574 }
575
576-func testTlsDial(c *C, addr string) (net.Conn, error) {
577- cp := x509.NewCertPool()
578- ok := cp.AppendCertsFromPEM((&testDevListenerCfg{}).CertPEMBlock())
579- c.Assert(ok, Equals, true)
580- return tls.Dial("tcp", addr, &tls.Config{RootCAs: cp})
581+func testTlsDial(addr string) (net.Conn, error) {
582+ return tls.Dial("tcp", addr, helpers.TestTLSClientConfig)
583 }
584
585 func testWriteByte(c *C, conn net.Conn, toWrite uint32) {
586@@ -159,11 +151,11 @@
587 errCh <- lst.AcceptLoop(testSession, s.testlog)
588 }()
589 listenerAddr := lst.Addr().String()
590- conn1, err := testTlsDial(c, listenerAddr)
591+ conn1, err := testTlsDial(listenerAddr)
592 c.Assert(err, IsNil)
593 defer conn1.Close()
594 testWriteByte(c, conn1, '1')
595- conn2, err := testTlsDial(c, listenerAddr)
596+ conn2, err := testTlsDial(listenerAddr)
597 c.Assert(err, IsNil)
598 defer conn2.Close()
599 testWriteByte(c, conn2, '2')
600@@ -203,7 +195,7 @@
601 res, err := cmd.Output()
602 c.Assert(err, IsNil)
603 c.Assert(string(res), Matches, "(?s).*timed out.*")
604- conn2, err := testTlsDial(c, listenerAddr)
605+ conn2, err := testTlsDial(listenerAddr)
606 c.Assert(err, IsNil)
607 defer conn2.Close()
608 testWriteByte(c, conn2, '2')
609@@ -225,7 +217,7 @@
610 }, s.testlog)
611 }()
612 listenerAddr := lst.Addr().String()
613- _, err = testTlsDial(c, listenerAddr)
614+ _, err = testTlsDial(listenerAddr)
615 c.Assert(err, Not(IsNil))
616 lst.Close()
617 c.Check(<-errCh, ErrorMatches, ".*use of closed.*")
618@@ -244,7 +236,7 @@
619 }()
620 listenerAddr := lst.Addr().String()
621 c.Check(listenerAddr, Equals, foreignLst.Addr().String())
622- conn1, err := testTlsDial(c, listenerAddr)
623+ conn1, err := testTlsDial(listenerAddr)
624 c.Assert(err, IsNil)
625 defer conn1.Close()
626 testWriteByte(c, conn1, '1')
627
628=== modified file 'server/runner_devices.go'
629--- server/runner_devices.go 2014-03-12 12:34:18 +0000
630+++ server/runner_devices.go 2014-09-10 15:12:43 +0000
631@@ -17,7 +17,6 @@
632 package server
633
634 import (
635- "fmt"
636 "net"
637 "syscall"
638 "time"
639@@ -36,26 +35,8 @@
640 ParsedSessionQueueSize config.ConfigQueueSize `json:"session_queue_size"`
641 ParsedBrokerQueueSize config.ConfigQueueSize `json:"broker_queue_size"`
642 // device listener configuration
643- ParsedAddr config.ConfigHostPort `json:"addr"`
644- ParsedKeyPEMFile string `json:"key_pem_file"`
645- ParsedCertPEMFile string `json:"cert_pem_file"`
646- // private post-processed config
647- certPEMBlock []byte
648- keyPEMBlock []byte
649-}
650-
651-func (cfg *DevicesParsedConfig) FinishLoad(baseDir string) error {
652- keyPEMBlock, err := config.LoadFile(cfg.ParsedKeyPEMFile, baseDir)
653- if err != nil {
654- return fmt.Errorf("reading key_pem_file: %v", err)
655- }
656- certPEMBlock, err := config.LoadFile(cfg.ParsedCertPEMFile, baseDir)
657- if err != nil {
658- return fmt.Errorf("reading cert_pem_file: %v", err)
659- }
660- cfg.keyPEMBlock = keyPEMBlock
661- cfg.certPEMBlock = certPEMBlock
662- return nil
663+ ParsedAddr config.ConfigHostPort `json:"addr"`
664+ TLSParsedConfig
665 }
666
667 func (cfg *DevicesParsedConfig) PingInterval() time.Duration {
668@@ -78,14 +59,6 @@
669 return cfg.ParsedAddr.HostPort()
670 }
671
672-func (cfg *DevicesParsedConfig) KeyPEMBlock() []byte {
673- return cfg.keyPEMBlock
674-}
675-
676-func (cfg *DevicesParsedConfig) CertPEMBlock() []byte {
677- return cfg.certPEMBlock
678-}
679-
680 // DevicesRunner returns a function to accept device connections.
681 // If adoptLst is not nil it will be used as the underlying listener, instead
682 // of creating one, wrapped in a TLS layer.
683
684=== modified file 'server/runner_http.go'
685--- server/runner_http.go 2014-03-25 19:02:18 +0000
686+++ server/runner_http.go 2014-09-10 15:12:43 +0000
687@@ -17,6 +17,7 @@
688 package server
689
690 import (
691+ "crypto/tls"
692 "net"
693 "net/http"
694
695@@ -32,7 +33,8 @@
696
697 // HTTPServeRunner returns a function to serve HTTP requests.
698 // If httpLst is not nil it will be used as the underlying listener.
699-func HTTPServeRunner(httpLst net.Listener, h http.Handler, parsedCfg *HTTPServeParsedConfig) func() {
700+// If tlsCfg is not nit server over TLS with the config.
701+func HTTPServeRunner(httpLst net.Listener, h http.Handler, parsedCfg *HTTPServeParsedConfig, tlsCfg *tls.Config) func() {
702 if httpLst == nil {
703 var err error
704 httpLst, err = net.Listen("tcp", parsedCfg.ParsedHTTPAddr.HostPort())
705@@ -46,6 +48,9 @@
706 ReadTimeout: parsedCfg.ParsedHTTPReadTimeout.TimeDuration(),
707 WriteTimeout: parsedCfg.ParsedHTTPWriteTimeout.TimeDuration(),
708 }
709+ if tlsCfg != nil {
710+ httpLst = tls.NewListener(httpLst, tlsCfg)
711+ }
712 return func() {
713 err := srv.Serve(httpLst)
714 if err != nil {
715
716=== modified file 'server/runner_test.go'
717--- server/runner_test.go 2014-03-25 19:02:18 +0000
718+++ server/runner_test.go 2014-09-10 15:12:43 +0000
719@@ -17,6 +17,7 @@
720 package server
721
722 import (
723+ "crypto/tls"
724 "fmt"
725 "io/ioutil"
726 "net"
727@@ -68,7 +69,7 @@
728 func (s *runnerSuite) TestHTTPServeRunner(c *C) {
729 errCh := make(chan interface{}, 1)
730 h := http.HandlerFunc(testHandle)
731- runner := HTTPServeRunner(nil, h, &testHTTPServeParsedConfig)
732+ runner := HTTPServeRunner(nil, h, &testHTTPServeParsedConfig, nil)
733 c.Assert(s.lst, Not(IsNil))
734 defer s.lst.Close()
735 c.Check(s.kind, Equals, "http")
736@@ -89,16 +90,25 @@
737 c.Check(<-errCh, Matches, "accepting http connections:.*closed.*")
738 }
739
740+func cert() tls.Certificate {
741+ cert, err := tls.X509KeyPair(helpers.TestCertPEMBlock, helpers.TestKeyPEMBlock)
742+ if err != nil {
743+ panic(err)
744+ }
745+ return cert
746+}
747+
748 var testDevicesParsedConfig = DevicesParsedConfig{
749 ParsedPingInterval: config.ConfigTimeDuration{60 * time.Second},
750 ParsedExchangeTimeout: config.ConfigTimeDuration{10 * time.Second},
751 ParsedBrokerQueueSize: config.ConfigQueueSize(1000),
752 ParsedSessionQueueSize: config.ConfigQueueSize(10),
753 ParsedAddr: "127.0.0.1:0",
754- ParsedKeyPEMFile: "",
755- ParsedCertPEMFile: "",
756- keyPEMBlock: helpers.TestKeyPEMBlock,
757- certPEMBlock: helpers.TestCertPEMBlock,
758+ TLSParsedConfig: TLSParsedConfig{
759+ ParsedKeyPEMFile: "",
760+ ParsedCertPEMFile: "",
761+ cert: cert(),
762+ },
763 }
764
765 func (s *runnerSuite) TestDevicesRunner(c *C) {
766@@ -135,7 +145,36 @@
767 lst0, err := net.Listen("tcp", "127.0.0.1:0")
768 c.Assert(err, IsNil)
769 defer lst0.Close()
770- HTTPServeRunner(lst0, nil, &testHTTPServeParsedConfig)
771+ HTTPServeRunner(lst0, nil, &testHTTPServeParsedConfig, nil)
772 c.Assert(s.lst, Equals, lst0)
773 c.Check(s.kind, Equals, "http")
774 }
775+
776+func (s *runnerSuite) TestHTTPServeRunnerTLS(c *C) {
777+ errCh := make(chan interface{}, 1)
778+ h := http.HandlerFunc(testHandle)
779+ runner := HTTPServeRunner(nil, h, &testHTTPServeParsedConfig, helpers.TestTLSServerConfig)
780+ c.Assert(s.lst, Not(IsNil))
781+ defer s.lst.Close()
782+ c.Check(s.kind, Equals, "http")
783+ go func() {
784+ defer func() {
785+ errCh <- recover()
786+ }()
787+ runner()
788+ }()
789+ cli := http.Client{
790+ Transport: &http.Transport{
791+ TLSClientConfig: helpers.TestTLSClientConfig,
792+ },
793+ }
794+ resp, err := cli.Get(fmt.Sprintf("https://%s/", s.lst.Addr()))
795+ c.Assert(err, IsNil)
796+ defer resp.Body.Close()
797+ c.Assert(resp.StatusCode, Equals, 200)
798+ body, err := ioutil.ReadAll(resp.Body)
799+ c.Assert(err, IsNil)
800+ c.Check(string(body), Equals, "yay!\n")
801+ s.lst.Close()
802+ c.Check(<-errCh, Matches, "accepting http connections:.*closed.*")
803+}
804
805=== added file 'server/tlsconfig.go'
806--- server/tlsconfig.go 1970-01-01 00:00:00 +0000
807+++ server/tlsconfig.go 2014-09-10 15:12:43 +0000
808@@ -0,0 +1,53 @@
809+/*
810+ Copyright 2013-2014 Canonical Ltd.
811+
812+ This program is free software: you can redistribute it and/or modify it
813+ under the terms of the GNU General Public License version 3, as published
814+ by the Free Software Foundation.
815+
816+ This program is distributed in the hope that it will be useful, but
817+ WITHOUT ANY WARRANTY; without even the implied warranties of
818+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
819+ PURPOSE. See the GNU General Public License for more details.
820+
821+ You should have received a copy of the GNU General Public License along
822+ with this program. If not, see <http://www.gnu.org/licenses/>.
823+*/
824+
825+package server
826+
827+import (
828+ "crypto/tls"
829+ "fmt"
830+
831+ "launchpad.net/ubuntu-push/config"
832+)
833+
834+// A TLSParsedConfig holds and can be used to parse a tls server config.
835+type TLSParsedConfig struct {
836+ ParsedKeyPEMFile string `json:"key_pem_file"`
837+ ParsedCertPEMFile string `json:"cert_pem_file"`
838+ // private post-processed config
839+ cert tls.Certificate
840+}
841+
842+func (cfg *TLSParsedConfig) LoadPEMs(baseDir string) error {
843+ keyPEMBlock, err := config.LoadFile(cfg.ParsedKeyPEMFile, baseDir)
844+ if err != nil {
845+ return fmt.Errorf("reading key_pem_file: %v", err)
846+ }
847+ certPEMBlock, err := config.LoadFile(cfg.ParsedCertPEMFile, baseDir)
848+ if err != nil {
849+ return fmt.Errorf("reading cert_pem_file: %v", err)
850+ }
851+ cfg.cert, err = tls.X509KeyPair(certPEMBlock, keyPEMBlock)
852+ return err
853+}
854+
855+func (cfg *TLSParsedConfig) TLSServerConfig() *tls.Config {
856+ tlsCfg := &tls.Config{
857+ Certificates: []tls.Certificate{cfg.cert},
858+ SessionTicketsDisabled: true,
859+ }
860+ return tlsCfg
861+}
862
863=== modified file 'testing/tls.go'
864--- testing/tls.go 2014-01-21 21:36:07 +0000
865+++ testing/tls.go 2014-09-10 15:12:43 +0000
866@@ -16,26 +16,53 @@
867
868 package testing
869
870-// key&cert generated with go run /usr/lib/go/src/pkg/crypto/tls/generate_cert.go -ca -host localhost -rsa-bits 512 -duration 87600h
871+import (
872+ "crypto/tls"
873+ "crypto/x509"
874+)
875+
876+// key&cert generated with go run /usr/lib/go/src/pkg/crypto/tls/generate_cert.go -ca -host push-delivery -rsa-bits 512 -duration 87600h
877 var (
878 TestKeyPEMBlock = []byte(`-----BEGIN RSA PRIVATE KEY-----
879-MIIBPAIBAAJBAPw+niki17X2qALE2A2AzE1q5dvK9CI4OduRtT9IgbFLC6psqAT2
880-1NA+QbY17nWSSpyP65zkMkwKXrbDzstwLPkCAwEAAQJAKwXbIBULScP6QA6m8xam
881-wgWbkvN41GVWqPafPV32kPBvKwSc+M1e+JR7g3/xPZE7TCELcfYi4yXEHZZI3Pbh
882-oQIhAP/UsgJbsfH1GFv8Y8qGl5l/kmwwkwHhuKvEC87Yur9FAiEA/GlQv3ZfaXnT
883-lcCFT0aL02O0RDiRYyMUG/JAZQJs6CUCIQCHO5SZYIUwxIGK5mCNxxXOAzyQSiD7
884-hqkKywf+4FvfDQIhALa0TLyqJFom0t7c4iIGAIRc8UlIYQSPiajI64+x9775AiEA
885-0v4fgSK/Rq059zW1753JjuB6aR0Uh+3RqJII4dUR1Wg=
886+MIIBOgIBAAJBANRU+pZKMNHpMvg549meJ060xQ4HCjrfVq+AeIER9W1pkaknDj8c
887+hwOWKHTeztcPF/LHVpKPabn+fSNbFlq+SzcCAwEAAQJBAIOO+4xu/3yv/rKqO7C0
888+Oyqa+pVMa1w60R0AfqmKFQTqiTgevM77uqjpW1+t0hpK20nyj6MUIPaL+9kZgp7t
889+mnECIQDqw79PXSzudf10XGy9ve5bRazINHxQYgJ7FvlTT6JhdQIhAOeJxq9zcKni
890+69ueO1ualz0hn8w6uHPsG9FlZ8C+7Jh7AiAWJgebjjfZ+4nA+6NKt2uQct9dOA5u
891+awC+6ij1ojK4rQIgNEqAbcWDj0qpe8sLms+aEntSjJxCZiPP0IW3XeeApZsCIDwo
892+x+YyxXQWJlf9L5TNYPRo+KFEdk3Cew0lv6QNs+xe
893 -----END RSA PRIVATE KEY-----`)
894
895 TestCertPEMBlock = []byte(`-----BEGIN CERTIFICATE-----
896 MIIBYzCCAQ+gAwIBAgIBADALBgkqhkiG9w0BAQUwEjEQMA4GA1UEChMHQWNtZSBD
897-bzAeFw0xMzEyMTkyMDU1NDNaFw0yMzEyMTcyMDU1NDNaMBIxEDAOBgNVBAoTB0Fj
898-bWUgQ28wWjALBgkqhkiG9w0BAQEDSwAwSAJBAPw+niki17X2qALE2A2AzE1q5dvK
899-9CI4OduRtT9IgbFLC6psqAT21NA+QbY17nWSSpyP65zkMkwKXrbDzstwLPkCAwEA
900-AaNUMFIwDgYDVR0PAQH/BAQDAgCkMBMGA1UdJQQMMAoGCCsGAQUFBwMBMA8GA1Ud
901-EwEB/wQFMAMBAf8wGgYDVR0RBBMwEYIJbG9jYWxob3N0hwR/AAABMAsGCSqGSIb3
902-DQEBBQNBAFqiVI+Km2XPSO+pxITaPvhmuzg+XG3l1+2di3gL+HlDobocjBqRctRU
903-YySO32W07acjGJmCHUKpCJuq9X8hpmk=
904+bzAeFw0xNDA4MjkxMjQyMDFaFw0yNDA4MjYxMjQyMDFaMBIxEDAOBgNVBAoTB0Fj
905+bWUgQ28wXDANBgkqhkiG9w0BAQEFAANLADBIAkEA1FT6lkow0eky+Dnj2Z4nTrTF
906+DgcKOt9Wr4B4gRH1bWmRqScOPxyHA5YodN7O1w8X8sdWko9puf59I1sWWr5LNwID
907+AQABo1IwUDAOBgNVHQ8BAf8EBAMCAKQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDwYD
908+VR0TAQH/BAUwAwEB/zAYBgNVHREEETAPgg1wdXNoLWRlbGl2ZXJ5MAsGCSqGSIb3
909+DQEBBQNBABtWCdMFkhIO8+oM3vugOWle9WJZ1FCRWD+cMl76mI1lhmNF4lvEZG47
910+xUjekA1+heU39WpOEzZSybrOdiEaGbI=
911 -----END CERTIFICATE-----`)
912 )
913+
914+// test tls server & client config
915+var TestTLSServerConfig, TestTLSClientConfig *tls.Config
916+
917+func init() {
918+ cert, err := tls.X509KeyPair(TestCertPEMBlock, TestKeyPEMBlock)
919+ if err != nil {
920+ panic(err)
921+ }
922+ TestTLSServerConfig = &tls.Config{
923+ Certificates: []tls.Certificate{cert},
924+ }
925+ cp := x509.NewCertPool()
926+ ok := cp.AppendCertsFromPEM(TestCertPEMBlock)
927+ if !ok {
928+ panic("failed to parse test cert")
929+ }
930+ TestTLSClientConfig = &tls.Config{
931+ RootCAs: cp,
932+ ServerName: "push-delivery",
933+ }
934+}

Subscribers

People subscribed via source and target branches