Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/osbuild: add ExpireDate to users #513

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/blueprint/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type UserCustomization struct {
Groups []string `json:"groups,omitempty" toml:"groups,omitempty"`
UID *int `json:"uid,omitempty" toml:"uid,omitempty"`
GID *int `json:"gid,omitempty" toml:"gid,omitempty"`
ExpireDate *int `json:"expiredate,omitempty" toml:"expiredate,omitempty"`
}

type GroupCustomization struct {
Expand Down
39 changes: 10 additions & 29 deletions pkg/blueprint/customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestCheckAllowed(t *testing.T) {
GID := 321

expectedUsers := []UserCustomization{
UserCustomization{
{
Name: "John",
Description: &Desc,
Password: &Pass,
Expand All @@ -32,7 +32,7 @@ func TestCheckAllowed(t *testing.T) {
},
}

var expectedHostname = "Hostname"
expectedHostname := "Hostname"

x := Customizations{Hostname: &expectedHostname, User: expectedUsers}

Expand All @@ -49,20 +49,17 @@ func TestCheckAllowed(t *testing.T) {
}

func TestGetHostname(t *testing.T) {

var expectedHostname = "Hostname"
expectedHostname := "Hostname"

TestCustomizations := Customizations{
Hostname: &expectedHostname,
}

retHostname := TestCustomizations.GetHostname()
assert.Equal(t, &expectedHostname, retHostname)

}

func TestGetKernel(t *testing.T) {

expectedKernel := KernelCustomization{
Append: "--test",
Name: "kernel",
Expand All @@ -78,9 +75,8 @@ func TestGetKernel(t *testing.T) {
}

func TestSSHKey(t *testing.T) {

expectedSSHKeys := []SSHKeyCustomization{
SSHKeyCustomization{
{
User: "test-user",
Key: "test-key",
},
Expand All @@ -94,11 +90,9 @@ func TestSSHKey(t *testing.T) {

assert.Equal(t, expectedSSHKeys[0].User, retUser)
assert.Equal(t, expectedSSHKeys[0].Key, retKey)

}

func TestGetUsers(t *testing.T) {

Desc := "Test descritpion"
Pass := "testpass"
Key := "testkey"
Expand All @@ -109,9 +103,10 @@ func TestGetUsers(t *testing.T) {
}
UID := 123
GID := 321
ExpireDate := 12345

expectedUsers := []UserCustomization{
UserCustomization{
{
Name: "John",
Description: &Desc,
Password: &Pass,
Expand All @@ -121,6 +116,7 @@ func TestGetUsers(t *testing.T) {
Groups: Groups,
UID: &UID,
GID: &GID,
ExpireDate: &ExpireDate,
},
}

Expand All @@ -134,10 +130,9 @@ func TestGetUsers(t *testing.T) {
}

func TestGetGroups(t *testing.T) {

GID := 1234
expectedGroups := []GroupCustomization{
GroupCustomization{
{
Name: "TestGroup",
GID: &GID,
},
Expand All @@ -153,7 +148,6 @@ func TestGetGroups(t *testing.T) {
}

func TestGetTimezoneSettings(t *testing.T) {

expectedTimezone := "testZONE"
expectedNTPServers := []string{
"server",
Expand All @@ -172,11 +166,9 @@ func TestGetTimezoneSettings(t *testing.T) {

assert.Equal(t, expectedTimezone, *retTimezone)
assert.Equal(t, expectedNTPServers, retNTPServers)

}

func TestGetPrimaryLocale(t *testing.T) {

expectedLanguages := []string{
"enUS",
}
Expand All @@ -198,7 +190,6 @@ func TestGetPrimaryLocale(t *testing.T) {
}

func TestGetFirewall(t *testing.T) {

expectedPorts := []string{"22", "9090"}

expectedServices := FirewallServicesCustomization{
Expand All @@ -223,7 +214,6 @@ func TestGetFirewall(t *testing.T) {
}

func TestGetServices(t *testing.T) {

expectedServices := ServicesCustomization{
Enabled: []string{"cockpit", "osbuild-composer"},
Disabled: []string{"sshd", "ftp"},
Expand All @@ -249,12 +239,10 @@ func TestError(t *testing.T) {
retError := expectedError.Error()

assert.Equal(t, expectedError.Message, retError)

}

// This tests calling all the functions on a Blueprint with no Customizations
func TestNoCustomizationsInBlueprint(t *testing.T) {

TestBP := Blueprint{}

assert.Nil(t, TestBP.Customizations.GetHostname())
Expand All @@ -275,16 +263,15 @@ func TestNoCustomizationsInBlueprint(t *testing.T) {

// This tests additional scenarios where GetPrimaryLocale() returns nil values
func TestNilGetPrimaryLocale(t *testing.T) {

//Case empty Customization
// Case empty Customization
TestCustomizationsEmpty := Customizations{}

retLanguage, retKeyboard := TestCustomizationsEmpty.GetPrimaryLocale()

assert.Nil(t, retLanguage)
assert.Nil(t, retKeyboard)

//Case empty Languages
// Case empty Languages
expectedKeyboard := "en"
expectedLocaleCustomization := LocaleCustomization{
Keyboard: &expectedKeyboard,
Expand All @@ -298,12 +285,10 @@ func TestNilGetPrimaryLocale(t *testing.T) {

assert.Nil(t, retLanguage)
assert.Equal(t, expectedKeyboard, *retKeyboard)

}

// This tests additional scenario where GetTimezoneSEtting() returns nil values
func TestNilGetTimezoneSettings(t *testing.T) {

TestCustomizationsEmpty := Customizations{}

retTimezone, retNTPServers := TestCustomizationsEmpty.GetTimezoneSettings()
Expand All @@ -313,7 +298,6 @@ func TestNilGetTimezoneSettings(t *testing.T) {
}

func TestGetFilesystems(t *testing.T) {

expectedFilesystems := []FilesystemCustomization{
{
MinSize: 1024,
Expand All @@ -331,7 +315,6 @@ func TestGetFilesystems(t *testing.T) {
}

func TestGetFilesystemsMinSize(t *testing.T) {

expectedFilesystems := []FilesystemCustomization{
{
MinSize: 1024,
Expand All @@ -353,7 +336,6 @@ func TestGetFilesystemsMinSize(t *testing.T) {
}

func TestGetFilesystemsMinSizeNonSectorSize(t *testing.T) {

expectedFilesystems := []FilesystemCustomization{
{
MinSize: 1025,
Expand All @@ -375,7 +357,6 @@ func TestGetFilesystemsMinSizeNonSectorSize(t *testing.T) {
}

func TestGetOpenSCAPConfig(t *testing.T) {

expectedOscap := OpenSCAPCustomization{
DataStream: "test-data-stream.xml",
ProfileID: "test_profile",
Expand Down
1 change: 1 addition & 0 deletions pkg/customizations/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type User struct {
Groups []string
UID *int
GID *int
ExpireDate *int
}

type Group struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/osbuild/users_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type UsersStageOptionsUser struct {
Shell *string `json:"shell,omitempty"`
Password *string `json:"password,omitempty"`
Key *string `json:"key,omitempty"`
ExpireDate *int `json:"expiredate,omitempty"`
}

func NewUsersStage(options *UsersStageOptions) *Stage {
Expand Down Expand Up @@ -60,6 +61,7 @@ func NewUsersStageOptions(userCustomizations []users.User, omitKey bool) (*Users
Shell: uc.Shell,
Password: uc.Password,
Key: nil,
ExpireDate: uc.ExpireDate,
}
if !omitKey {
user.Key = uc.Key
Expand Down
Loading