Merge lp:~chipaca/ubuntu-push/shuffle-signing-bits into lp:ubuntu-push/automatic

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 181
Merged at revision: 180
Proposed branch: lp:~chipaca/ubuntu-push/shuffle-signing-bits
Merge into: lp:ubuntu-push/automatic
Diff against target: 200 lines (+69/-40)
5 files modified
client/client.go (+21/-1)
client/client_test.go (+36/-1)
client/session/session.go (+5/-17)
client/session/session_test.go (+6/-21)
debian/changelog (+1/-0)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/shuffle-signing-bits
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Review via email: mp+222783@code.launchpad.net

This proposal supersedes a proposal from 2014-06-11.

Commit message

Move the signing bits about a bit (up from session to client, for reuse from service).

Description of the change

Move the signing bits about a bit (up from session to client, for reuse from service).

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

Other than the text conflict it looks good.

review: Approve
181. By John Lenton

merged trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/client.go'
--- client/client.go 2014-05-21 10:03:18 +0000
+++ client/client.go 2014-06-11 13:44:07 +0000
@@ -28,6 +28,7 @@
28 "fmt"28 "fmt"
29 "io/ioutil"29 "io/ioutil"
30 "os"30 "os"
31 "os/exec"
31 "strings"32 "strings"
3233
33 "launchpad.net/go-dbus/v1"34 "launchpad.net/go-dbus/v1"
@@ -160,7 +161,26 @@
160 ExpectAllRepairedTime: client.config.ExpectAllRepairedTime.TimeDuration(),161 ExpectAllRepairedTime: client.config.ExpectAllRepairedTime.TimeDuration(),
161 PEM: client.pem,162 PEM: client.pem,
162 Info: info,163 Info: info,
163 AuthHelper: client.config.AuthHelper,164 AuthGetter: client.getAuthorization,
165 }
166}
167
168// getAuthorization gets the authorization blob to send to the server
169func (client *PushClient) getAuthorization() string {
170 client.log.Debugf("getting authorization")
171 // using a helper, for now at least
172 if len(client.config.AuthHelper) == 0 {
173 // do nothing if helper is unset or empty
174 return ""
175 }
176
177 auth, err := exec.Command(client.config.AuthHelper[0], client.config.AuthHelper[1:]...).Output()
178 if err != nil {
179 // For now we just log the error, as we don't want to block unauthorized users
180 client.log.Errorf("unable to get the authorization token from the account: %v", err)
181 return ""
182 } else {
183 return strings.TrimSpace(string(auth))
164 }184 }
165}185}
166186
167187
=== modified file 'client/client_test.go'
--- client/client_test.go 2014-05-20 13:56:37 +0000
+++ client/client_test.go 2014-06-11 13:44:07 +0000
@@ -272,7 +272,7 @@
272 ExpectAllRepairedTime: 30 * time.Minute,272 ExpectAllRepairedTime: 30 * time.Minute,
273 PEM: cli.pem,273 PEM: cli.pem,
274 Info: info,274 Info: info,
275 AuthHelper: []string{"auth", "helper"},275 AuthGetter: func() string { return "" },
276 }276 }
277 // sanity check that we are looking at all fields277 // sanity check that we are looking at all fields
278 vExpected := reflect.ValueOf(expected)278 vExpected := reflect.ValueOf(expected)
@@ -284,6 +284,11 @@
284 }284 }
285 // finally compare285 // finally compare
286 conf := cli.deriveSessionConfig(info)286 conf := cli.deriveSessionConfig(info)
287 // compare authGetter by string
288 c.Check(fmt.Sprintf("%v", conf.AuthGetter), Equals, fmt.Sprintf("%v", cli.getAuthorization))
289 // and set it to nil
290 conf.AuthGetter = nil
291 expected.AuthGetter = nil
287 c.Check(conf, DeepEquals, expected)292 c.Check(conf, DeepEquals, expected)
288}293}
289294
@@ -951,3 +956,33 @@
951 c.Assert(err, NotNil)956 c.Assert(err, NotNil)
952 c.Check(cs.log.Captured(), Matches, "(?msi).*showing notification: no way$")957 c.Check(cs.log.Captured(), Matches, "(?msi).*showing notification: no way$")
953}958}
959
960/*****************************************************************
961 getAuthorization() tests
962******************************************************************/
963
964func (cs *clientSuite) TestGetAuthorizationIgnoresErrors(c *C) {
965 cli := NewPushClient(cs.configPath, cs.leveldbPath)
966 cli.configure()
967 cli.config.AuthHelper = []string{"sh", "-c", "echo hello; false"}
968
969 c.Check(cli.getAuthorization(), Equals, "")
970}
971
972func (cs *clientSuite) TestGetAuthorizationGetsIt(c *C) {
973 cli := NewPushClient(cs.configPath, cs.leveldbPath)
974 cli.configure()
975 cli.config.AuthHelper = []string{"echo", "hello"}
976
977 c.Check(cli.getAuthorization(), Equals, "hello")
978}
979
980func (cs *clientSuite) TestGetAuthorizationWorksIfUnsetOrNil(c *C) {
981 cli := NewPushClient(cs.configPath, cs.leveldbPath)
982 cli.log = cs.log
983
984 c.Assert(cli.config, NotNil)
985 c.Check(cli.getAuthorization(), Equals, "")
986 cli.configure()
987 c.Check(cli.getAuthorization(), Equals, "")
988}
954989
=== modified file 'client/session/session.go'
--- client/session/session.go 2014-05-23 05:59:38 +0000
+++ client/session/session.go 2014-06-11 13:44:07 +0000
@@ -26,7 +26,6 @@
26 "fmt"26 "fmt"
27 "math/rand"27 "math/rand"
28 "net"28 "net"
29 "os/exec"
30 "strings"29 "strings"
31 "sync"30 "sync"
32 "sync/atomic"31 "sync/atomic"
@@ -87,7 +86,7 @@
87 ExpectAllRepairedTime time.Duration86 ExpectAllRepairedTime time.Duration
88 PEM []byte87 PEM []byte
89 Info map[string]interface{}88 Info map[string]interface{}
90 AuthHelper []string89 AuthGetter func() string
91}90}
9291
93// ClientSession holds a client<->server session and its configuration.92// ClientSession holds a client<->server session and its configuration.
@@ -244,21 +243,10 @@
244// addAuthorization gets the authorization blob to send to the server243// addAuthorization gets the authorization blob to send to the server
245// and adds it to the session.244// and adds it to the session.
246func (sess *ClientSession) addAuthorization() error {245func (sess *ClientSession) addAuthorization() error {
247 sess.Log.Debugf("adding authorization")246 if sess.AuthGetter != nil {
248 // using a helper, for now at least247 sess.Log.Debugf("adding authorization")
249 if len(sess.AuthHelper) == 0 {248 sess.auth = sess.AuthGetter()
250 // do nothing if helper is unset or empty249 }
251 return nil
252 }
253
254 auth, err := exec.Command(sess.AuthHelper[0], sess.AuthHelper[1:]...).Output()
255 if err != nil {
256 // For now we just log the error, as we don't want to block unauthorized users
257 sess.Log.Errorf("unable to get the authorization token from the account: %v", err)
258 } else {
259 sess.auth = strings.TrimSpace(string(auth))
260 }
261
262 return nil250 return nil
263}251}
264252
265253
=== modified file 'client/session/session_test.go'
--- client/session/session_test.go 2014-05-23 05:59:38 +0000
+++ client/session/session_test.go 2014-06-11 13:44:07 +0000
@@ -354,33 +354,18 @@
354354
355func (cs *clientSessionSuite) TestAddAuthorizationAddsAuthorization(c *C) {355func (cs *clientSessionSuite) TestAddAuthorizationAddsAuthorization(c *C) {
356 sess := &ClientSession{Log: cs.log}356 sess := &ClientSession{Log: cs.log}
357 sess.AuthHelper = []string{"echo", "some auth"}357 sess.AuthGetter = func() string { return "some auth" }
358 c.Assert(sess.auth, Equals, "")358 c.Assert(sess.auth, Equals, "")
359 err := sess.addAuthorization()359 err := sess.addAuthorization()
360 c.Assert(err, IsNil)360 c.Assert(err, IsNil)
361 c.Check(sess.auth, Equals, "some auth")361 c.Check(sess.auth, Equals, "some auth")
362}362}
363363
364func (cs *clientSessionSuite) TestAddAuthorizationIgnoresErrors(c *C) {364func (cs *clientSessionSuite) TestAddAuthorizationSkipsIfUnset(c *C) {
365 sess := &ClientSession{Log: cs.log}365 sess := &ClientSession{Log: cs.log}
366 sess.AuthHelper = []string{"sh", "-c", "echo hello; false"}366 sess.AuthGetter = nil
367367 c.Assert(sess.auth, Equals, "")
368 c.Assert(sess.auth, Equals, "")368 err := sess.addAuthorization()
369 err := sess.addAuthorization()
370 c.Assert(err, IsNil)
371 c.Check(sess.auth, Equals, "")
372}
373
374func (cs *clientSessionSuite) TestAddAuthorizationSkipsIfUnsetOrNil(c *C) {
375 sess := &ClientSession{Log: cs.log}
376 sess.AuthHelper = nil
377 c.Assert(sess.auth, Equals, "")
378 err := sess.addAuthorization()
379 c.Assert(err, IsNil)
380 c.Check(sess.auth, Equals, "")
381
382 sess.AuthHelper = []string{}
383 err = sess.addAuthorization()
384 c.Assert(err, IsNil)369 c.Assert(err, IsNil)
385 c.Check(sess.auth, Equals, "")370 c.Check(sess.auth, Equals, "")
386}371}
387372
=== modified file 'debian/changelog'
--- debian/changelog 2014-06-06 12:13:37 +0000
+++ debian/changelog 2014-06-11 13:44:07 +0000
@@ -9,6 +9,7 @@
99
10 [ John R. Lenton ]10 [ John R. Lenton ]
11 * Switch dbus api to retrieve app name from dbus path.11 * Switch dbus api to retrieve app name from dbus path.
12 * Move signing bits up from session to client, for reuse by service.
1213
13 -- John R. Lenton <john.lenton@canonical.com> Fri, 06 Jun 2014 12:02:56 +010014 -- John R. Lenton <john.lenton@canonical.com> Fri, 06 Jun 2014 12:02:56 +0100
1415

Subscribers

People subscribed via source and target branches