Merge lp:~pedronis/ubuntu-push/refactor-service-setup into lp:ubuntu-push/automatic

Proposed by Samuele Pedroni
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 217
Merged at revision: 215
Proposed branch: lp:~pedronis/ubuntu-push/refactor-service-setup
Merge into: lp:ubuntu-push/automatic
Diff against target: 657 lines (+226/-148)
7 files modified
client/client.go (+19/-4)
client/client_test.go (+59/-4)
client/service/service.go (+54/-68)
client/service/service_test.go (+82/-71)
debian/config.json (+1/-1)
server/session/session_test.go (+1/-0)
testing/helpers.go (+10/-0)
To merge this branch: bzr merge lp:~pedronis/ubuntu-push/refactor-service-setup
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+225478@code.launchpad.net

This proposal supersedes a proposal from 2014-07-03.

Commit message

* let take NewPushService a setup obj, have a generic manageReg
* update config.json now that registration is a base url

Description of the change

* let take NewPushService a setup obj, have a generic manageReg
* update config.json now that registration is a base url

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (7.1 KiB)

The attempt to merge lp:~pedronis/ubuntu-push/refactor-service-setup into lp:ubuntu-push/automatic failed. Below is the output from the failed tests.

scripts/deps.sh ubuntu-push-client.go
scripts/deps.sh server/dev/server.go
scripts/deps.sh server/acceptance/cmd/acceptanceclient.go
/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin/godeps -t launchpad.net/ubuntu-push launchpad.net/ubuntu-push/bus launchpad.net/ubuntu-push/bus/connectivity launchpad.net/ubuntu-push/bus/networkmanager launchpad.net/ubuntu-push/bus/notifications launchpad.net/ubuntu-push/bus/notifications/app_helper launchpad.net/ubuntu-push/bus/systemimage launchpad.net/ubuntu-push/bus/testing launchpad.net/ubuntu-push/bus/urldispatcher launchpad.net/ubuntu-push/client launchpad.net/ubuntu-push/client/gethosts launchpad.net/ubuntu-push/client/service launchpad.net/ubuntu-push/client/session launchpad.net/ubuntu-push/client/session/seenstate launchpad.net/ubuntu-push/config launchpad.net/ubuntu-push/external/murmur3 launchpad.net/ubuntu-push/launch_helper launchpad.net/ubuntu-push/logger launchpad.net/ubuntu-push/messaging launchpad.net/ubuntu-push/messaging/cmessaging launchpad.net/ubuntu-push/messaging/reply launchpad.net/ubuntu-push/nih launchpad.net/ubuntu-push/nih/cnih launchpad.net/ubuntu-push/protocol launchpad.net/ubuntu-push/server launchpad.net/ubuntu-push/server/api launchpad.net/ubuntu-push/server/broker launchpad.net/ubuntu-push/server/broker/simple launchpad.net/ubuntu-push/server/broker/testing launchpad.net/ubuntu-push/server/broker/testsuite launchpad.net/ubuntu-push/server/dev launchpad.net/ubuntu-push/server/listener launchpad.net/ubuntu-push/server/session launchpad.net/ubuntu-push/server/store launchpad.net/ubuntu-push/testing launchpad.net/ubuntu-push/testing/condition launchpad.net/ubuntu-push/util launchpad.net/ubuntu-push/whoopsie launchpad.net/ubuntu-push/whoopsie/identifier launchpad.net/ubuntu-push/whoopsie/identifier/testing launchpad.net/ubuntu-push/server/acceptance/cmd/ launchpad.net/ubuntu-push/server/dev/ launchpad.net/ubuntu-push/ 2>/dev/null | cat > dependencies.tsv
rm -f -r /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
go get -u launchpad.net/godeps
go get -d -u launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 code.google.com/p/go-uuid/uuid
/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin/godeps -u dependencies.tsv
go install launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 code.google.com/p/go-uuid/uuid
go test launchpad.net/ubuntu-push launchpad.net/ubuntu-push/bus launchpad.net/ubuntu-push/bus/connectivity launchpad.net/ubuntu-push/bus/networkmanager launchpad.net/ubuntu-push/bus/notifications launchpad.net/ubuntu-push/bus/notifications/app_helper launchpad.net/ubuntu-push/bus/systemimage launchpad.net/ubuntu-push/bus/testing launchpad.net/ubuntu-push/bus/urldispatcher launchpad.net/ubuntu-push/client launchpad.net/ubuntu-push/client/gethosts launchpad.net/ubuntu-push/client/service launchpad.net/ubuntu-pu...

