Skip to content

Commit

Permalink
Dump apt config from apt rather than parsing selected config files (#986
Browse files Browse the repository at this point in the history
)
  • Loading branch information
a-crate authored Dec 14, 2023
1 parent 9a6977d commit 56542b2
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions imagetest/test_suites/security/image_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,11 @@ func verifyServiceEnabled(image string) error {
}

func verifyAutomaticUpdate(image string) error {
automaticUpdateConfig, err := readAPTConfig(image)
output, err := exec.Command("apt-config", "dump").Output()
if err != nil {
return err
}
automaticUpdateConfig := string(output)
switch {
case strings.Contains(image, "debian-9"):
if !strings.Contains(automaticUpdateConfig, `APT::Periodic::Enable "1";`) {
Expand Down Expand Up @@ -306,25 +307,6 @@ func verifyAutomaticUpdate(image string) error {
return nil
}

func readAPTConfig(image string) (string, error) {
var configPaths []string
var b []byte
configPaths = append(configPaths, "/etc/apt/apt.conf.d/20auto-upgrades")
if strings.Contains(image, "debian-9") {
configPaths = append(configPaths, "/etc/apt/apt.conf.d/02periodic")
} else if strings.Contains(image, "ubuntu") {
configPaths = append(configPaths, "/etc/apt/apt.conf.d/10periodic")
}
for _, path := range configPaths {
newByte, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
b = append(b, newByte...)
}
return string(b), nil
}

// sysctlGet returns a sysctl from a given key.
func sysctlGet(key string) (string, error) {
path := filepath.Join(sysctlBase, strings.Replace(key, ".", "/", -1))
Expand Down

0 comments on commit 56542b2

Please sign in to comment.