Example #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)
		})
	})
}
Example #2
0
// CentOS returns the distribution implementation of CentOS
// operating system that uses the given sys.Executor.
func CentOS(exec sys.Executor) ContextConsumer {
	return &Implementation{
		Executor: exec,

		ID:       identity.NewManager(exec),
		NSS:      &nss.Server{exec},
		Firewall: &iptables.Implementation{exec},
		//FileSystem: &file.System{exec},
		//Sysconf: conf.Manager hostname, timedate, etc. sysctl for CentOS
		Initd: &systemd.Implementation{
			UnitDir: "/etc/systemd/userexec",
			Exec:    exec,
		},
	}
}
Example #3
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)
		})
	})
}
Example #4
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)
		})
	})
}