Read more...

217. By Samuele Pedroni

wait for inc elapsed time

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/client.go'
2--- client/client.go 2014-07-02 20:52:56 +0000
3+++ client/client.go 2014-07-03 14:25:59 +0000
4@@ -26,6 +26,7 @@
5 "errors"
6 "fmt"
7 "io/ioutil"
8+ "net/url"
9 "os"
10 "os/exec"
11 "strings"
12@@ -163,6 +164,19 @@
13 }
14 }
15
16+// derivePushServiceSetup derives the service setup from the client configuration bits.
17+func (client *PushClient) derivePushServiceSetup() (*service.PushServiceSetup, error) {
18+ setup := new(service.PushServiceSetup)
19+ purl, err := url.Parse(client.config.RegistrationURL)
20+ if err != nil {
21+ return nil, fmt.Errorf("cannot parse registration url: %v", err)
22+ }
23+ setup.RegURL = purl
24+ setup.DeviceId = client.deviceId
25+ setup.AuthGetter = client.getAuthorization
26+ return setup, nil
27+}
28+
29 // getAuthorization gets the authorization blob to send to the server
30 func (client *PushClient) getAuthorization(url string) string {
31 client.log.Debugf("getting authorization for %s", url)
32@@ -399,6 +413,10 @@
33 }
34
35 func (client *PushClient) startService() error {
36+ setup, err := client.derivePushServiceSetup()
37+ if err != nil {
38+ return err
39+ }
40 if client.pushServiceEndpoint == nil {
41 client.pushServiceEndpoint = bus.SessionBus.Endpoint(service.PushServiceBusAddress, client.log)
42 }
43@@ -406,10 +424,7 @@
44 client.postalServiceEndpoint = bus.SessionBus.Endpoint(service.PostalServiceBusAddress, client.log)
45 }
46
47- client.pushService = service.NewPushService(client.pushServiceEndpoint, client.log)
48- client.pushService.SetRegistrationURL(client.config.RegistrationURL)
49- client.pushService.SetAuthGetter(client.getAuthorization)
50- client.pushService.SetDeviceId(client.deviceId)
51+ client.pushService = service.NewPushService(client.pushServiceEndpoint, setup, client.log)
52 if err := client.pushService.Start(); err != nil {
53 return err
54 }
55
56=== modified file 'client/client_test.go'
57--- client/client_test.go 2014-07-02 20:52:56 +0000
58+++ client/client_test.go 2014-07-03 14:25:59 +0000
59@@ -289,7 +289,7 @@
60 // finally compare
61 conf := cli.deriveSessionConfig(info)
62 // compare authGetter by string
63- c.Check(fmt.Sprintf("%v", conf.AuthGetter), Equals, fmt.Sprintf("%v", cli.getAuthorization))
64+ c.Check(fmt.Sprintf("%#v", conf.AuthGetter), Equals, fmt.Sprintf("%#v", cli.getAuthorization))
65 // and set it to nil
66 conf.AuthGetter = nil
67 expected.AuthGetter = nil
68@@ -297,6 +297,51 @@
69 }
70
71 /*****************************************************************
72+ derivePushServiceSetup tests
73+******************************************************************/
74+
75+func (cs *clientSuite) TestDerivePushServiceSetup(c *C) {
76+ cs.writeTestConfig(map[string]interface{}{})
77+ cli := NewPushClient(cs.configPath, cs.leveldbPath)
78+ err := cli.configure()
79+ c.Assert(err, IsNil)
80+ cli.deviceId = "zoo"
81+ expected := &service.PushServiceSetup{
82+ DeviceId: "zoo",
83+ AuthGetter: func(string) string { return "" },
84+ RegURL: helpers.ParseURL("reg://"),
85+ }
86+ // sanity check that we are looking at all fields
87+ vExpected := reflect.ValueOf(expected).Elem()
88+ nf := vExpected.NumField()
89+ for i := 0; i < nf; i++ {
90+ fv := vExpected.Field(i)
91+ // field isn't empty/zero
92+ c.Assert(fv.Interface(), Not(DeepEquals), reflect.Zero(fv.Type()).Interface(), Commentf("forgot about: %s", vExpected.Type().Field(i).Name))
93+ }
94+ // finally compare
95+ setup, err := cli.derivePushServiceSetup()
96+ c.Assert(err, IsNil)
97+ // compare authGetter by string
98+ c.Check(fmt.Sprintf("%#v", setup.AuthGetter), Equals, fmt.Sprintf("%#v", cli.getAuthorization))
99+ // and set it to nil
100+ setup.AuthGetter = nil
101+ expected.AuthGetter = nil
102+ c.Check(setup, DeepEquals, expected)
103+}
104+
105+func (cs *clientSuite) TestDerivePushServiceSetupError(c *C) {
106+ cs.writeTestConfig(map[string]interface{}{
107+ "registration_url": "%gh",
108+ })
109+ cli := NewPushClient(cs.configPath, cs.leveldbPath)
110+ err := cli.configure()
111+ c.Assert(err, IsNil)
112+ _, err = cli.derivePushServiceSetup()
113+ c.Check(err, ErrorMatches, "cannot parse registration url:.*")
114+}
115+
116+/*****************************************************************
117 startService tests
118 ******************************************************************/
119
120@@ -305,7 +350,8 @@
121 "auth_helper": helpers.ScriptAbsPath("dummyauth.sh"),
122 })
123 cli := NewPushClient(cs.configPath, cs.leveldbPath)
124- cli.configure()
125+ err := cli.configure()
126+ c.Assert(err, IsNil)
127 cli.log = cs.log
128 cli.deviceId = "fake-id"
129 cli.pushServiceEndpoint = testibus.NewTestingEndpoint(condition.Work(true), nil)
130@@ -314,8 +360,6 @@
131 c.Check(cli.startService(), IsNil)
132 c.Assert(cli.pushService, NotNil)
133 c.Check(cli.pushService.IsRunning(), Equals, true)
134- c.Check(cli.pushService.GetDeviceId(), Equals, "fake-id")
135- c.Check(cli.pushService.GetRegistrationAuthorization(), Equals, "hello reg://")
136 c.Assert(cli.setupPostalService(), IsNil)
137 c.Assert(cli.startPostalService(), IsNil)
138 c.Check(cli.postalService.IsRunning(), Equals, true)
139@@ -323,6 +367,17 @@
140 cli.postalService.Stop()
141 }
142
143+func (cs *clientSuite) TestStartServiceSetupError(c *C) {
144+ cs.writeTestConfig(map[string]interface{}{
145+ "registration_url": "%gh",
146+ })
147+ cli := NewPushClient(cs.configPath, cs.leveldbPath)
148+ err := cli.configure()
149+ c.Assert(err, IsNil)
150+ err = cli.startService()
151+ c.Check(err, ErrorMatches, "cannot parse registration url:.*")
152+}
153+
154 func (cs *clientSuite) TestStartServiceErrorsOnNilLog(c *C) {
155 cli := NewPushClient(cs.configPath, cs.leveldbPath)
156 c.Check(cli.log, IsNil)
157
158=== modified file 'client/service/service.go'
159--- client/service/service.go 2014-07-01 11:55:30 +0000
160+++ client/service/service.go 2014-07-03 14:25:59 +0000
161@@ -23,6 +23,7 @@
162 "fmt"
163 "io/ioutil"
164 "net/http"
165+ "net/url"
166 "os"
167 "strings"
168
169@@ -32,10 +33,17 @@
170 "launchpad.net/ubuntu-push/nih"
171 )
172
173+// PushServiceSetup encapsulates the params for setting up a PushService.
174+type PushServiceSetup struct {
175+ RegURL *url.URL
176+ DeviceId string
177+ AuthGetter func(string) string
178+}
179+
180 // PushService is the dbus api
181 type PushService struct {
182 DBusService
183- regURL string
184+ regURL *url.URL
185 deviceId string
186 authGetter func(string) string
187 httpCli http13.Client
188@@ -50,59 +58,28 @@
189 )
190
191 // NewPushService() builds a new service and returns it.
192-func NewPushService(bus bus.Endpoint, log logger.Logger) *PushService {
193+func NewPushService(bus bus.Endpoint, setup *PushServiceSetup, log logger.Logger) *PushService {
194 var svc = &PushService{}
195 svc.Log = log
196 svc.Bus = bus
197+ svc.regURL = setup.RegURL
198+ svc.deviceId = setup.DeviceId
199+ svc.authGetter = setup.AuthGetter
200 return svc
201 }
202
203-// SetRegistrationURL() sets the registration url for the service
204-func (svc *PushService) SetRegistrationURL(url string) {
205- svc.lock.Lock()
206- defer svc.lock.Unlock()
207- svc.regURL = url
208-}
209-
210-// SetAuthGetter() sets the authorization getter for the service
211-func (svc *PushService) SetAuthGetter(authGetter func(string) string) {
212- svc.lock.Lock()
213- defer svc.lock.Unlock()
214- svc.authGetter = authGetter
215-}
216-
217-// getRegistrationAuthorization() returns the authorization header for
218-// POSTing to the registration HTTP endpoint
219-//
220-// (this is for calling with the lock held)
221-func (svc *PushService) getRegistrationAuthorization() string {
222- if svc.authGetter != nil && svc.regURL != "" {
223- return svc.authGetter(svc.regURL)
224- } else {
225- return ""
226- }
227-}
228-
229-// GetRegistrationAuthorization() returns the authorization header for
230-// POSTing to the registration HTTP endpoint
231-func (svc *PushService) GetRegistrationAuthorization() string {
232- svc.lock.RLock()
233- defer svc.lock.RUnlock()
234- return svc.getRegistrationAuthorization()
235-}
236-
237-// SetDeviceId() sets the device id
238-func (svc *PushService) SetDeviceId(deviceId string) {
239- svc.lock.Lock()
240- defer svc.lock.Unlock()
241- svc.deviceId = deviceId
242-}
243-
244-// GetDeviceId() returns the device id
245-func (svc *PushService) GetDeviceId() string {
246- svc.lock.RLock()
247- defer svc.lock.RUnlock()
248- return svc.deviceId
249+// getAuthorization() returns the URL and the authorization header for
250+// POSTing to the registration HTTP endpoint for op
251+func (svc *PushService) getAuthorization(op string) (string, string) {
252+ if svc.authGetter == nil || svc.regURL == nil {
253+ return "", ""
254+ }
255+ purl, err := svc.regURL.Parse(op)
256+ if err != nil {
257+ panic("op to getAuthorization was invalid")
258+ }
259+ url := purl.String()
260+ return url, svc.authGetter(url)
261 }
262
263 func (svc *PushService) Start() error {
264@@ -130,32 +107,21 @@
265 Message string `json:"message"` //
266 }
267
268-func (svc *PushService) register(path string, args, _ []interface{}) ([]interface{}, error) {
269- svc.lock.RLock()
270- defer svc.lock.RUnlock()
271- if len(args) != 0 {
272- return nil, BadArgCount
273- }
274- raw_appname := path[strings.LastIndex(path, "/")+1:]
275- appname := string(nih.Unquote([]byte(raw_appname)))
276-
277- rv := os.Getenv("PUSH_REG_" + raw_appname)
278- if rv != "" {
279- return []interface{}{rv}, nil
280- }
281-
282- req_body, err := json.Marshal(registrationRequest{svc.deviceId, appname})
283+func (svc *PushService) manageReg(op, appId string) (*registrationReply, error) {
284+ req_body, err := json.Marshal(registrationRequest{svc.deviceId, appId})
285 if err != nil {
286 return nil, fmt.Errorf("unable to marshal register request body: %v", err)
287 }
288- req, err := http13.NewRequest("POST", svc.regURL, bytes.NewReader(req_body))
289- if err != nil {
290- return nil, fmt.Errorf("unable to build register request: %v", err)
291- }
292- auth := svc.getRegistrationAuthorization()
293+
294+ url, auth := svc.getAuthorization(op)
295 if auth == "" {
296 return nil, BadAuth
297 }
298+
299+ req, err := http13.NewRequest("POST", url, bytes.NewReader(req_body))
300+ if err != nil {
301+ panic(fmt.Errorf("unable to build register request: %v", err))
302+ }
303 req.Header.Add("Authorization", auth)
304 req.Header.Add("Content-Type", "application/json")
305
306@@ -188,6 +154,26 @@
307 return nil, fmt.Errorf("unable to unmarshal register response: %v", err)
308 }
309
310+ return &reply, nil
311+}
312+
313+func (svc *PushService) register(path string, args, _ []interface{}) ([]interface{}, error) {
314+ if len(args) != 0 {
315+ return nil, BadArgCount
316+ }
317+ raw_appname := path[strings.LastIndex(path, "/")+1:]
318+ appname := string(nih.Unquote([]byte(raw_appname)))
319+
320+ rv := os.Getenv("PUSH_REG_" + raw_appname)
321+ if rv != "" {
322+ return []interface{}{rv}, nil
323+ }
324+
325+ reply, err := svc.manageReg("/register", appname)
326+ if err != nil {
327+ return nil, err
328+ }
329+
330 if !reply.Ok || reply.Token == "" {
331 svc.Log.Errorf("Unexpected response: %#v", reply)
332 return nil, BadToken
333
334=== modified file 'client/service/service_test.go'
335--- client/service/service_test.go 2014-06-20 12:33:03 +0000
336+++ client/service/service_test.go 2014-07-03 14:25:59 +0000
337@@ -47,8 +47,25 @@
338 ss.bus = testibus.NewTestingEndpoint(condition.Work(true), nil)
339 }
340
341+var testSetup = &PushServiceSetup{}
342+
343+func (ss *serviceSuite) TestBuild(c *C) {
344+ setup := &PushServiceSetup{
345+ RegURL: helpers.ParseURL("http://reg"),
346+ DeviceId: "FOO",
347+ AuthGetter: func(s string) string {
348+ return ""
349+ },
350+ }
351+ svc := NewPushService(ss.bus, setup, ss.log)
352+ c.Check(svc.Bus, Equals, ss.bus)
353+ c.Check(svc.regURL, DeepEquals, helpers.ParseURL("http://reg"))
354+ c.Check(fmt.Sprintf("%#v", svc.authGetter), Equals, fmt.Sprintf("%#v", setup.AuthGetter))
355+ // ...
356+}
357+
358 func (ss *serviceSuite) TestStart(c *C) {
359- svc := NewPushService(ss.bus, ss.log)
360+ svc := NewPushService(ss.bus, testSetup, ss.log)
361 c.Check(svc.IsRunning(), Equals, false)
362 c.Check(svc.Start(), IsNil)
363 c.Check(svc.IsRunning(), Equals, true)
364@@ -56,31 +73,31 @@
365 }
366
367 func (ss *serviceSuite) TestStartTwice(c *C) {
368- svc := NewPushService(ss.bus, ss.log)
369+ svc := NewPushService(ss.bus, testSetup, ss.log)
370 c.Check(svc.Start(), IsNil)
371 c.Check(svc.Start(), Equals, AlreadyStarted)
372 svc.Stop()
373 }
374
375 func (ss *serviceSuite) TestStartNoLog(c *C) {
376- svc := NewPushService(ss.bus, nil)
377+ svc := NewPushService(ss.bus, testSetup, nil)
378 c.Check(svc.Start(), Equals, NotConfigured)
379 }
380
381 func (ss *serviceSuite) TestStartNoBus(c *C) {
382- svc := NewPushService(nil, ss.log)
383+ svc := NewPushService(nil, testSetup, ss.log)
384 c.Check(svc.Start(), Equals, NotConfigured)
385 }
386
387 func (ss *serviceSuite) TestStartFailsOnBusDialFailure(c *C) {
388 bus := testibus.NewTestingEndpoint(condition.Work(false), nil)
389- svc := NewPushService(bus, ss.log)
390+ svc := NewPushService(bus, testSetup, ss.log)
391 c.Check(svc.Start(), ErrorMatches, `.*(?i)cond said no.*`)
392 svc.Stop()
393 }
394
395 func (ss *serviceSuite) TestStartGrabsName(c *C) {
396- svc := NewPushService(ss.bus, ss.log)
397+ svc := NewPushService(ss.bus, testSetup, ss.log)
398 c.Assert(svc.Start(), IsNil)
399 callArgs := testibus.GetCallArgs(ss.bus)
400 defer svc.Stop()
401@@ -89,7 +106,7 @@
402 }
403
404 func (ss *serviceSuite) TestStopClosesBus(c *C) {
405- svc := NewPushService(ss.bus, ss.log)
406+ svc := NewPushService(ss.bus, testSetup, ss.log)
407 c.Assert(svc.Start(), IsNil)
408 svc.Stop()
409 callArgs := testibus.GetCallArgs(ss.bus)
410@@ -99,35 +116,27 @@
411
412 // registration tests
413
414-func (ss *serviceSuite) TestSetRegURLWorks(c *C) {
415- svc := NewPushService(ss.bus, ss.log)
416- c.Check(svc.regURL, Equals, "")
417- svc.SetRegistrationURL("xyzzy://")
418- c.Check(svc.regURL, Equals, "xyzzy://")
419-}
420-
421-func (ss *serviceSuite) TestSetAuthGetterWorks(c *C) {
422- svc := NewPushService(ss.bus, ss.log)
423- c.Check(svc.authGetter, IsNil)
424- f := func(string) string { return "" }
425- svc.SetAuthGetter(f)
426- c.Check(fmt.Sprintf("%#v", svc.authGetter), Equals, fmt.Sprintf("%#v", f))
427-}
428-
429 func (ss *serviceSuite) TestGetRegAuthWorks(c *C) {
430- svc := NewPushService(ss.bus, ss.log)
431- svc.SetRegistrationURL("xyzzy://")
432 ch := make(chan string, 1)
433- f := func(s string) string { ch <- s; return "Auth " + s }
434- svc.SetAuthGetter(f)
435- c.Check(svc.getRegistrationAuthorization(), Equals, "Auth xyzzy://")
436+ setup := &PushServiceSetup{
437+ RegURL: helpers.ParseURL("http://foo"),
438+ AuthGetter: func(s string) string {
439+ ch <- s
440+ return "Auth " + s
441+ },
442+ }
443+ svc := NewPushService(ss.bus, setup, ss.log)
444+ url, auth := svc.getAuthorization("/op")
445+ c.Check(auth, Equals, "Auth http://foo/op")
446 c.Assert(len(ch), Equals, 1)
447- c.Check(<-ch, Equals, "xyzzy://")
448+ c.Check(<-ch, Equals, "http://foo/op")
449+ c.Check(url, Equals, "http://foo/op")
450 }
451
452 func (ss *serviceSuite) TestGetRegAuthDoesNotPanic(c *C) {
453- svc := NewPushService(ss.bus, ss.log)
454- c.Check(svc.getRegistrationAuthorization(), Equals, "")
455+ svc := NewPushService(ss.bus, testSetup, ss.log)
456+ _, auth := svc.getAuthorization("/op")
457+ c.Check(auth, Equals, "")
458 }
459
460 func (ss *serviceSuite) TestRegistrationFailsIfBadArgs(c *C) {
461@@ -149,11 +158,12 @@
462 fmt.Fprintln(w, `{"ok":true,"token":"blob-of-bytes"}`)
463 }))
464 defer ts.Close()
465-
466- svc := NewPushService(ss.bus, ss.log)
467- svc.SetAuthGetter(func(string) string { return "tok" })
468- svc.SetRegistrationURL(ts.URL)
469- svc.SetDeviceId("fake-device-id")
470+ setup := &PushServiceSetup{
471+ DeviceId: "fake-device-id",
472+ RegURL: helpers.ParseURL(ts.URL),
473+ AuthGetter: func(string) string { return "tok" },
474+ }
475+ svc := NewPushService(ss.bus, setup, ss.log)
476 // this'll check (un)quoting, too
477 reg, err := svc.register("/an_2dapp_2did", nil, nil)
478 c.Assert(err, IsNil)
479@@ -175,60 +185,59 @@
480 c.Check(err, IsNil)
481 }
482
483-func (ss *serviceSuite) TestRegistrationFailsOnBadReqURL(c *C) {
484- svc := NewPushService(ss.bus, ss.log)
485- svc.SetRegistrationURL("%gh")
486- reg, err := svc.register("thing", nil, nil)
487- c.Check(reg, IsNil)
488- c.Check(err, ErrorMatches, "unable to build register request: .*")
489-}
490-
491-func (ss *serviceSuite) TestRegistrationFailsOnBadAuth(c *C) {
492- svc := NewPushService(ss.bus, ss.log)
493+func (ss *serviceSuite) TestManageRegFailsOnBadAuth(c *C) {
494 // ... no auth added
495+ svc := NewPushService(ss.bus, testSetup, ss.log)
496 reg, err := svc.register("thing", nil, nil)
497 c.Check(reg, IsNil)
498 c.Check(err, Equals, BadAuth)
499 }
500
501-func (ss *serviceSuite) TestRegistrationFailsOnNoServer(c *C) {
502- svc := NewPushService(ss.bus, ss.log)
503- svc.SetRegistrationURL("xyzzy://")
504- svc.SetAuthGetter(func(string) string { return "tok" })
505+func (ss *serviceSuite) TestManageRegFailsOnNoServer(c *C) {
506+ setup := &PushServiceSetup{
507+ DeviceId: "fake-device-id",
508+ RegURL: helpers.ParseURL("xyzzy://"),
509+ AuthGetter: func(string) string { return "tok" },
510+ }
511+ svc := NewPushService(ss.bus, setup, ss.log)
512 reg, err := svc.register("thing", nil, nil)
513 c.Check(reg, IsNil)
514 c.Check(err, ErrorMatches, "unable to request registration: .*")
515 }
516
517-func (ss *serviceSuite) TestRegistrationFailsOn40x(c *C) {
518+func (ss *serviceSuite) TestManageRegFailsOn40x(c *C) {
519 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
520 http.Error(w, "I'm a teapot", 418)
521 }))
522 defer ts.Close()
523-
524- svc := NewPushService(ss.bus, ss.log)
525- svc.SetAuthGetter(func(string) string { return "tok" })
526- svc.SetRegistrationURL(ts.URL)
527+ setup := &PushServiceSetup{
528+ DeviceId: "fake-device-id",
529+ RegURL: helpers.ParseURL(ts.URL),
530+ AuthGetter: func(string) string { return "tok" },
531+ }
532+ svc := NewPushService(ss.bus, setup, ss.log)
533 reg, err := svc.register("/thing", nil, nil)
534 c.Check(err, Equals, BadRequest)
535 c.Check(reg, IsNil)
536 }
537
538-func (ss *serviceSuite) TestRegistrationFailsOn50x(c *C) {
539+func (ss *serviceSuite) TestManageRegFailsOn50x(c *C) {
540 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
541 http.Error(w, "Not implemented", 501)
542 }))
543 defer ts.Close()
544-
545- svc := NewPushService(ss.bus, ss.log)
546- svc.SetAuthGetter(func(string) string { return "tok" })
547- svc.SetRegistrationURL(ts.URL)
548+ setup := &PushServiceSetup{
549+ DeviceId: "fake-device-id",
550+ RegURL: helpers.ParseURL(ts.URL),
551+ AuthGetter: func(string) string { return "tok" },
552+ }
553+ svc := NewPushService(ss.bus, setup, ss.log)
554 reg, err := svc.register("/thing", nil, nil)
555 c.Check(err, Equals, BadServer)
556 c.Check(reg, IsNil)
557 }
558
559-func (ss *serviceSuite) TestRegistrationFailsOnBadJSON(c *C) {
560+func (ss *serviceSuite) TestManageRegFailsOnBadJSON(c *C) {
561 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
562 buf := make([]byte, 256)
563 n, e := r.Body.Read(buf)
564@@ -241,18 +250,19 @@
565 fmt.Fprintln(w, `{`)
566 }))
567 defer ts.Close()
568-
569- svc := NewPushService(ss.bus, ss.log)
570- svc.SetAuthGetter(func(string) string { return "tok" })
571- svc.SetRegistrationURL(ts.URL)
572- svc.SetDeviceId("fake-device-id")
573+ setup := &PushServiceSetup{
574+ DeviceId: "fake-device-id",
575+ RegURL: helpers.ParseURL(ts.URL),
576+ AuthGetter: func(string) string { return "tok" },
577+ }
578+ svc := NewPushService(ss.bus, setup, ss.log)
579 // this'll check (un)quoting, too
580 reg, err := svc.register("/an_2dapp_2did", nil, nil)
581 c.Check(reg, IsNil)
582 c.Check(err, ErrorMatches, "unable to unmarshal register response: .*")
583 }
584
585-func (ss *serviceSuite) TestRegistrationFailsOnBadJSONDocument(c *C) {
586+func (ss *serviceSuite) TestManageRegFailsOnBadJSONDocument(c *C) {
587 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
588 buf := make([]byte, 256)
589 n, e := r.Body.Read(buf)
590@@ -265,11 +275,12 @@
591 fmt.Fprintln(w, `{"bananas": "very yes"}`)
592 }))
593 defer ts.Close()
594-
595- svc := NewPushService(ss.bus, ss.log)
596- svc.SetAuthGetter(func(string) string { return "tok" })
597- svc.SetRegistrationURL(ts.URL)
598- svc.SetDeviceId("fake-device-id")
599+ setup := &PushServiceSetup{
600+ DeviceId: "fake-device-id",
601+ RegURL: helpers.ParseURL(ts.URL),
602+ AuthGetter: func(string) string { return "tok" },
603+ }
604+ svc := NewPushService(ss.bus, setup, ss.log)
605 // this'll check (un)quoting, too
606 reg, err := svc.register("/an_2dapp_2did", nil, nil)
607 c.Check(reg, IsNil)
608
609=== modified file 'debian/config.json'
610--- debian/config.json 2014-06-19 21:12:04 +0000
611+++ debian/config.json 2014-07-03 14:25:59 +0000
612@@ -1,7 +1,7 @@
613 {
614 "auth_helper": "/usr/lib/ubuntu-push-client/signing-helper",
615 "session_url": "https://push.ubuntu.com/",
616- "registration_url": "https://push.ubuntu.com/register",
617+ "registration_url": "https://push.ubuntu.com",
618 "connect_timeout": "20s",
619 "exchange_timeout": "30s",
620 "hosts_cache_expiry": "12h",
621
622=== modified file 'server/session/session_test.go'
623--- server/session/session_test.go 2014-06-19 13:06:52 +0000
624+++ server/session/session_test.go 2014-07-03 14:25:59 +0000
625@@ -373,6 +373,7 @@
626 pingTimer: time.NewTimer(pingInterval),
627 intervalStart: now,
628 }
629+ time.Sleep(10 * time.Millisecond)
630 l.pingTimer.Stop()
631 done := l.pingTimerReset(true)
632 c.Assert(done, Equals, true)
633
634=== modified file 'testing/helpers.go'
635--- testing/helpers.go 2014-06-23 12:46:28 +0000
636+++ testing/helpers.go 2014-07-03 14:25:59 +0000
637@@ -20,6 +20,7 @@
638 import (
639 "encoding/json"
640 "fmt"
641+ "net/url"
642 "os"
643 "path"
644 "path/filepath"
645@@ -160,3 +161,12 @@
646 }
647 return res
648 }
649+
650+// ParseURL parses a URL conveniently.
651+func ParseURL(s string) *url.URL {
652+ purl, err := url.Parse(s)
653+ if err != nil {
654+ panic(err)
655+ }
656+ return purl
657+}

Subscribers

People subscribed via source and target branches