Merge lp:~rsalveti/ubuntu-push/merge-automatic-branch into lp:ubuntu-push

Proposed by Ricardo Salveti
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 146
Merged at revision: 146
Proposed branch: lp:~rsalveti/ubuntu-push/merge-automatic-branch
Merge into: lp:ubuntu-push
Diff against target: 1246 lines (+572/-99)
24 files modified
LICENSE (+1/-1)
bus/connectivity/connectivity_test.go (+4/-0)
bus/endpoint.go (+43/-0)
bus/testing/testing_endpoint.go (+10/-0)
bus/testing/testing_endpoint_test.go (+19/-0)
bus/urfkill/urfkill.go (+70/-6)
bus/urfkill/urfkill_test.go (+107/-10)
click/cclick/cclick.go (+1/-1)
client/service/postal_test.go (+5/-2)
client/session/session.go (+18/-0)
client/session/session_test.go (+42/-9)
debian/changelog (+16/-0)
launch_helper/kindpool.go (+5/-0)
poller/poller.go (+15/-16)
poller/poller_test.go (+12/-6)
server/acceptance/acceptanceclient.go (+13/-7)
server/acceptance/kit/api.go (+1/-0)
server/acceptance/kit/cliloop.go (+3/-0)
server/acceptance/ssl/README (+3/-3)
server/acceptance/ssl/testing.cert (+17/-8)
server/acceptance/ssl/testing.key (+28/-9)
server/broker/broker.go (+14/-1)
server/broker/broker_test.go (+18/-0)
testing/tls.go (+107/-20)
To merge this branch: bzr merge lp:~rsalveti/ubuntu-push/merge-automatic-branch
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+257903@code.launchpad.net

Commit message

