<commit_before># Check for critical packages
['cron-apt', 'ntp'].each do |pkg|
  describe package(pkg) do
    it { should be_installed }
  end
end

# ensure custom cron-apt config file is present
describe file('/etc/cron-apt/config') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  its(:content) { should match /^SYSLOGON="always"$/ }
  its(:content) { should match /^EXITON=error$/ }
end

# list desired security repositories
security_repositories = [
  'deb http://security.ubuntu.com/ubuntu trusty-security main',
  'deb-src http://security.ubuntu.com/ubuntu trusty-security main',
  'deb http://security.ubuntu.com/ubuntu trusty-security universe',
  'deb-src http://security.ubuntu.com/ubuntu trusty-security universe',
  'deb [arch=amd64] https://apt.freedom.press trusty main',
  'deb http://deb.torproject.org/torproject.org trusty main',
]
# ensure custom security.list file is present
describe file('/etc/apt/security.list') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  security_repositories.each do |repo|
    repo_regex = Regexp.quote(repo)
    its(:content) { should match /^#{repo_regex}$/ }
  end
end

# ensure cron-apt updates the security.list packages
describe file('/etc/cron-apt/action.d/0-update') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  repo_regex = Regexp.quote('update -o quiet=2 -o Dir::Etc::SourceList=/etc/apt/security.list -o Dir::Etc::SourceParts=""')
  its(:content) { should match /^#{repo_regex}$/ }
end

# ensure cron-apt upgrades the security.list packages
describe file('/etc/cron-apt/action.d/5-security') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  its(:content) { should match /^autoclean -y$/ }
  config_regex = Regexp.quote('dist-upgrade -y -o APT::Get::Show-Upgraded=true -o Dir::Etc::SourceList=/etc/apt/security.list -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold')
  its(:content) { should match /^#{config_regex}$/ }
  its(:content) { should match /^autoremove -y$/ }
end

# ensure default cron-apt file to download all updates does not exist
describe file('/etc/cron-apt/action.d/3-download') do
  it { should_not exist }
end

desired_cronjobs = [
  '0 4 * * * root    /usr/bin/test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt',
  '0 5 * * * root    /sbin/reboot',
]
# ensure the cron.d config for cron-apt exists
describe file('/etc/cron.d/cron-apt') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  desired_cronjobs.each do |cronjob|
    cronjob_regex = Regexp.quote(cronjob)
    its(:content) { should match /^#{cronjob_regex}$/ }<commit_msg>Updates tests for cron-apt reboot timing.<commit_after># Check for critical packages
['cron-apt', 'ntp'].each do |pkg|
  describe package(pkg) do
    it { should be_installed }
  end
end

# ensure custom cron-apt config file is present
describe file('/etc/cron-apt/config') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  its(:content) { should match /^SYSLOGON="always"$/ }
  its(:content) { should match /^EXITON=error$/ }
end

# list desired security repositories
security_repositories = [
  'deb http://security.ubuntu.com/ubuntu trusty-security main',
  'deb-src http://security.ubuntu.com/ubuntu trusty-security main',
  'deb http://security.ubuntu.com/ubuntu trusty-security universe',
  'deb-src http://security.ubuntu.com/ubuntu trusty-security universe',
  'deb [arch=amd64] https://apt.freedom.press trusty main',
  'deb http://deb.torproject.org/torproject.org trusty main',
]
# ensure custom security.list file is present
describe file('/etc/apt/security.list') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  security_repositories.each do |repo|
    repo_regex = Regexp.quote(repo)
    its(:content) { should match /^#{repo_regex}$/ }
  end
end

# ensure cron-apt updates the security.list packages
describe file('/etc/cron-apt/action.d/0-update') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  repo_regex = Regexp.quote('update -o quiet=2 -o Dir::Etc::SourceList=/etc/apt/security.list -o Dir::Etc::SourceParts=""')
  its(:content) { should match /^#{repo_regex}$/ }
end

# ensure cron-apt upgrades the security.list packages
describe file('/etc/cron-apt/action.d/5-security') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  its(:content) { should match /^autoclean -y$/ }
  config_regex = Regexp.quote('dist-upgrade -y -o APT::Get::Show-Upgraded=true -o Dir::Etc::SourceList=/etc/apt/security.list -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold')
  its(:content) { should match /^#{config_regex}$/ }
  its(:content) { should match /^autoremove -y$/ }
end

# ensure default cron-apt file to download all updates does not exist
describe file('/etc/cron-apt/action.d/3-download') do
  it { should_not exist }
end

desired_cronjobs = [
  '0 4 * * * root    /usr/bin/test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt && /sbin/reboot'
]
# Checking for old cronjobs to guard against regressions.
unwanted_cronjobs = [
  '0 4 * * * root    /usr/bin/test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt',
  '0 5 * * * root    /sbin/reboot',
]
# ensure the cron.d config for cron-apt exists
describe file('/etc/cron.d/cron-apt') do
  it { should be_file }
  it { should be_owned_by  'root' }
  it { should be_mode '644' }
  desired_cronjobs.each do |cronjob|
    cronjob_regex = Regexp.quote(cronjob)
    its(:content) { should match /^#{cronjob_regex}$/ }
  end
  unwanted_cronjobs.each do |cronjob|
    cronjob_regex = Regexp.quote(cronjob)
    its(:content) { should_not match /^#{cronjob_regex}$/ }
{'fraction_non_alphanumeric': 0.14954066008846548, 'fraction_numerical': 0.008846546444368834, 'mean_word_length': 3.7757920389926887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6425237', 'n_tokens_mistral': 2209, 'n_tokens_neox': 2088, 'n_words': 526}