Example #1
0
func Test_getNewIdentity_DifferentGroup(t *testing.T) {
	p := userinfo.MakeFakeProvider(501, 20, users, groups)

	uid, gid, warning := getNewIdentity(p, "", "wheel")

	assert.Equal(t, uint32(501), uid)
	assert.Equal(t, uint32(0), gid)
	assert.NoError(t, warning)
}
Example #2
0
func Test_getNewIdentity_DifferentUserId_WithExplicitGroup(t *testing.T) {
	p := userinfo.MakeFakeProvider(501, 20, users, groups)

	uid, gid, warning := getNewIdentity(p, "502", "20")

	assert.Equal(t, uint32(502), uid)
	assert.Equal(t, uint32(20), gid)
	assert.NoError(t, warning)
}
Example #3
0
func Test_getNewIdentity_CurrentUser_NoGroup(t *testing.T) {
	p := userinfo.MakeFakeProvider(501, 20, users, groups)

	uid, gid, warning := getNewIdentity(p, "user", "")

	assert.Equal(t, uint32(501), uid)
	assert.Equal(t, uint32(20), gid)
	assert.NoError(t, warning)
}
Example #4
0
func Test_getNewIdentity_UnknownGroupname(t *testing.T) {
	p := userinfo.MakeFakeProvider(501, 20, users, groups)

	uid, gid, warning := getNewIdentity(p, "", "nagios")

	assert.Equal(t, uint32(501), uid)
	assert.Equal(t, uint32(20), gid)
	if assert.Error(t, warning) {
		assert.Equal(t, `can't look up group "nagios": No group matching groupname: "nagios"`, warning.Error())
	}
}
Example #5
0
func Test_getNewIdentity_UnknownUserName(t *testing.T) {
	p := userinfo.MakeFakeProvider(501, 20, users, groups)

	uid, gid, warning := getNewIdentity(p, "banana", "")

	assert.Equal(t, uint32(501), uid)
	assert.Equal(t, uint32(20), gid)
	if assert.Error(t, warning) {
		assert.Equal(t, `can't look up user "banana": No user matching username: "******"`, warning.Error())
	}
}
Example #6
0
// This should never happen, but with one API using strings and another
// using numbers I feel like I should check it out, anyway.
func Test_getNewIdentity_BadKnownUserId(t *testing.T) {
	u := &user.User{
		Username: "******",
		Uid:      "4294967296",
		Gid:      "20",
	}
	p := userinfo.MakeFakeProvider(501, 20, userinfo.Users(user501, u), groups)

	uid, gid, warning := getNewIdentity(p, "4294967296", "")

	assert.Equal(t, uint32(501), uid)
	assert.Equal(t, uint32(20), gid)
	if assert.Error(t, warning) {
		assert.Equal(t, `bad retrieved Uid: strconv.ParseUint: parsing "4294967296": value out of range`, warning.Error())
	}
}