Example #1
0
func (s *userManagerSuite) TestUserInfo(c *gc.C) {
	userFoo := s.Factory.MakeUser(c, &factory.UserParams{Name: "foobar", DisplayName: "Foo Bar"})
	userBar := s.Factory.MakeUser(c, &factory.UserParams{Name: "barfoo", DisplayName: "Bar Foo", Disabled: true})
	err := controller.ChangeControllerAccess(
		s.State, s.AdminUserTag(c), names.NewUserTag("fred@external"),
		params.GrantControllerAccess, permission.AddModelAccess)
	c.Assert(err, jc.ErrorIsNil)

	args := params.UserInfoRequest{
		Entities: []params.Entity{
			{
				Tag: userFoo.Tag().String(),
			}, {
				Tag: userBar.Tag().String(),
			}, {
				Tag: names.NewLocalUserTag("ellie").String(),
			}, {
				Tag: names.NewUserTag("fred@external").String(),
			}, {
				Tag: "not-a-tag",
			},
		}}

	results, err := s.usermanager.UserInfo(args)
	c.Assert(err, jc.ErrorIsNil)
	var expected params.UserInfoResults
	for _, r := range []struct {
		user *state.User
		info *params.UserInfo
		err  *params.Error
	}{
		{
			user: userFoo,
			info: &params.UserInfo{
				Username:    "******",
				DisplayName: "Foo Bar",
				Access:      "login",
			},
		}, {
			user: userBar,
			info: &params.UserInfo{
				Username:    "******",
				DisplayName: "Bar Foo",
				Access:      "login",
				Disabled:    true,
			},
		}, {
			err: &params.Error{
				Message: "permission denied",
				Code:    params.CodeUnauthorized,
			},
		}, {
			info: &params.UserInfo{
				Username: "******",
				Access:   "addmodel",
			},
		}, {
			err: &params.Error{
				Message: `"not-a-tag" is not a valid tag`,
			},
		},
	} {
		if r.info != nil {
			if names.NewUserTag(r.info.Username).IsLocal() {
				r.info.DateCreated = r.user.DateCreated()
				r.info.LastConnection = lastLoginPointer(c, r.user)
				r.info.CreatedBy = s.adminName
			}
		}
		expected.Results = append(expected.Results, params.UserInfoResult{Result: r.info, Error: r.err})
	}

	c.Assert(results, jc.DeepEquals, expected)
}
Example #2
0
func setEveryoneAccess(c *gc.C, st *state.State, adminUser names.UserTag, access permission.Access) {
	err := controller.ChangeControllerAccess(
		st, adminUser, names.NewUserTag(common.EveryoneTagName),
		params.GrantControllerAccess, access)
	c.Assert(err, jc.ErrorIsNil)
}