diff --git a/test/integration/default/controls/_mapdata_spec.rb b/test/integration/default/controls/_mapdata_spec.rb index fccc087..79c3ca8 100644 --- a/test/integration/default/controls/_mapdata_spec.rb +++ b/test/integration/default/controls/_mapdata_spec.rb @@ -1,12 +1,7 @@ # frozen_string_literal: true -# Replace per minion strings -replacement = { - hostname: system.hostname -} - mapdata_file = "_mapdata/#{system.platform[:finger].split('.').first}.yaml" -mapdata_dump = inspec.profile.file(mapdata_file) % replacement +mapdata_dump = inspec.profile.file(mapdata_file) control '`map.jinja` YAML dump' do title 'should contain the lines' diff --git a/test/integration/default/files/_mapdata/amazonlinux-1.yaml b/test/integration/default/files/_mapdata/amazonlinux-1.yaml index 1b66e6c..7566157 100644 --- a/test/integration/default/files/_mapdata/amazonlinux-1.yaml +++ b/test/integration/default/files/_mapdata/amazonlinux-1.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-clients client_version: latest diff --git a/test/integration/default/files/_mapdata/amazonlinux-2.yaml b/test/integration/default/files/_mapdata/amazonlinux-2.yaml index 27b3886..ff39b52 100644 --- a/test/integration/default/files/_mapdata/amazonlinux-2.yaml +++ b/test/integration/default/files/_mapdata/amazonlinux-2.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-clients client_version: latest diff --git a/test/integration/default/files/_mapdata/arch-base-latest.yaml b/test/integration/default/files/_mapdata/arch-base-latest.yaml index 42f2a2b..90d1d26 100644 --- a/test/integration/default/files/_mapdata/arch-base-latest.yaml +++ b/test/integration/default/files/_mapdata/arch-base-latest.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh client_version: latest diff --git a/test/integration/default/files/_mapdata/centos-6.yaml b/test/integration/default/files/_mapdata/centos-6.yaml index e648559..4c05c6b 100644 --- a/test/integration/default/files/_mapdata/centos-6.yaml +++ b/test/integration/default/files/_mapdata/centos-6.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-clients client_version: latest diff --git a/test/integration/default/files/_mapdata/centos-7.yaml b/test/integration/default/files/_mapdata/centos-7.yaml index 9b1349c..9e37cb8 100644 --- a/test/integration/default/files/_mapdata/centos-7.yaml +++ b/test/integration/default/files/_mapdata/centos-7.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-clients client_version: latest diff --git a/test/integration/default/files/_mapdata/centos-8.yaml b/test/integration/default/files/_mapdata/centos-8.yaml index fd1180f..c0e6c76 100644 --- a/test/integration/default/files/_mapdata/centos-8.yaml +++ b/test/integration/default/files/_mapdata/centos-8.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-clients client_version: latest diff --git a/test/integration/default/files/_mapdata/debian-10.yaml b/test/integration/default/files/_mapdata/debian-10.yaml index 4bb86c2..c6c148f 100644 --- a/test/integration/default/files/_mapdata/debian-10.yaml +++ b/test/integration/default/files/_mapdata/debian-10.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-client client_version: latest diff --git a/test/integration/default/files/_mapdata/debian-9.yaml b/test/integration/default/files/_mapdata/debian-9.yaml index 7acf08d..6a4436c 100644 --- a/test/integration/default/files/_mapdata/debian-9.yaml +++ b/test/integration/default/files/_mapdata/debian-9.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-client client_version: latest diff --git a/test/integration/default/files/_mapdata/fedora-31.yaml b/test/integration/default/files/_mapdata/fedora-31.yaml index 2b55a0d..b61b597 100644 --- a/test/integration/default/files/_mapdata/fedora-31.yaml +++ b/test/integration/default/files/_mapdata/fedora-31.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-clients client_version: latest diff --git a/test/integration/default/files/_mapdata/fedora-32.yaml b/test/integration/default/files/_mapdata/fedora-32.yaml index 8f28bd0..1981214 100644 --- a/test/integration/default/files/_mapdata/fedora-32.yaml +++ b/test/integration/default/files/_mapdata/fedora-32.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-clients client_version: latest diff --git a/test/integration/default/files/_mapdata/opensuse-15.yaml b/test/integration/default/files/_mapdata/opensuse-15.yaml index ea9b47e..fc1eddc 100644 --- a/test/integration/default/files/_mapdata/opensuse-15.yaml +++ b/test/integration/default/files/_mapdata/opensuse-15.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh client_version: latest diff --git a/test/integration/default/files/_mapdata/ubuntu-16.yaml b/test/integration/default/files/_mapdata/ubuntu-16.yaml index 77c3f06..ebf0904 100644 --- a/test/integration/default/files/_mapdata/ubuntu-16.yaml +++ b/test/integration/default/files/_mapdata/ubuntu-16.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-client client_version: latest diff --git a/test/integration/default/files/_mapdata/ubuntu-18.yaml b/test/integration/default/files/_mapdata/ubuntu-18.yaml index f684641..d560513 100644 --- a/test/integration/default/files/_mapdata/ubuntu-18.yaml +++ b/test/integration/default/files/_mapdata/ubuntu-18.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-client client_version: latest diff --git a/test/integration/default/files/_mapdata/ubuntu-20.yaml b/test/integration/default/files/_mapdata/ubuntu-20.yaml index 4c31070..2bf6e3e 100644 --- a/test/integration/default/files/_mapdata/ubuntu-20.yaml +++ b/test/integration/default/files/_mapdata/ubuntu-20.yaml @@ -42,7 +42,7 @@ openssh: present: false banner: /etc/ssh/banner banner_src: banner - banner_string: 'Welcome to %{hostname}! + banner_string: 'Welcome to example.net! ' client: openssh-client client_version: latest diff --git a/test/integration/share/README.md b/test/integration/share/README.md index 80e0fb2..5c5ef9c 100644 --- a/test/integration/share/README.md +++ b/test/integration/share/README.md @@ -10,7 +10,6 @@ It's goal is to share the libraries between all profiles. The `system` library provides easy access to system dependents informations: -- `system.hostname`: return the result of `hostname -s` or `hostnamectl --static` based on the availability of each commans - `system.platform`: take `inspec.platform` and mangle things a bit to be useful - `system.platform[:family]` provides a family name for Arch - `system.platform[:name]` modify `amazon` to `amazonlinux` diff --git a/test/integration/share/libraries/system.rb b/test/integration/share/libraries/system.rb index 3c6304c..ebd32b3 100644 --- a/test/integration/share/libraries/system.rb +++ b/test/integration/share/libraries/system.rb @@ -4,47 +4,17 @@ # Author: Daniel Dehennin # Copyright (C) 2020 Daniel Dehennin -HOSTNAME_CMDS = %w[hostname hostnamectl].freeze -HOSTNAME_CMDS_OPT = { - 'hostname' => '-s', - 'hostnamectl' => '--static' -}.freeze - class SystemResource < Inspec.resource(1) name 'system' attr_reader :platform - attr_reader :hostname def initialize @platform = build_platform - @hostname = found_hostname end private - def found_hostname - cmd = guess_hostname_cmd - - unless cmd.exit_status.zero? - raise Inspec::Exceptions::ResourceSkipped, - "Error running '#{cmd}': #{cmd.stderr}" - end - - cmd.stdout.chomp - end - - def guess_hostname_cmd - HOSTNAME_CMDS.each do |cmd| - if inspec.command(cmd).exist? - return inspec.command("#{cmd} #{HOSTNAME_CMDS_OPT[cmd]}") - end - end - - raise Inspec::Exceptions::ResourceSkipped, - "Error: #{@platform[:finger]}} has none of #{HOSTNAME_CMDS.join(', ')}" - end - def build_platform { family: build_platform_family,