Merge pull request #845 from harshavardhana/add-missing

Add missing reply.Name and add possible failure tests
master
Harshavardhana 9 years ago
commit 7a61447ce5
  1. 4
      pkg/controller/rpc/auth.go
  2. 29
      pkg/controller/rpc_test.go

@ -68,6 +68,8 @@ func generateAuth(args *AuthArgs, reply *AuthReply) *probe.Error {
return err.Trace() return err.Trace()
} }
reply.SecretAccessKey = string(secretAccessKey) reply.SecretAccessKey = string(secretAccessKey)
reply.Name = args.User
config.Users[args.User] = &auth.User{ config.Users[args.User] = &auth.User{
Name: args.User, Name: args.User,
AccessKeyID: string(accessKeyID), AccessKeyID: string(accessKeyID),
@ -90,6 +92,7 @@ func fetchAuth(args *AuthArgs, reply *AuthReply) *probe.Error {
} }
reply.AccessKeyID = config.Users[args.User].AccessKeyID reply.AccessKeyID = config.Users[args.User].AccessKeyID
reply.SecretAccessKey = config.Users[args.User].SecretAccessKey reply.SecretAccessKey = config.Users[args.User].SecretAccessKey
reply.Name = args.User
return nil return nil
} }
@ -112,6 +115,7 @@ func resetAuth(args *AuthArgs, reply *AuthReply) *probe.Error {
return err.Trace() return err.Trace()
} }
reply.SecretAccessKey = string(secretAccessKey) reply.SecretAccessKey = string(secretAccessKey)
reply.Name = args.User
config.Users[args.User] = &auth.User{ config.Users[args.User] = &auth.User{
Name: args.User, Name: args.User,

@ -104,6 +104,7 @@ func (s *MySuite) TestAuth(c *C) {
c.Assert(reply, Not(DeepEquals), rpc.AuthReply{}) c.Assert(reply, Not(DeepEquals), rpc.AuthReply{})
c.Assert(len(reply.AccessKeyID), Equals, 20) c.Assert(len(reply.AccessKeyID), Equals, 20)
c.Assert(len(reply.SecretAccessKey), Equals, 40) c.Assert(len(reply.SecretAccessKey), Equals, 40)
c.Assert(len(reply.Name), Not(Equals), 0)
op = rpc.Operation{ op = rpc.Operation{
Method: "Auth.Fetch", Method: "Auth.Fetch",
@ -122,6 +123,7 @@ func (s *MySuite) TestAuth(c *C) {
c.Assert(newReply, Not(DeepEquals), rpc.AuthReply{}) c.Assert(newReply, Not(DeepEquals), rpc.AuthReply{})
c.Assert(reply.AccessKeyID, Equals, newReply.AccessKeyID) c.Assert(reply.AccessKeyID, Equals, newReply.AccessKeyID)
c.Assert(reply.SecretAccessKey, Equals, newReply.SecretAccessKey) c.Assert(reply.SecretAccessKey, Equals, newReply.SecretAccessKey)
c.Assert(len(reply.Name), Not(Equals), 0)
op = rpc.Operation{ op = rpc.Operation{
Method: "Auth.Reset", Method: "Auth.Reset",
@ -140,4 +142,31 @@ func (s *MySuite) TestAuth(c *C) {
c.Assert(newReply, Not(DeepEquals), rpc.AuthReply{}) c.Assert(newReply, Not(DeepEquals), rpc.AuthReply{})
c.Assert(reply.AccessKeyID, Not(Equals), resetReply.AccessKeyID) c.Assert(reply.AccessKeyID, Not(Equals), resetReply.AccessKeyID)
c.Assert(reply.SecretAccessKey, Not(Equals), resetReply.SecretAccessKey) c.Assert(reply.SecretAccessKey, Not(Equals), resetReply.SecretAccessKey)
c.Assert(len(reply.Name), Not(Equals), 0)
// these operations should fail
/// generating access for existing user fails
op = rpc.Operation{
Method: "Auth.Generate",
Request: rpc.AuthArgs{User: "newuser"},
}
req, err = rpc.NewRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusBadRequest)
/// null user provided invalid
op = rpc.Operation{
Method: "Auth.Generate",
Request: rpc.AuthArgs{User: ""},
}
req, err = rpc.NewRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
c.Assert(err, IsNil)
c.Assert(req.Get("Content-Type"), Equals, "application/json")
resp, err = req.Do()
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusBadRequest)
} }

Loading…
Cancel
Save