예제 #1
0
func TestGroupCreation(t *testing.T) {
	Convey("Given a group object and an executor", t, func() {
		user := identity.Group{
			Name:         "newGroup",
			PasswordHash: "PHASH",
			GID:          "1002",
		}

		exec := sys.NewMockExecutor()

		idmgr := identity.NewManager(exec)

		Convey("It should create a new group in the system", func() {
			exec.OutStr <- ""
			exec.OutErr <- nil

			err := idmgr.CreateGroup(user)

			So(<-exec.Exec, ShouldEqual, "groupadd")
			So(<-exec.Args, ShouldSetEqual, []string{"newGroup", "--password=PHASH", "--gid=1002"})

			So(err, ShouldEqual, nil)
		})
	})
}
예제 #2
0
func TestGroupSetPassword(t *testing.T) {
	Convey("Given a group name and a password hash and an executor", t, func() {
		gname, phash := "existentGroup", "PASSWORD_HASH"

		exec := sys.NewMockExecutor()

		idmgr := identity.NewManager(exec)

		Convey("It should change the password of the group", func() {
			exec.OutStr <- ""
			exec.OutErr <- nil

			err := idmgr.SetGroupPassword(gname, phash)

			So(<-exec.Exec, ShouldEqual, "groupmod")
			So(<-exec.Args, ShouldSetEqual, []string{"existentGroup", "--password=PASSWORD_HASH"})

			So(err, ShouldEqual, nil)
		})
	})
}
예제 #3
0
func TestUserSetPassword(t *testing.T) {
	Convey("Given a user name and a password hash and an executor", t, func() {
		uname, phash := "existentUser", "PASSWORD_HASH"

		exec := sys.NewMockExecutor()

		idmgr := identity.NewManager(exec)

		Convey("It should change the password of the user", func() {
			exec.OutStr <- ""
			exec.OutErr <- nil

			err := idmgr.SetUserPassword(uname, phash)

			So(<-exec.Exec, ShouldEqual, "chpasswd")
			So(<-exec.Args, ShouldSetEqual, []string{"-e", "existentUser:PASSWORD_HASH"})

			So(err, ShouldEqual, nil)
		})
	})
}