[ Samuele Pedroni ]
* switch poller to use killswitch state for WLAN instead of misleading NM property (LP: #1446584)
* don't have goroutines from a previous test overlap with the next, races gets detected otherwise
* have the TestDialWorksDirect* tests quickly timeout, go1.3 wants a ServerName set in the tls config for them to work
* fix flaky test
* support sha384/512 certs, some exercizing of that
* let send a build number with acceptanceclient
* add helper to get int out of ConnectMsg Info

Description of the change

[ Samuele Pedroni ]
* switch poller to use killswitch state for WLAN instead of misleading NM property (LP: #1446584)
* don't have goroutines from a previous test overlap with the next, races gets detected otherwise
* have the TestDialWorksDirect* tests quickly timeout, go1.3 wants a ServerName set in the tls config for them to work
* fix flaky test
* support sha384/512 certs, some exercizing of that
* let send a build number with acceptanceclient
* add helper to get int out of ConnectMsg Info

To post a comment you must log in.
Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve
147. By Ricardo Salveti

changelog: manually adding the changes for a better format

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'LICENSE'
2--- LICENSE 2014-01-14 15:35:20 +0000
3+++ LICENSE 2015-04-30 15:00:25 +0000
4@@ -1,5 +1,5 @@
5 /*
6- Copyright 2013-2014 Canonical Ltd.
7+ Copyright 2013-2015 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
12=== modified file 'bus/connectivity/connectivity_test.go'
13--- bus/connectivity/connectivity_test.go 2015-03-02 16:45:30 +0000
14+++ bus/connectivity/connectivity_test.go 2015-04-30 15:00:25 +0000
15@@ -196,6 +196,10 @@
16 return nil, nil
17 }
18
19+func (rep *racyEndpoint) WatchProperties(f func(map[string]dbus.Variant, []string), d func()) (bus.Cancellable, error) {
20+ return nil, nil
21+}
22+
23 func (*racyEndpoint) Close() {}
24 func (*racyEndpoint) Dial() error { return nil }
25 func (*racyEndpoint) String() string { return "racyEndpoint" }
26
27=== modified file 'bus/endpoint.go'
28--- bus/endpoint.go 2015-02-26 19:36:57 +0000
29+++ bus/endpoint.go 2015-04-30 15:00:25 +0000
30@@ -49,6 +49,7 @@
31 Call(member string, args []interface{}, rvs ...interface{}) error
32 GetProperty(property string) (interface{}, error)
33 SetProperty(property string, suffix string, value interface{}) error
34+ WatchProperties(f func(map[string]dbus.Variant, []string), d func()) (Cancellable, error)
35 Dial() error
36 Close()
37 String() string
38@@ -195,6 +196,48 @@
39 return err
40 }
41
42+// WatchProperties() sets up a watch for
43+// org.freedesktop.DBus.Properties PropertiesChanged signal for the
44+// path and interface provided when creating the endpoint, and then
45+// calls f() with the unpacked value. If it's unable to set up the
46+// watch it returns an error. If the watch fails once established, d()
47+// is called. Typically f() sends the values over a channel, and d()
48+// would close the channel.
49+//
50+// XXX: untested
51+func (endp *endpoint) WatchProperties(f func(map[string]dbus.Variant, []string), d func()) (Cancellable, error) {
52+ watch, err := endp.proxy.WatchSignal("org.freedesktop.DBus.Properties", "PropertiesChanged")
53+ if err != nil {
54+ endp.log.Debugf("failed to set up the watch: %s", err)
55+ return nil, err
56+ }
57+
58+ go func() {
59+ for {
60+ msg, ok := <-watch.C
61+ if !ok {
62+ break
63+ }
64+ var intfName string
65+ var changed map[string]dbus.Variant
66+ var invalidated []string
67+ if err := msg.Args(&intfName, &changed, &invalidated); err != nil {
68+ endp.log.Errorf("unexpected values from Properties watch")
69+ break
70+ }
71+ if intfName != endp.addr.Interface {
72+ // ignore
73+ continue
74+ }
75+ f(changed, invalidated)
76+ }
77+ endp.log.Debugf("got not-OK from Properties watch")
78+ d()
79+ }()
80+
81+ return watch, nil
82+}
83+
84 // Close the connection to dbus.
85 //
86 // XXX: untested
87
88=== modified file 'bus/testing/testing_endpoint.go'
89--- bus/testing/testing_endpoint.go 2015-02-26 19:36:57 +0000
90+++ bus/testing/testing_endpoint.go 2015-04-30 15:00:25 +0000
91@@ -154,6 +154,16 @@
92 }
93 }
94
95+// See Endpoint's WatchProperties.
96+func (tc *testingEndpoint) WatchProperties(f func(map[string]dbus.Variant, []string), d func()) (bus.Cancellable, error) {
97+ translate := func(vals ...interface{}) {
98+ changed := vals[0].(map[string]dbus.Variant)
99+ invalidated := vals[1].([]string)
100+ f(changed, invalidated)
101+ }
102+ return tc.WatchSignal("PropertiesChanged", translate, d)
103+}
104+
105 // See Endpoint's Call. This Call will check its condition to decide whether
106 // to return an error, or the first of its return values
107 func (tc *testingEndpoint) Call(member string, args []interface{}, rvs ...interface{}) error {
108
109=== modified file 'bus/testing/testing_endpoint_test.go'
110--- bus/testing/testing_endpoint_test.go 2015-02-26 19:36:57 +0000
111+++ bus/testing/testing_endpoint_test.go 2015-04-30 15:00:25 +0000
112@@ -20,6 +20,7 @@
113 "testing"
114 "time"
115
116+ "launchpad.net/go-dbus/v1"
117 . "launchpad.net/gocheck"
118
119 "launchpad.net/ubuntu-push/bus"
120@@ -203,6 +204,24 @@
121 c.Check(e, NotNil)
122 }
123
124+// Test that WatchProperties() with a positive condition sends the
125+// provided return values over the channel.
126+func (s *TestingEndpointSuite) TestWatchProperties(c *C) {
127+ var m, n int32 = 42, 17
128+ endp := NewMultiValuedTestingEndpoint(nil, condition.Work(true),
129+ []interface{}{map[string]dbus.Variant{"s": dbus.Variant{m}}, []string{}},
130+ []interface{}{map[string]dbus.Variant{"s": dbus.Variant{n}}, []string{}},
131+ )
132+ ch := make(chan int32)
133+ w, e := endp.WatchProperties(func(changed map[string]dbus.Variant, nvalited []string) {
134+ ch <- changed["s"].Value.(int32)
135+ }, func() { close(ch) })
136+ c.Assert(e, IsNil)
137+ defer w.Cancel()
138+ c.Check(<-ch, Equals, m)
139+ c.Check(<-ch, Equals, n)
140+}
141+
142 // Test Dial() with a non-working bus fails
143 func (s *TestingBusSuite) TestDialNoWork(c *C) {
144 endp := NewTestingEndpoint(condition.Work(false), nil)
145
146=== modified file 'bus/urfkill/urfkill.go'
147--- bus/urfkill/urfkill.go 2015-03-30 12:05:10 +0000
148+++ bus/urfkill/urfkill.go 2015-04-30 15:00:25 +0000
149@@ -19,7 +19,7 @@
150 package urfkill
151
152 import (
153- //"launchpad.net/go-dbus/v1"
154+ "launchpad.net/go-dbus/v1"
155
156 "launchpad.net/ubuntu-push/bus"
157 "launchpad.net/ubuntu-push/logger"
158@@ -32,26 +32,49 @@
159 Name: "org.freedesktop.URfkill",
160 }
161
162+// URfkill lives on a well-knwon bus.Address
163+var WLANKillswitchBusAddress bus.Address = bus.Address{
164+ Interface: "org.freedesktop.URfkill.Killswitch",
165+ Path: "/org/freedesktop/URfkill/WLAN",
166+ Name: "org.freedesktop.URfkill",
167+}
168+
169 /*****************************************************************
170 * URfkill (and its implementation)
171 */
172
173+type KillswitchState int32
174+
175+const (
176+ KillswitchStateUnblocked KillswitchState = 0
177+ KillswitchStateSoftBlocked KillswitchState = 1
178+ KillswitchStateHardBlocked KillswitchState = 2
179+)
180+
181 type URfkill interface {
182 // IsFlightMode returns flight mode state.
183 IsFlightMode() bool
184 // WatchFlightMode listens for changes to URfkill's flight
185 // mode state, and sends them out over the channel returned.
186 WatchFlightMode() (<-chan bool, bus.Cancellable, error)
187+ // GetWLANKillswitchState fetches and returns URfkill's
188+ // WLAN killswitch state.
189+ GetWLANKillswitchState() KillswitchState
190+ // WatchWLANKillswitchState listens for changes of URfkill's
191+ // WLAN killswtich state, and sends them out over the channel returned.
192+ WatchWLANKillswitchState() (<-chan KillswitchState, bus.Cancellable, error)
193 }
194
195 type uRfkill struct {
196- bus bus.Endpoint
197- log logger.Logger
198+ bus bus.Endpoint
199+ wlanKillswitch bus.Endpoint
200+ log logger.Logger
201 }
202
203-// New returns a new URfkill that'll use the provided bus.Endpoint
204-func New(endp bus.Endpoint, log logger.Logger) URfkill {
205- return &uRfkill{endp, log}
206+// New returns a new URfkill that'll use the provided bus.Endpoints
207+// for BusAddress and WLANKillswitchBusAddress
208+func New(endp bus.Endpoint, wlanKillswitch bus.Endpoint, log logger.Logger) URfkill {
209+ return &uRfkill{endp, wlanKillswitch, log}
210 }
211
212 // ensure uRfkill implements URfkill
213@@ -92,3 +115,44 @@
214
215 return ch, w, nil
216 }
217+
218+func (ur *uRfkill) GetWLANKillswitchState() KillswitchState {
219+ got, err := ur.wlanKillswitch.GetProperty("state")
220+ if err != nil {
221+ ur.log.Errorf("failed getting WLANKillswitchState: %s", err)
222+ ur.log.Debugf("defaulting WLANKillswitchState to true")
223+ return KillswitchStateUnblocked
224+ }
225+
226+ v, ok := got.(int32)
227+ if !ok {
228+ ur.log.Errorf("got weird WLANKillswitchState: %#v", got)
229+ return KillswitchStateUnblocked
230+ }
231+
232+ return KillswitchState(v)
233+}
234+
235+func (ur *uRfkill) WatchWLANKillswitchState() (<-chan KillswitchState, bus.Cancellable, error) {
236+ ch := make(chan KillswitchState)
237+ w, err := ur.wlanKillswitch.WatchProperties(
238+ func(changed map[string]dbus.Variant, invalidated []string) {
239+ v, ok := changed["state"]
240+ if !ok {
241+ return
242+ }
243+ st, ok := v.Value.(int32)
244+ if !ok {
245+ ur.log.Errorf("got weird WLANKillswitchState via PropertiesChanged: %#v", v)
246+ return
247+ }
248+ ur.log.Debugf("got WLANKillswitchState change: %v", st)
249+ ch <- KillswitchState(st)
250+ }, func() { close(ch) })
251+ if err != nil {
252+ ur.log.Debugf("failed to set up the watch: %s", err)
253+ return nil, nil, err
254+ }
255+
256+ return ch, w, nil
257+}
258
259=== renamed file 'bus/urfkill/urfkill.go_test.go' => 'bus/urfkill/urfkill_test.go'
260--- bus/urfkill/urfkill.go_test.go 2015-03-30 12:05:10 +0000
261+++ bus/urfkill/urfkill_test.go 2015-04-30 15:00:25 +0000
262@@ -19,7 +19,7 @@
263 import (
264 "testing"
265
266- //"launchpad.net/go-dbus/v1"
267+ "launchpad.net/go-dbus/v1"
268 . "launchpad.net/gocheck"
269
270 testingbus "launchpad.net/ubuntu-push/bus/testing"
271@@ -42,14 +42,14 @@
272 }
273
274 func (s *URSuite) TestNew(c *C) {
275- ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true)), s.log)
276+ ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true)), nil, s.log)
277 c.Check(ur, NotNil)
278 }
279
280 // IsFlightMode returns the right state when everything works
281 func (s *URSuite) TestIsFlightMode(c *C) {
282 endp := testingbus.NewTestingEndpoint(nil, condition.Work(true), true)
283- ur := New(endp, s.log)
284+ ur := New(endp, nil, s.log)
285 state := ur.IsFlightMode()
286 c.Check(state, Equals, true)
287 callArgs := testingbus.GetCallArgs(endp)
288@@ -60,7 +60,7 @@
289
290 // IsFlightMode returns the right state when dbus fails
291 func (s *URSuite) TestIsFlightModeFail(c *C) {
292- ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
293+ ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), nil, s.log)
294 state := ur.IsFlightMode()
295 c.Check(state, Equals, false)
296 }
297@@ -68,14 +68,14 @@
298 // IsFlightMode returns the right state when dbus works but delivers
299 // rubbish values
300 func (s *URSuite) TestIsFlightModeRubbishValues(c *C) {
301- ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), s.log)
302+ ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), nil, s.log)
303 state := ur.IsFlightMode()
304 c.Check(state, Equals, false)
305 }
306
307 // IsFlightMode returns the right state when dbus works but delivers a rubbish structure
308 func (s *URSuite) TestIsFlightModeRubbishStructure(c *C) {
309- ur := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), s.log)
310+ ur := New(testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), nil, s.log)
311 state := ur.IsFlightMode()
312 c.Check(state, Equals, false)
313 }
314@@ -83,7 +83,7 @@
315 // WatchFightMode sends a stream of states over the channel
316 func (s *URSuite) TestWatchFlightMode(c *C) {
317 tc := testingbus.NewTestingEndpoint(nil, condition.Work(true), false, true, false)
318- ur := New(tc, s.log)
319+ ur := New(tc, nil, s.log)
320 ch, w, err := ur.WatchFlightMode()
321 c.Assert(err, IsNil)
322 defer w.Cancel()
323@@ -93,7 +93,7 @@
324
325 // WatchFlightMode returns on error if the dbus call fails
326 func (s *URSuite) TestWatchFlightModeFails(c *C) {
327- ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
328+ ur := New(testingbus.NewTestingEndpoint(nil, condition.Work(false)), nil, s.log)
329 _, _, err := ur.WatchFlightMode()
330 c.Check(err, NotNil)
331 }
332@@ -101,7 +101,7 @@
333 // WatchFlightMode calls close on its channel when the watch bails
334 func (s *URSuite) TestWatchFlightModeClosesOnWatchBail(c *C) {
335 tc := testingbus.NewTestingEndpoint(nil, condition.Work(true))
336- ur := New(tc, s.log)
337+ ur := New(tc, nil, s.log)
338 ch, w, err := ur.WatchFlightMode()
339 c.Assert(err, IsNil)
340 defer w.Cancel()
341@@ -112,10 +112,107 @@
342 // WatchFlightMode survives rubbish values
343 func (s *URSuite) TestWatchFlightModeSurvivesRubbishValues(c *C) {
344 tc := testingbus.NewTestingEndpoint(nil, condition.Work(true), "gorp")
345- ur := New(tc, s.log)
346+ ur := New(tc, nil, s.log)
347 ch, w, err := ur.WatchFlightMode()
348 c.Assert(err, IsNil)
349 defer w.Cancel()
350 _, ok := <-ch
351 c.Check(ok, Equals, false)
352 }
353+
354+// GetWLANKillState returns the right state when everything works
355+func (s *URSuite) TestGetWLANKillState(c *C) {
356+ ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(true), KillswitchStateSoftBlocked), s.log)
357+ st := ur.GetWLANKillswitchState()
358+ c.Check(st, Equals, KillswitchStateSoftBlocked)
359+}
360+
361+// GetWLANKillswitchState returns the right state when dbus fails
362+func (s *URSuite) TestGetWLANKillswitchStateFail(c *C) {
363+ ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
364+ st := ur.GetWLANKillswitchState()
365+ c.Check(st, Equals, KillswitchStateUnblocked)
366+}
367+
368+// GetWLANKillswitchState returns the right state when dbus works but delivers rubbish values
369+func (s *URSuite) TestGetWLANKillswitchStateRubbishValues(c *C) {
370+ ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(true), "broken"), s.log)
371+ st := ur.GetWLANKillswitchState()
372+ c.Check(st, Equals, KillswitchStateUnblocked)
373+}
374+
375+// GetWLANKillswitchState returns the right state when dbus works but delivers a rubbish structure
376+func (s *URSuite) TestGetWLANKillswitchStateRubbishStructure(c *C) {
377+ ur := New(nil, testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true), []interface{}{}), s.log)
378+ st := ur.GetWLANKillswitchState()
379+ c.Check(st, Equals, KillswitchStateUnblocked)
380+}
381+
382+func mkWLANKillswitchStateMap(st KillswitchState) map[string]dbus.Variant {
383+ m := make(map[string]dbus.Variant)
384+ m["state"] = dbus.Variant{int32(st)}
385+ return m
386+}
387+
388+// WatchWLANKillswitchState sends a stream of WLAN killswitch states over the channel
389+func (s *URSuite) TestWatchWLANKillswitchState(c *C) {
390+ tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
391+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
392+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateHardBlocked), []string{}},
393+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
394+ )
395+ ur := New(nil, tc, s.log)
396+ ch, w, err := ur.WatchWLANKillswitchState()
397+ c.Assert(err, IsNil)
398+ defer w.Cancel()
399+ l := []KillswitchState{<-ch, <-ch, <-ch}
400+ c.Check(l, DeepEquals, []KillswitchState{KillswitchStateUnblocked, KillswitchStateHardBlocked, KillswitchStateUnblocked})
401+}
402+
403+// WatchWLANKillswitchState returns on error if the dbus call fails
404+func (s *URSuite) TestWatchWLANKillswitchStateFails(c *C) {
405+ ur := New(nil, testingbus.NewTestingEndpoint(nil, condition.Work(false)), s.log)
406+ _, _, err := ur.WatchWLANKillswitchState()
407+ c.Check(err, NotNil)
408+}
409+
410+// WatchWLANKillswitchState calls close on its channel when the watch bails
411+func (s *URSuite) TestWatchWLANKillswitchStateClosesOnWatchBail(c *C) {
412+ tc := testingbus.NewTestingEndpoint(nil, condition.Work(true))
413+ ur := New(nil, tc, s.log)
414+ ch, w, err := ur.WatchWLANKillswitchState()
415+ c.Assert(err, IsNil)
416+ defer w.Cancel()
417+ _, ok := <-ch
418+ c.Check(ok, Equals, false)
419+}
420+
421+// WatchWLANKillswitchState ignores non-WLAN-killswitch PropertiesChanged
422+func (s *URSuite) TestWatchWLANKillswitchStateIgnoresIrrelevant(c *C) {
423+ tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
424+ []interface{}{map[string]dbus.Variant{"foo": dbus.Variant{}}, []string{}},
425+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateUnblocked), []string{}},
426+ )
427+ ur := New(nil, tc, s.log)
428+ ch, w, err := ur.WatchWLANKillswitchState()
429+ c.Assert(err, IsNil)
430+ defer w.Cancel()
431+ v, ok := <-ch
432+ c.Check(ok, Equals, true)
433+ c.Check(v, Equals, KillswitchStateUnblocked)
434+}
435+
436+// WatchWLANKillswitchState ignores rubbish WLAN killswitch state
437+func (s *URSuite) TestWatchWLANKillswitchStateIgnoresRubbishValues(c *C) {
438+ tc := testingbus.NewMultiValuedTestingEndpoint(nil, condition.Work(true),
439+ []interface{}{map[string]dbus.Variant{"state": dbus.Variant{-12}}, []string{}},
440+ []interface{}{mkWLANKillswitchStateMap(KillswitchStateSoftBlocked), []string{}},
441+ )
442+ ur := New(nil, tc, s.log)
443+ ch, w, err := ur.WatchWLANKillswitchState()
444+ c.Assert(err, IsNil)
445+ defer w.Cancel()
446+ v, ok := <-ch
447+ c.Check(ok, Equals, true)
448+ c.Check(v, Equals, KillswitchStateSoftBlocked)
449+}
450
451=== modified file 'click/cclick/cclick.go'
452--- click/cclick/cclick.go 2015-02-06 17:01:15 +0000
453+++ click/cclick/cclick.go 2015-04-30 15:00:25 +0000
454@@ -51,7 +51,7 @@
455 }
456 ccu.cref = cref
457 runtime.SetFinalizer(holder, func(interface{}) {
458- ccu.cref = nil // 1.3 gc gets confused otherwise
459+ ccu.cref = nil // blocks gc really for now, 1.3 otherwise panics
460 C.g_object_unref((C.gpointer)(cref))
461 })
462 return nil
463
464=== modified file 'client/service/postal_test.go'
465--- client/service/postal_test.go 2015-03-05 14:09:54 +0000
466+++ client/service/postal_test.go 2015-04-30 15:00:25 +0000
467@@ -592,14 +592,17 @@
468
469 func (ps *postalSuite) TestMessageHandlerReportsFailedNotifies(c *C) {
470 endp := testibus.NewTestingEndpoint(condition.Work(true), condition.Work(true), 1)
471+ nopTicker := make(chan []interface{})
472+ testibus.SetWatchSource(endp, "ActionInvoked", nopTicker)
473+ defer close(nopTicker)
474 svc := ps.replaceBuses(NewPostalService(ps.cfg, ps.log))
475 svc.NotificationsEndp = endp
476 c.Assert(svc.Start(), IsNil)
477 card := &launch_helper.Card{Icon: "icon-value", Summary: "summary-value", Body: "body-value", Popup: true}
478 notif := &launch_helper.Notification{Card: card}
479 output := &launch_helper.HelperOutput{Notification: notif}
480- err := svc.messageHandler(&click.AppId{}, "", output)
481- c.Assert(err, NotNil)
482+ b := svc.messageHandler(&click.AppId{}, "", output)
483+ c.Check(b, Equals, false)
484 }
485
486 func (ps *postalSuite) TestMessageHandlerInhibition(c *C) {
487
488=== modified file 'client/session/session.go'
489--- client/session/session.go 2015-03-24 17:32:13 +0000
490+++ client/session/session.go 2015-04-30 15:00:25 +0000
491@@ -19,9 +19,11 @@
492 package session
493
494 import (
495+ _ "crypto/sha512" // support sha384/512 certs
496 "crypto/tls"
497 "crypto/x509"
498 "encoding/json"
499+ "encoding/pem"
500 "errors"
501 "fmt"
502 "math/rand"
503@@ -246,6 +248,22 @@
504 return nil, errors.New("could not parse certificate")
505 }
506 sess.TLS.RootCAs = cp
507+ block, _ := pem.Decode(sess.PEM)
508+ if block == nil {
509+ panic(fmt.Errorf("unexpected error reparsing certificate"))
510+ }
511+ cert, err := x509.ParseCertificate(block.Bytes)
512+ if err != nil {
513+ panic(fmt.Errorf("unexpected error reparsing certificate: %v", err))
514+ }
515+ // good guess
516+ var serverName string
517+ if len(cert.DNSNames) > 0 {
518+ serverName = cert.DNSNames[0]
519+ } else {
520+ serverName = cert.Subject.CommonName
521+ }
522+ sess.TLS.ServerName = serverName
523 }
524 sess.doneCh = make(chan uint32, 1)
525 sess.stopCh = make(chan struct{})
526
527=== modified file 'client/session/session_test.go'
528--- client/session/session_test.go 2015-03-24 15:28:24 +0000
529+++ client/session/session_test.go 2015-04-30 15:00:25 +0000
530@@ -259,10 +259,9 @@
531 c.Check(sess.getHost, NotNil)
532 }
533
534-var certfile string = helpers.SourceRelative("../../server/acceptance/ssl/testing.cert")
535-var pem, _ = ioutil.ReadFile(certfile)
536-
537 func (cs *clientSessionSuite) TestNewSessionPEMWorks(c *C) {
538+ pem, err := ioutil.ReadFile(helpers.SourceRelative("../../server/acceptance/ssl/testing.cert"))
539+ c.Assert(err, IsNil)
540 conf := ClientSessionConfig{PEM: pem}
541 sess, err := NewSession("", conf, "wah", cs.lvls, cs.log)
542 c.Check(sess, NotNil)
543@@ -1474,10 +1473,14 @@
544 dialTestTimeout = 300 * time.Millisecond
545 )
546
547-func dialTestConf() ClientSessionConfig {
548+func dialTestConf(certPEM []byte) ClientSessionConfig {
549 conf := dummyConf()
550 conf.ExchangeTimeout = dialTestTimeout
551- conf.PEM = helpers.TestCertPEMBlock
552+ if certPEM == nil {
553+ conf.PEM = helpers.TestCertPEMBlock
554+ } else {
555+ conf.PEM = certPEM
556+ }
557 return conf
558 }
559
560@@ -1499,7 +1502,7 @@
561 }))
562 defer ts.Close()
563
564- sess, err := NewSession(ts.URL, dialTestConf(), "wah", cs.lvls, cs.log)
565+ sess, err := NewSession(ts.URL, dialTestConf(nil), "wah", cs.lvls, cs.log)
566 c.Assert(err, IsNil)
567 tconn := &testConn{}
568 sess.Connection = tconn
569@@ -1544,7 +1547,7 @@
570 }))
571 defer ts.Close()
572
573- sess, err := NewSession(ts.URL, dialTestConf(), "wah", cs.lvls, cs.log)
574+ sess, err := NewSession(ts.URL, dialTestConf(nil), "wah", cs.lvls, cs.log)
575 c.Assert(err, IsNil)
576 tconn := &testConn{CloseCondition: condition.Fail2Work(10)}
577 sess.Connection = tconn
578@@ -1631,7 +1634,7 @@
579 // happy path thoughts
580 lst, err := tls.Listen("tcp", "localhost:0", helpers.TestTLSServerConfig)
581 c.Assert(err, IsNil)
582- sess, err := NewSession(lst.Addr().String(), dialTestConf(), "wah", cs.lvls, cs.log)
583+ sess, err := NewSession(lst.Addr().String(), dialTestConf(nil), "wah", cs.lvls, cs.log)
584 c.Assert(err, IsNil)
585 defer sess.StopKeepConnection()
586
587@@ -1642,7 +1645,37 @@
588
589 go sess.Dial()
590
591- _, err = lst.Accept()
592+ cli, err := lst.Accept()
593+ c.Assert(err, IsNil)
594+ cli.SetReadDeadline(time.Now().Add(2 * time.Second))
595+ var buf [1]byte
596+ _, err = cli.Read(buf[:])
597+ c.Assert(err, IsNil)
598+ // connect done
599+}
600+
601+func (cs *clientSessionSuite) TestDialWorksDirectSHA512Cert(c *C) {
602+ // happy path thoughts
603+ lst, err := tls.Listen("tcp", "localhost:0", helpers.TestTLSServerConfigs["sha512"])
604+ c.Assert(err, IsNil)
605+ sess, err := NewSession(lst.Addr().String(), dialTestConf(helpers.TestCertPEMBlock512), "wah", cs.lvls, cs.log)
606+ c.Assert(err, IsNil)
607+ defer sess.StopKeepConnection()
608+
609+ upCh := make(chan interface{}, 5)
610+ downCh := make(chan interface{}, 5)
611+ proto := &testProtocol{up: upCh, down: downCh}
612+ sess.Protocolator = func(conn net.Conn) protocol.Protocol {
613+ return proto
614+ }
615+
616+ go sess.Dial()
617+
618+ cli, err := lst.Accept()
619+ c.Assert(err, IsNil)
620+ cli.SetReadDeadline(time.Now().Add(2 * time.Second))
621+ var buf [1]byte
622+ _, err = cli.Read(buf[:])
623 c.Assert(err, IsNil)
624 // connect done
625 }
626
627=== modified file 'debian/changelog'
628--- debian/changelog 2015-04-03 13:27:44 +0000
629+++ debian/changelog 2015-04-30 15:00:25 +0000
630@@ -1,3 +1,19 @@
631+ubuntu-push (0.68+15.04.20150430-0ubuntu1) UNRELEASED; urgency=medium
632+
633+ [ Samuele Pedroni ]
634+ * switch poller to use killswitch state for WLAN instead of
635+ misleading NM property (LP: #1446584)
636+ * don't have goroutines from a previous test overlap with the next,
637+ races gets detected otherwise
638+ * have the TestDialWorksDirect* tests quickly timeout, go1.3 wants a
639+ ServerName set in the tls config for them to work
640+ * fix flaky test
641+ * support sha384/512 certs, some exercizing of that
642+ * let send a build number with acceptanceclient
643+ * add helper to get int out of ConnectMsg Info
644+
645+ -- Ricardo Salveti de Araujo <ricardo.salveti@canonical.com> Thu, 30 Apr 2015 09:57:38 -0500
646+
647 ubuntu-push (0.68+15.04.20150403-0ubuntu1) vivid; urgency=medium
648
649 [ Samuele Pedroni ]
650
651=== modified file 'launch_helper/kindpool.go'
652--- launch_helper/kindpool.go 2015-01-21 17:21:42 +0000
653+++ launch_helper/kindpool.go 2015-04-30 15:00:25 +0000
654@@ -61,6 +61,7 @@
655 chOut chan *HelperResult
656 chIn chan *HelperInput
657 chDone chan *click.AppId
658+ chStopped chan struct{}
659 launchers map[string]HelperLauncher
660 lock sync.Mutex
661 hmap map[string]*HelperArgs
662@@ -91,6 +92,7 @@
663 pool.chOut = make(chan *HelperResult)
664 pool.chIn = make(chan *HelperInput, InputBufferSize)
665 pool.chDone = make(chan *click.AppId)
666+ pool.chStopped = make(chan struct{})
667
668 for kind, launcher := range pool.launchers {
669 kind1 := kind
670@@ -115,6 +117,7 @@
671 select {
672 case in, ok := <-pool.chIn:
673 if !ok {
674+ close(pool.chStopped)
675 return
676 }
677 if len(running) >= pool.maxNum || running[in.App.Original()] {
678@@ -176,6 +179,8 @@
679 panic(fmt.Errorf("failed to remove helper observer for &s: %v", kind, err))
680 }
681 }
682+ // make Stop sync for tests
683+ <-pool.chStopped
684 }
685
686 func (pool *kindHelperPool) Run(kind string, input *HelperInput) {
687
688=== modified file 'poller/poller.go'
689--- poller/poller.go 2015-03-30 20:48:00 +0000
690+++ poller/poller.go 2015-04-30 15:00:25 +0000
691@@ -25,7 +25,6 @@
692 "time"
693
694 "launchpad.net/ubuntu-push/bus"
695- "launchpad.net/ubuntu-push/bus/networkmanager"
696 "launchpad.net/ubuntu-push/bus/polld"
697 "launchpad.net/ubuntu-push/bus/powerd"
698 "launchpad.net/ubuntu-push/bus/urfkill"
699@@ -68,7 +67,6 @@
700 type poller struct {
701 times Times
702 log logger.Logger
703- nm networkmanager.NetworkManager
704 powerd powerd.Powerd
705 polld polld.Polld
706 urfkill urfkill.URfkill
707@@ -103,18 +101,13 @@
708 if p.powerd != nil || p.polld != nil {
709 return ErrAlreadyStarted
710 }
711- nmEndp := bus.SystemBus.Endpoint(networkmanager.BusAddress, p.log)
712 powerdEndp := bus.SystemBus.Endpoint(powerd.BusAddress, p.log)
713 polldEndp := bus.SessionBus.Endpoint(polld.BusAddress, p.log)
714 urEndp := bus.SystemBus.Endpoint(urfkill.BusAddress, p.log)
715+ urWLANKillswitchEndp := bus.SystemBus.Endpoint(urfkill.WLANKillswitchBusAddress, p.log)
716 var wg sync.WaitGroup
717 wg.Add(4)
718 go func() {
719- n := util.NewAutoRedialer(nmEndp).Redial()
720- p.log.Debugf("NetworkManager dialed on try %d", n)
721- wg.Done()
722- }()
723- go func() {
724 n := util.NewAutoRedialer(powerdEndp).Redial()
725 p.log.Debugf("powerd dialed on try %d", n)
726 wg.Done()
727@@ -129,12 +122,16 @@
728 p.log.Debugf("URfkill dialed on try %d", n)
729 wg.Done()
730 }()
731+ go func() {
732+ n := util.NewAutoRedialer(urWLANKillswitchEndp).Redial()
733+ p.log.Debugf("URfkill (WLAN killswitch) dialed on try %d", n)
734+ wg.Done()
735+ }()
736 wg.Wait()
737
738- p.nm = networkmanager.New(nmEndp, p.log)
739 p.powerd = powerd.New(powerdEndp, p.log)
740 p.polld = polld.New(polldEndp, p.log)
741- p.urfkill = urfkill.New(urEndp, p.log)
742+ p.urfkill = urfkill.New(urEndp, urWLANKillswitchEndp, p.log)
743
744 // busy sleep loop to workaround go's timer/sleep
745 // not accounting for time when the system is suspended
746@@ -157,7 +154,7 @@
747 if p.log == nil {
748 return ErrUnconfigured
749 }
750- if p.nm == nil || p.powerd == nil || p.polld == nil || p.urfkill == nil {
751+ if p.powerd == nil || p.polld == nil || p.urfkill == nil {
752 return ErrNotStarted
753 }
754 wakeupCh, err := p.powerd.WatchWakeups()
755@@ -169,18 +166,18 @@
756 return err
757 }
758 flightMode := p.urfkill.IsFlightMode()
759- wirelessEnabled := p.nm.GetWirelessEnabled()
760+ wlanKillswitchState := p.urfkill.GetWLANKillswitchState()
761 flightModeCh, _, err := p.urfkill.WatchFlightMode()
762 if err != nil {
763 return err
764 }
765- wirelessEnabledCh, _, err := p.nm.WatchWirelessEnabled()
766+ wlanKillswitchStateCh, _, err := p.urfkill.WatchWLANKillswitchState()
767 if err != nil {
768 return err
769 }
770
771 filteredWakeUpCh := make(chan bool)
772- go p.control(wakeupCh, filteredWakeUpCh, flightMode, flightModeCh, wirelessEnabled, wirelessEnabledCh)
773+ go p.control(wakeupCh, filteredWakeUpCh, flightMode, flightModeCh, wlanKillswitchState, wlanKillswitchStateCh)
774 go p.run(filteredWakeUpCh, doneCh)
775 return nil
776 }
777@@ -198,7 +195,8 @@
778 return t, cookie, err
779 }
780
781-func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, flightMode bool, flightModeCh <-chan bool, wirelessEnabled bool, wirelessEnabledCh <-chan bool) {
782+func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, flightMode bool, flightModeCh <-chan bool, wlanKillswitchState urfkill.KillswitchState, wlanKillswitchStateCh <-chan urfkill.KillswitchState) {
783+ wirelessEnabled := wlanKillswitchState == urfkill.KillswitchStateUnblocked
784 dontPoll := flightMode && !wirelessEnabled
785 var t time.Time
786 cookie := ""
787@@ -237,7 +235,8 @@
788 }
789 }
790 case flightMode = <-flightModeCh:
791- case wirelessEnabled = <-wirelessEnabledCh:
792+ case wlanKillswitchState = <-wlanKillswitchStateCh:
793+ wirelessEnabled = wlanKillswitchState == urfkill.KillswitchStateUnblocked
794 }
795 newDontPoll := flightMode && !wirelessEnabled
796 p.log.Debugf("control: flightMode:%v wirelessEnabled:%v prevDontPoll:%v dontPoll:%v wakeupReq:%v holdsWakeLock:%v", flightMode, wirelessEnabled, dontPoll, newDontPoll, !t.IsZero(), holdsWakeLock)
797
798=== modified file 'poller/poller_test.go'
799--- poller/poller_test.go 2015-03-30 15:59:19 +0000
800+++ poller/poller_test.go 2015-04-30 15:00:25 +0000
801@@ -21,6 +21,7 @@
802
803 . "launchpad.net/gocheck"
804
805+ "launchpad.net/ubuntu-push/bus/urfkill"
806 "launchpad.net/ubuntu-push/client/session"
807 helpers "launchpad.net/ubuntu-push/testing"
808 )
809@@ -90,6 +91,11 @@
810 s.myd = &myD{}
811 }
812
813+const (
814+ wlanOn = urfkill.KillswitchStateUnblocked
815+ wlanOff = urfkill.KillswitchStateSoftBlocked
816+)
817+
818 func (s *PrSuite) TestStep(c *C) {
819 p := &poller{
820 times: Times{},
821@@ -111,7 +117,7 @@
822 ch := make(chan string)
823 // now, run
824 filteredWakeUpCh := make(chan bool)
825- go p.control(wakeupCh, filteredWakeUpCh, false, nil, true, nil)
826+ go p.control(wakeupCh, filteredWakeUpCh, false, nil, wlanOn, nil)
827 go func() { ch <- p.step(filteredWakeUpCh, doneCh, "old cookie") }()
828 select {
829 case s := <-ch:
830@@ -138,8 +144,8 @@
831 filteredWakeUpCh := make(chan bool)
832 s.myd.watchWakeCh = make(chan bool, 1)
833 flightModeCh := make(chan bool)
834- wirelessModeCh := make(chan bool)
835- go p.control(wakeUpCh, filteredWakeUpCh, false, flightModeCh, true, wirelessModeCh)
836+ wlanKillswitchStateCh := make(chan urfkill.KillswitchState)
837+ go p.control(wakeUpCh, filteredWakeUpCh, false, flightModeCh, wlanOn, wlanKillswitchStateCh)
838
839 // works
840 err := p.requestWakeup()
841@@ -157,17 +163,17 @@
842
843 // flight mode
844 flightModeCh <- true
845- wirelessModeCh <- false
846+ wlanKillswitchStateCh <- wlanOff
847 err = p.requestWakeup()
848 c.Assert(err, IsNil)
849 c.Check(s.myd.watchWakeCh, HasLen, 0)
850
851 // wireless on
852- wirelessModeCh <- true
853+ wlanKillswitchStateCh <- wlanOn
854 c.Check(<-s.myd.watchWakeCh, Equals, true)
855
856 // wireless off
857- wirelessModeCh <- false
858+ wlanKillswitchStateCh <- wlanOff
859 // pending wakeup was cleared
860 c.Check(<-s.myd.watchWakeCh, Equals, false)
861
862
863=== modified file 'server/acceptance/acceptanceclient.go'
864--- server/acceptance/acceptanceclient.go 2014-12-08 16:31:10 +0000
865+++ server/acceptance/acceptanceclient.go 2015-04-30 15:00:25 +0000
866@@ -18,6 +18,7 @@
867 package acceptance
868
869 import (
870+ _ "crypto/sha512" // support sha384/512 certs
871 "crypto/tls"
872 "encoding/json"
873 "fmt"
874@@ -37,6 +38,7 @@
875 DeviceId string
876 Model string
877 ImageChannel string
878+ BuildNumber int32
879 ServerAddr string
880 ExchangeTimeout time.Duration
881 ReportPings bool
882@@ -106,14 +108,18 @@
883 return err
884 }
885 proto := protocol.NewProtocol0(conn)
886+ info := map[string]interface{}{
887+ "device": sess.Model,
888+ "channel": sess.ImageChannel,
889+ }
890+ if sess.BuildNumber != -1 {
891+ info["build_number"] = sess.BuildNumber
892+ }
893 err = proto.WriteMessage(protocol.ConnectMsg{
894- Type: "connect",
895- DeviceId: sess.DeviceId,
896- Levels: sess.Levels,
897- Info: map[string]interface{}{
898- "device": sess.Model,
899- "channel": sess.ImageChannel,
900- },
901+ Type: "connect",
902+ DeviceId: sess.DeviceId,
903+ Levels: sess.Levels,
904+ Info: info,
905 Authorization: sess.Auth,
906 Cookie: sess.GetCookie(),
907 })
908
909=== modified file 'server/acceptance/kit/api.go'
910--- server/acceptance/kit/api.go 2015-01-28 21:41:34 +0000
911+++ server/acceptance/kit/api.go 2015-04-30 15:00:25 +0000
912@@ -19,6 +19,7 @@
913
914 import (
915 "bytes"
916+ _ "crypto/sha512" // support sha384/512 certs
917 "crypto/tls"
918 "encoding/json"
919 "errors"
920
921=== modified file 'server/acceptance/kit/cliloop.go'
922--- server/acceptance/kit/cliloop.go 2014-08-20 19:48:59 +0000
923+++ server/acceptance/kit/cliloop.go 2015-04-30 15:00:25 +0000
924@@ -45,6 +45,7 @@
925 ReportPings bool `json:"reportPings" help:"report each Ping from the server"`
926 DeviceModel string `json:"model" help:"device image model"`
927 ImageChannel string `json:"imageChannel" help:"image channel"`
928+ BuildNumber int32 `json:"buildNumber" help:"build number"`
929 }
930
931 func (cfg *Configuration) PickByTarget(what, productionValue, stagingValue string) (value string) {
932@@ -75,6 +76,7 @@
933 "reportPings": true,
934 "model": "?",
935 "imageChannel": "?",
936+ "buildNumber": -1,
937 }
938 )
939
940@@ -112,6 +114,7 @@
941 // flags
942 Model: cfg.DeviceModel,
943 ImageChannel: cfg.ImageChannel,
944+ BuildNumber: cfg.BuildNumber,
945 ReportPings: cfg.ReportPings,
946 }
947 cfgDir := filepath.Dir(flag.Lookup("cfg@").Value.String())
948
949=== modified file 'server/acceptance/ssl/README'
950--- server/acceptance/ssl/README 2014-09-01 14:48:03 +0000
951+++ server/acceptance/ssl/README 2015-04-30 15:00:25 +0000
952@@ -3,6 +3,6 @@
953
954 Generated with:
955
956- go run /usr/lib/go/src/pkg/crypto/tls/generate_cert.go -ca -host push-delivery -rsa-bits 512 -duration 87600h
957-
958-and then renamed.
959+ openssl req -x509 -nodes -newkey rsa:2048 -multivalue-rdn -sha384 -days 3650 -keyout testing.key -out testing.cert -subj "/O=Acme Co/CN=push-delivery/"
960+
961+
962
963=== modified file 'server/acceptance/ssl/testing.cert'
964--- server/acceptance/ssl/testing.cert 2014-09-01 14:48:03 +0000
965+++ server/acceptance/ssl/testing.cert 2015-04-30 15:00:25 +0000
966@@ -1,10 +1,19 @@
967 -----BEGIN CERTIFICATE-----
968-MIIBYzCCAQ+gAwIBAgIBADALBgkqhkiG9w0BAQUwEjEQMA4GA1UEChMHQWNtZSBD
969-bzAeFw0xNDA4MjkxMjQyMDFaFw0yNDA4MjYxMjQyMDFaMBIxEDAOBgNVBAoTB0Fj
970-bWUgQ28wXDANBgkqhkiG9w0BAQEFAANLADBIAkEA1FT6lkow0eky+Dnj2Z4nTrTF
971-DgcKOt9Wr4B4gRH1bWmRqScOPxyHA5YodN7O1w8X8sdWko9puf59I1sWWr5LNwID
972-AQABo1IwUDAOBgNVHQ8BAf8EBAMCAKQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDwYD
973-VR0TAQH/BAUwAwEB/zAYBgNVHREEETAPgg1wdXNoLWRlbGl2ZXJ5MAsGCSqGSIb3
974-DQEBBQNBABtWCdMFkhIO8+oM3vugOWle9WJZ1FCRWD+cMl76mI1lhmNF4lvEZG47
975-xUjekA1+heU39WpOEzZSybrOdiEaGbI=
976+MIIDJzCCAg+gAwIBAgIJAOFQ2INogVqRMA0GCSqGSIb3DQEBDAUAMCoxEDAOBgNV
977+BAoMB0FjbWUgQ28xFjAUBgNVBAMMDXB1c2gtZGVsaXZlcnkwHhcNMTUwNDE1MTcx
978+NjMyWhcNMjUwNDEyMTcxNjMyWjAqMRAwDgYDVQQKDAdBY21lIENvMRYwFAYDVQQD
979+DA1wdXNoLWRlbGl2ZXJ5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
980+yPk8yurO/LVuzNE/BZy7katJt7V4exbr+pqUci4bLzPUNENJ+SsyZzvj0iwXtHG5
981+JUM2F3zSe5XzGE+PqVuer2pN1ujgp3sVGVj/ZzLYbQo1xojTt8wHgJippWBczaq+
982+IJ3lTQiAfjGyB1xMnpz97r/fpNLlLbpyYN9WyV60VVNExqMPQgBeXfjpZbSTcktu
983+sC0522RC4nhManzdVP6PaSw1bUWdptvxBzar+kfL4rb3PqbfAQLn7fGplvZ86k8b
984+sDeGT9Xa0oOAY9RGMxY6XdXzGmtd2DVGrynACgbalk4VWTre+7RtmFBIi+nmehWR
985+rNu3GIXUWGx9K3+FRFSk1QIDAQABo1AwTjAdBgNVHQ4EFgQUjN2dS9quo9qDce5j
986+RUpgh40OJhgwHwYDVR0jBBgwFoAUjN2dS9quo9qDce5jRUpgh40OJhgwDAYDVR0T
987+BAUwAwEB/zANBgkqhkiG9w0BAQwFAAOCAQEAkyL9bA8KmEIdCso3uznPN6B+g9be
988+kaxfWeskOHWDxq4h8sa2rcAIqP4uv60DKvE1QcJhXNJHKW35TXFB9a0bosc3eNVL
989+Z28gEcie7yk04r2+h535CRtsgZUZ20Pr6qeNfiyrZeqGY3RHqkHfIztx0AxtYNXO
990+N/dTikTVLKquHpMQs07rOgkRhr1lRVl1kAZ0fj7IdWpjvMsAo8RzfRJFom9TFFa+
991+v3X6SAKwihDESPWRPzPtH6K/d8sRsiV3av2DlA20bUzhpi2S7FUXWAmzzzXk6wO3
992+GoklmlJs5nuGebuDaQ2zKvHgNIaMJinMREdtDcVGf96HKdjgILvxjrdtyA==
993 -----END CERTIFICATE-----
994
995=== modified file 'server/acceptance/ssl/testing.key'
996--- server/acceptance/ssl/testing.key 2014-09-01 14:48:03 +0000
997+++ server/acceptance/ssl/testing.key 2015-04-30 15:00:25 +0000
998@@ -1,9 +1,28 @@
999------BEGIN RSA PRIVATE KEY-----
1000-MIIBOgIBAAJBANRU+pZKMNHpMvg549meJ060xQ4HCjrfVq+AeIER9W1pkaknDj8c
1001-hwOWKHTeztcPF/LHVpKPabn+fSNbFlq+SzcCAwEAAQJBAIOO+4xu/3yv/rKqO7C0
1002-Oyqa+pVMa1w60R0AfqmKFQTqiTgevM77uqjpW1+t0hpK20nyj6MUIPaL+9kZgp7t
1003-mnECIQDqw79PXSzudf10XGy9ve5bRazINHxQYgJ7FvlTT6JhdQIhAOeJxq9zcKni
1004-69ueO1ualz0hn8w6uHPsG9FlZ8C+7Jh7AiAWJgebjjfZ+4nA+6NKt2uQct9dOA5u
1005-awC+6ij1ojK4rQIgNEqAbcWDj0qpe8sLms+aEntSjJxCZiPP0IW3XeeApZsCIDwo
1006-x+YyxXQWJlf9L5TNYPRo+KFEdk3Cew0lv6QNs+xe
1007------END RSA PRIVATE KEY-----
1008+-----BEGIN PRIVATE KEY-----
1009+MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDI+TzK6s78tW7M
1010+0T8FnLuRq0m3tXh7Fuv6mpRyLhsvM9Q0Q0n5KzJnO+PSLBe0cbklQzYXfNJ7lfMY
1011+T4+pW56vak3W6OCnexUZWP9nMthtCjXGiNO3zAeAmKmlYFzNqr4gneVNCIB+MbIH
1012+XEyenP3uv9+k0uUtunJg31bJXrRVU0TGow9CAF5d+OlltJNyS26wLTnbZELieExq
1013+fN1U/o9pLDVtRZ2m2/EHNqv6R8vitvc+pt8BAuft8amW9nzqTxuwN4ZP1drSg4Bj
1014+1EYzFjpd1fMaa13YNUavKcAKBtqWThVZOt77tG2YUEiL6eZ6FZGs27cYhdRYbH0r
1015+f4VEVKTVAgMBAAECggEAZWViJ5qqTdOYEFwt6L334HnEGpzDKY8aBfkBlk3uxzTm
1016+BmxAoScLKgyMV9iJKTALUmKDovwGEfZIjOZvO+oOuL/wf9JErhsqPPyq9z0u9myl
1017+TwJvlxaoXlgnl1lz2QwhGsGvE9uLQKAACzilK41XjKJfyn/gwt6DoJ5t4fEXGMii
1018+Sw300qn41pb/5ZVCrELDrP1L97El6M2cjaE/bsspYUFGIPEY6NdVNovXmSW0L88X
1019+0r85WjsIq94sTyymx01QQrSz7HsihyKhYkh/BLd9rrGNPf/ztlTsXw71ebYCsowU
1020+coL46AsAkejosCawBDKEa1NCc0ojdNPXVb9eEoK7TQKBgQDm3BpbDsrLpmgTtuJQ
1021+2RzMgAqEVHHTq/GC89pPljfPLBsSRZU7BmSEXFTA4mulb81vUXmkBG+v7L2tzVSA
1022+PGaqz8qPfCgf09uN4mFDq51xaIpYrjYU5+YTsPpjYv0qwdXotDOcdkNKnx5CiZ7q
1023+A8KwJ4CrQ0EW9D9PA2DQt9XqOwKBgQDe2/gAM58HBpHYXW7K4er9RUmvLbNIils7
1024+ztZLkEGBENCCWGLwnx4R48HXO/XITlPb8oqv8EztTL0HceOoZZAerxl9QWUJpZ46
1025+Ba5uDY6lb1ntUMSRDmgX00JNooskolT0YGemCIMx2NwYMfmY+WWuqa1pK5k/z6FC
1026+fcKWph2sLwKBgEOrPKZ4PYVYL6Wns8rS+RgQaATF49+RxOcHp3Qwqgc1/HFsqAN3
1027+KjuJ/OXU+Iyzqtn4Xdlv23ULxcWOLDiye72RzuQkFnbN2MtMEgqN4UZ+yB6aYgva
1028+tZwMAjjjqSXBT3w4ZfB00eCrp2kFgelCVOzhh1usCQY7bdsxOE21tSRFAoGAFLPK
1029+bfpdo4FwuvCzAhXKhoyRM7zDEtIHd57XOV3FOAAf3nvndQLTAEZwE1Z2lozwLVZy
1030+m7Vu7/xY8wAZbeNBaBhL/d69TBAeirVMZtzLi4K0j98Y44C7Grt9RUj8NAMAcVMj
1031+TcEsrsy+ZWD/Fr7UO0131nU+Xzcie9LC6Mu1pfECgYEAh6G7eWd/TX26u9ZB0ZsS
1032+caFD+sut9nAWCTAR7KzZrumK5BiqcQwrKafQaKrl7RsEe0JlG9dEpJOnCG/CPkFj
1033+odfah1tuPYhk09QQRpSvTWlMQpyICd1ezsjDyZDQLsUSl7OxOoCmrzKieS8PdFYk
1034+OZ0Jl7ocnv+viqxetkictDM=
1035+-----END PRIVATE KEY-----
1036
1037=== modified file 'server/broker/broker.go'
1038--- server/broker/broker.go 2014-09-25 11:16:38 +0000
1039+++ server/broker/broker.go 2015-04-30 15:00:25 +0000
1040@@ -60,7 +60,7 @@
1041 // LevelsMap is the type for holding channel levels for session.
1042 type LevelsMap map[store.InternalChannelId]int64
1043
1044-// GetInfoString helps retrivieng a string out of a protocol.ConnectMsg.Info
1045+// GetInfoString helps retrieveng a string out of a protocol.ConnectMsg.Info.
1046 func GetInfoString(msg *protocol.ConnectMsg, name, defaultVal string) (string, error) {
1047 v, ok := msg.Info[name]
1048 if !ok {
1049@@ -73,6 +73,19 @@
1050 return s, nil
1051 }
1052
1053+// GetInfoInt helps retrieving an integer out of a protocol.ConnectMsg.Info.
1054+func GetInfoInt(msg *protocol.ConnectMsg, name string, defaultVal int) (int, error) {
1055+ v, ok := msg.Info[name]
1056+ if !ok {
1057+ return defaultVal, nil
1058+ }
1059+ n, ok := v.(float64)
1060+ if !ok {
1061+ return -1, ErrUnexpectedValue
1062+ }
1063+ return int(n), nil
1064+}
1065+
1066 // BrokerSession holds broker session state.
1067 type BrokerSession interface {
1068 // SessionChannel returns the session control channel
1069
1070=== modified file 'server/broker/broker_test.go'
1071--- server/broker/broker_test.go 2014-04-03 14:31:10 +0000
1072+++ server/broker/broker_test.go 2015-04-30 15:00:25 +0000
1073@@ -17,6 +17,7 @@
1074 package broker
1075
1076 import (
1077+ "encoding/json"
1078 "fmt"
1079
1080 . "launchpad.net/gocheck"
1081@@ -48,3 +49,20 @@
1082 v, err = GetInfoString(connectMsg, "foo", "?")
1083 c.Check(err, Equals, ErrUnexpectedValue)
1084 }
1085+
1086+func (s *brokerSuite) TestGetInfoInt(c *C) {
1087+ connectMsg := &protocol.ConnectMsg{}
1088+ v, err := GetInfoInt(connectMsg, "bar", -1)
1089+ c.Check(err, IsNil)
1090+ c.Check(v, Equals, -1)
1091+
1092+ err = json.Unmarshal([]byte(`{"bar": 233}`), &connectMsg.Info)
1093+ c.Assert(err, IsNil)
1094+ v, err = GetInfoInt(connectMsg, "bar", -1)
1095+ c.Check(err, IsNil)
1096+ c.Check(v, Equals, 233)
1097+
1098+ connectMsg.Info["bar"] = "garbage"
1099+ v, err = GetInfoInt(connectMsg, "bar", -1)
1100+ c.Check(err, Equals, ErrUnexpectedValue)
1101+}
1102
1103=== modified file 'testing/tls.go'
1104--- testing/tls.go 2014-09-04 17:54:14 +0000
1105+++ testing/tls.go 2015-04-30 15:00:25 +0000
1106@@ -19,6 +19,7 @@
1107 import (
1108 "crypto/tls"
1109 "crypto/x509"
1110+ "io/ioutil"
1111 )
1112
1113 // 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
1114@@ -43,26 +44,112 @@
1115 DQEBBQNBABtWCdMFkhIO8+oM3vugOWle9WJZ1FCRWD+cMl76mI1lhmNF4lvEZG47
1116 xUjekA1+heU39WpOEzZSybrOdiEaGbI=
1117 -----END CERTIFICATE-----`)
1118-)
1119-
1120-// test tls server & client config
1121-var TestTLSServerConfig, TestTLSClientConfig *tls.Config
1122+
1123+ // key&cert generated with openssl req -x509 -nodes -newkey rsa:2048
1124+ // -multivalue-rdn -sha512 -days 3650 -keyout testing.key -out
1125+ // testing.cert -subj "/O=Acme Co/CN=push-delivery/"
1126+ TestKeyPEMBlock512 = []byte(`-----BEGIN PRIVATE KEY-----
1127+MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4ySO/avJFWps8
1128+AygUZ0dcylNr1UxZb4QPHuO93OXAkYX5ngw7TjnWIGHjvoLzLzPZCxlrGl7e+M1H
1129+GNZqFT3kFv/XYexp9Cx3MCDy0ZWkK9BAVDTAxMkjSR8ZwRjByQqniilDA/kr92NQ
1130+yaL0GlajsxpmcGMjDM0Dp5QF+inQM48ADJpJl0xlfFwE8CwfVVGM8G/ZtQpBJ3AN
1131+RelEG1iF8tsT9nVlWF37Zp9Wp/CxDDVTuzboZx9pkryOeJmm0l93x1aoSy6DTVyg
1132+zjdAOjKFjSsjY7we7x7GgpHuUtXymVH7OHdc0ji5+2O+yf9VEDxuym0fJJEgVLfX
1133+ungSHFxJAgMBAAECggEAeC2gyTqF7KM7+LDY3UQ6Plf8H1KvAC+txKPDXFURO8ep
1134+SaoHrH540RFoeNULl5uobc1xL54L+5n27/lwYbgE85YduHegaVx7mty7YRD78LTq
1135+ERxy3rhdVEyXJInYTxgwjLwnj8VCxdx0RDOPfpCurnKqhdssLryBjZHsjGKh1RzH
1136+bv5fNrqMhU0uH82cOKXy20uzyVo5zuLwWA+PxCEeOTMumpWgN4PmtMrjUot2t2/q
1137+jVoEkrB3B5Xs/s8OrEv10t90nNQPcKT89Kts/jdmgDNNg/dtILogiD4JshTG8fIB
1138+STUArRDCE0NXOmB0XuXRxk8YlZyBj2AsIUQcFRrOgQKBgQDrAkE77wIZcCJRYGxK
1139+KkB5zE5Lei44dKEHU5zIueOflsWFC+RZGWVn1+hTQw9Sk1kqm5atrDbfMZDOk62U
1140+bNcQLT+QqDRo3iSYLo9Q5hFNNxMGUm6RMHApr5iIZeoBFDZ7b4+zCEEFNtYukvjY
1141+DWyeTgUqftoOTDebHbHrk9w/0QKBgQDJSnnestarqjLXyF4RWzcFTsDjFgRv53Cq
1142+WrpiQUkk5JLlKliwoTAGTxzH2skJofT6OAQjrc5489mc5Gt6TVwWB49l+OzzG4H/
1143+QSe5X9I5BEEcdD27wDwsaO/NsusM9jZ4IjauTKR5XqGoepbrWrm7+lBgEe1DvBWx
1144+C71U7Eoq+QKBgQDNJT2+zMf/XrSGZu6A21tHN0KNfo2EeMLsu19clXCPKjUoDBZ8
1145+dL/ho0bKD/r7MWcf24vv9So9MW5f9egLbeta0rTvWPXPKUO2mMZAb2VhCxePaDve
1146+f/MZYJB9WMGpyXQ50kwVk7n2jETxiRiyuR09H4xA6VT+MChGPujGZV9ZUQKBgH7i
1147+06/uTCQqRaKAS8vlE+nkmvKLDoD8A6lfR95oCROYgoCzEPVGpl9Tv3C8Gb5YuXSB
1148+mxpilaTpEmQ0GQwfd8zrNxmwsK0OygN9ruzL2ljWtbSaEdAofcYA4Clqf4DMM8nG
1149+x3FYHtXjMURjAn+Z0TsNr1zf8BCin4nbPJ4r1RUBAoGBALFHLtEWwVxpm3MN4f08
1150+GtH2Phd289H0s5SaX/NaWYy44T+Q/d7LuYk72LWX1jZB/2V3OhiFzih0uK44PBM4
1151+Gaiu8c/vl+M1hixeOenTrapE4ORaYt76INIEC8JpqEvGi0DYkUH1D4F8zzAiejgF
1152+t+nz90UBRCRA8vtZ8fiwz8O0
1153+-----END PRIVATE KEY-----`)
1154+
1155+ TestCertPEMBlock512 = []byte(`-----BEGIN CERTIFICATE-----
1156+MIIDJzCCAg+gAwIBAgIJAP9ScfFaKlalMA0GCSqGSIb3DQEBDQUAMCoxEDAOBgNV
1157+BAoMB0FjbWUgQ28xFjAUBgNVBAMMDXB1c2gtZGVsaXZlcnkwHhcNMTUwNDE1MTYx
1158+MDM1WhcNMjUwNDEyMTYxMDM1WjAqMRAwDgYDVQQKDAdBY21lIENvMRYwFAYDVQQD
1159+DA1wdXNoLWRlbGl2ZXJ5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
1160+uMkjv2ryRVqbPAMoFGdHXMpTa9VMWW+EDx7jvdzlwJGF+Z4MO0451iBh476C8y8z
1161+2QsZaxpe3vjNRxjWahU95Bb/12HsafQsdzAg8tGVpCvQQFQ0wMTJI0kfGcEYwckK
1162+p4opQwP5K/djUMmi9BpWo7MaZnBjIwzNA6eUBfop0DOPAAyaSZdMZXxcBPAsH1VR
1163+jPBv2bUKQSdwDUXpRBtYhfLbE/Z1ZVhd+2afVqfwsQw1U7s26GcfaZK8jniZptJf
1164+d8dWqEsug01coM43QDoyhY0rI2O8Hu8exoKR7lLV8plR+zh3XNI4uftjvsn/VRA8
1165+bsptHySRIFS317p4EhxcSQIDAQABo1AwTjAdBgNVHQ4EFgQUG2Qk9GbWWfSPXRTE
1166++cfOZMljydAwHwYDVR0jBBgwFoAUG2Qk9GbWWfSPXRTE+cfOZMljydAwDAYDVR0T
1167+BAUwAwEB/zANBgkqhkiG9w0BAQ0FAAOCAQEAUw36s8n8a39ECYUmSS5o+PdjmF1v
1168+6K6ld5n7IlFVwCtA1Rkz2L2AUrko/ao1/ZgKhHsIBFQ7mm5fkvuNd14ZEJ0F8LyI
1169+55Et63IYWYOPHl0oNmzTHex0WRL9nmNvxbQ5UytzGTE5amv/sZTOYH9qnpEes68O
1170+TPP+C3OoM+U6hjOXNGG73zb54JHQUZ4arMg2gbVzxNXU2ReoKYKrYexGGuqIlHcE
1171+XdOQp93oJfqWAj111YS6tIn63ccjx7bKzFzaufuVvCIsk0WrXG2rpuqx+0OYzRKc
1172+deU3hnONgWVXjCQdNysBzUXLeOWcv1KuqScETvGZe7D1UIk7HWsAgnQnYQ==
1173+-----END CERTIFICATE-----`)
1174+
1175+ // key&cert, same as server/acceptance/ssl/testing.*
1176+ TestKeyPEMBlockAcceptance []byte
1177+
1178+ TestCertPEMBlockAcceptance []byte
1179+)
1180+
1181+// test tls server & client configs
1182+var (
1183+ TestTLSServerConfigs = map[string]*tls.Config{}
1184+ TestTLSClientConfigs = map[string]*tls.Config{}
1185+ TestTLSServerConfig, TestTLSClientConfig *tls.Config
1186+)
1187
1188 func init() {
1189- cert, err := tls.X509KeyPair(TestCertPEMBlock, TestKeyPEMBlock)
1190- if err != nil {
1191- panic(err)
1192- }
1193- TestTLSServerConfig = &tls.Config{
1194- Certificates: []tls.Certificate{cert},
1195- }
1196- cp := x509.NewCertPool()
1197- ok := cp.AppendCertsFromPEM(TestCertPEMBlock)
1198- if !ok {
1199- panic("failed to parse test cert")
1200- }
1201- TestTLSClientConfig = &tls.Config{
1202- RootCAs: cp,
1203- ServerName: "push-delivery",
1204- }
1205+ var err error
1206+ TestKeyPEMBlockAcceptance, err = ioutil.ReadFile(SourceRelative("../server/acceptance/ssl/testing.key"))
1207+ if err != nil {
1208+ panic(err)
1209+ }
1210+
1211+ TestCertPEMBlockAcceptance, err = ioutil.ReadFile(SourceRelative("../server/acceptance/ssl/testing.cert"))
1212+ if err != nil {
1213+ panic(err)
1214+ }
1215+
1216+ for _, cfgBits := range []struct {
1217+ label string
1218+ key []byte
1219+ cert []byte
1220+ }{
1221+ {"sha1", TestKeyPEMBlock, TestCertPEMBlock},
1222+ {"sha512", TestKeyPEMBlock512, TestCertPEMBlock512},
1223+ {"acceptance", TestKeyPEMBlockAcceptance, TestCertPEMBlockAcceptance},
1224+ } {
1225+ cert, err := tls.X509KeyPair(cfgBits.cert, cfgBits.key)
1226+ if err != nil {
1227+ panic(err)
1228+ }
1229+ tlsServerConfig := &tls.Config{
1230+ Certificates: []tls.Certificate{cert},
1231+ }
1232+ cp := x509.NewCertPool()
1233+ ok := cp.AppendCertsFromPEM(cfgBits.cert)
1234+ if !ok {
1235+ panic("failed to parse test cert")
1236+ }
1237+ tlsClientConfig := &tls.Config{
1238+ RootCAs: cp,
1239+ ServerName: "push-delivery",
1240+ }
1241+ TestTLSClientConfigs[cfgBits.label] = tlsClientConfig
1242+ TestTLSServerConfigs[cfgBits.label] = tlsServerConfig
1243+ }
1244+ TestTLSClientConfig = TestTLSClientConfigs["sha1"]
1245+ TestTLSServerConfig = TestTLSServerConfigs["sha1"]
1246 }

Subscribers

People subscribed via source and target branches