Rev 28: Change AddUser to not take the token. in http://bazaar.launchpad.net/+branch/goose

John Arbash Meinel john at arbash-meinel.com
Sun Nov 11 11:14:01 UTC 2012


At http://bazaar.launchpad.net/+branch/goose

------------------------------------------------------------
revno: 28
revision-id: john at arbash-meinel.com-20121111111352-7j0ilcvxf8v5y03n
parent: john at arbash-meinel.com-20121111110650-90l4cvq6gok0dy2c
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: goose
timestamp: Sun 2012-11-11 11:13:52 +0000
message:
  Change AddUser to not take the token.
  
  We will create it on the fly, though ideally we wouldn't create it until the user authed.
-------------- next part --------------
=== modified file 'identity/legacy_test.go'
--- a/identity/legacy_test.go	2012-11-02 10:59:29 +0000
+++ b/identity/legacy_test.go	2012-11-11 11:13:52 +0000
@@ -15,20 +15,20 @@
 func (s *LegacyTestSuite) TestAuthAgainstServer(c *C) {
 	service := identityservice.NewLegacy()
 	s.Mux.Handle("/", service)
-	service.AddUser("joe-user", "secrets", "active-token")
+	token := service.AddUser("joe-user", "secrets")
 	service.SetManagementURL("http://management/url")
 	var l Authenticator = &Legacy{}
 	creds := Credentials{User: "joe-user", URL: s.Server.URL, Secrets: "secrets"}
 	auth, err := l.Auth(creds)
 	c.Assert(err, IsNil)
-	c.Assert(auth.Token, Equals, "active-token")
+	c.Assert(auth.Token, Equals, token)
 	c.Assert(auth.ServiceURLs, DeepEquals, map[string]string{"compute": "http://management/url"})
 }
 
 func (s *LegacyTestSuite) TestBadAuth(c *C) {
 	service := identityservice.NewLegacy()
 	s.Mux.Handle("/", service)
-	service.AddUser("joe-user", "secrets", "active-token")
+	_ = service.AddUser("joe-user", "secrets")
 	var l Authenticator = &Legacy{}
 	creds := Credentials{User: "joe-user", URL: s.Server.URL, Secrets: "bad-secrets"}
 	auth, err := l.Auth(creds)

=== modified file 'identity/userpass_test.go'
--- a/identity/userpass_test.go	2012-11-02 10:59:29 +0000
+++ b/identity/userpass_test.go	2012-11-11 11:13:52 +0000
@@ -15,11 +15,11 @@
 func (s *UserPassTestSuite) TestAuthAgainstServer(c *C) {
 	service := identityservice.NewUserPass()
 	s.Mux.Handle("/", service)
-	service.AddUser("joe-user", "secrets", "active-token")
+	token := service.AddUser("joe-user", "secrets")
 	var l Authenticator = &UserPass{}
 	creds := Credentials{User: "joe-user", URL: s.Server.URL, Secrets: "secrets"}
 	auth, err := l.Auth(creds)
 	c.Assert(err, IsNil)
-	c.Assert(auth.Token, Equals, "active-token")
+	c.Assert(auth.Token, Equals, token)
 	// c.Assert(auth.ServiceURLs, DeepEquals, map[string]string{"compute": "http://management/url"})
 }

=== modified file 'testservices/identityservice/identityservice.go'
--- a/testservices/identityservice/identityservice.go	2012-11-01 12:02:04 +0000
+++ b/testservices/identityservice/identityservice.go	2012-11-11 11:13:52 +0000
@@ -5,6 +5,6 @@
 )
 
 type IdentityService interface {
-	AddUser(user, secret, token string)
+	AddUser(user, secret string) (token string)
 	ServeHTTP(w http.ResponseWriter, r *http.Request)
 }

=== modified file 'testservices/identityservice/legacy.go'
--- a/testservices/identityservice/legacy.go	2012-11-01 12:02:04 +0000
+++ b/testservices/identityservice/legacy.go	2012-11-11 11:13:52 +0000
@@ -24,8 +24,10 @@
 	lis.managementURL = URL
 }
 
-func (lis *Legacy) AddUser(user, secret, token string) {
+func (lis *Legacy) AddUser(user, secret string) string {
+	token := "new-secret-token"
 	lis.tokens[user] = UserInfo{secret: secret, token: token}
+	return token
 }
 
 func (lis *Legacy) ServeHTTP(w http.ResponseWriter, r *http.Request) {

=== modified file 'testservices/identityservice/legacy_test.go'
--- a/testservices/identityservice/legacy_test.go	2012-11-01 12:02:04 +0000
+++ b/testservices/identityservice/legacy_test.go	2012-11-11 11:13:52 +0000
@@ -20,9 +20,8 @@
 	var _ IdentityService = identity
 	identity.SetManagementURL(managementURL)
 	s.Mux.Handle("/", identity)
-	token = "new-special-token"
 	if user != "" {
-		identity.AddUser(user, secret, token)
+		token = identity.AddUser(user, secret)
 	}
 	return
 }

=== modified file 'testservices/identityservice/userpass.go'
--- a/testservices/identityservice/userpass.go	2012-11-01 15:44:16 +0000
+++ b/testservices/identityservice/userpass.go	2012-11-11 11:13:52 +0000
@@ -143,8 +143,10 @@
 	return userpass
 }
 
-func (u *UserPass) AddUser(user, secret, token string) {
+func (u *UserPass) AddUser(user, secret string) string {
+	token := "new-secret-token"
 	u.users[user] = UserInfo{secret: secret, token: token}
+	return token
 }
 
 var internalError = []byte(`{

=== modified file 'testservices/identityservice/userpass_test.go'
--- a/testservices/identityservice/userpass_test.go	2012-11-11 11:06:50 +0000
+++ b/testservices/identityservice/userpass_test.go	2012-11-11 11:13:52 +0000
@@ -21,9 +21,8 @@
 	// Ensure that it conforms to the interface
 	var _ IdentityService = identity
 	s.Mux.Handle("/", identity)
-	token = "new-special-token"
 	if user != "" {
-		identity.AddUser(user, secret, token)
+		token = identity.AddUser(user, secret)
 	}
 	return
 }

=== modified file 'testservices/main.go'
--- a/testservices/main.go	2012-11-02 09:43:37 +0000
+++ b/testservices/main.go	2012-11-11 11:13:52 +0000
@@ -10,7 +10,7 @@
 )
 
 type userInfo struct {
-	user, secret, token string
+	user, secret string
 }
 type userValues struct {
 	users []userInfo
@@ -18,13 +18,12 @@
 
 func (uv *userValues) Set(s string) error {
 	vals := strings.Split(s, ":")
-	if len(vals) != 3 {
-		return fmt.Errorf("Invalid --user option, should be: user:secret:token")
+	if len(vals) != 2 {
+		return fmt.Errorf("Invalid --user option, should be: user:secret")
 	}
 	uv.users = append(uv.users, userInfo{
 		user:   vals[0],
 		secret: vals[1],
-		token:  vals[2],
 	})
 	return nil
 }
@@ -64,7 +63,7 @@
 	}
 	http.Handle("/", p)
 	for _, u := range users.users {
-		p.AddUser(u.user, u.secret, u.token)
+		p.AddUser(u.user, u.secret)
 	}
 	log.Fatal(http.ListenAndServe(*serveAddr, nil))
 }



More information about the bazaar-commits mailing list