2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/interface"
|
2015-10-08 10:11:55 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Interface" do
|
2015-10-08 10:11:55 +00:00
|
|
|
|
|
|
|
# ubuntu 14.04
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify interface on ubuntu" do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource("interface", "eth0")
|
2015-10-08 10:11:55 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.up?).must_equal true
|
|
|
|
_(resource.speed).must_equal 10000
|
2019-10-03 07:23:17 +00:00
|
|
|
_(resource.name).must_equal "eth0"
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.ipv4_cidrs).must_include "127.0.0.1/8"
|
2020-06-05 17:48:41 +00:00
|
|
|
_(resource.ipv4_address).must_equal "127.0.0.1"
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.ipv4_addresses).must_include "127.0.0.1"
|
|
|
|
_(resource.ipv4_addresses_netmask).must_include "127.0.0.1/255.0.0.0"
|
|
|
|
_(resource.ipv6_cidrs).must_include "::1/128"
|
2020-06-05 17:48:41 +00:00
|
|
|
_(resource.ipv6_address).must_equal "::1"
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.ipv6_addresses).must_include "::1"
|
2019-03-18 22:53:51 +00:00
|
|
|
_(resource.ipv4_address?).must_equal true
|
|
|
|
_(resource.ipv6_address?).must_equal true
|
2015-10-08 10:11:55 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify invalid interface on ubuntu" do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource("interface", "eth1")
|
2015-10-08 10:11:55 +00:00
|
|
|
_(resource.exists?).must_equal false
|
|
|
|
_(resource.up?).must_equal false
|
2019-10-03 07:23:17 +00:00
|
|
|
_(resource.name).must_be_nil
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.speed).must_be_nil
|
2019-03-18 22:53:51 +00:00
|
|
|
_(resource.ipv4_cidrs).must_be_empty
|
2020-05-19 03:42:25 +00:00
|
|
|
_(resource.ipv4_address).must_be_nil
|
2019-03-18 22:53:51 +00:00
|
|
|
_(resource.ipv4_addresses).must_be_empty
|
|
|
|
_(resource.ipv4_addresses_netmask).must_be_empty
|
2020-05-19 03:42:25 +00:00
|
|
|
_(resource.ipv6_address).must_be_nil
|
2019-03-18 22:53:51 +00:00
|
|
|
_(resource.ipv6_cidrs).must_be_empty
|
|
|
|
_(resource.ipv6_addresses).must_be_empty
|
|
|
|
_(resource.ipv4_address?).must_equal false
|
|
|
|
_(resource.ipv6_address?).must_equal false
|
2015-10-08 10:11:55 +00:00
|
|
|
end
|
2015-10-08 11:01:09 +00:00
|
|
|
|
2019-03-18 22:53:51 +00:00
|
|
|
# windows
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify interface on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("interface", "ethernet0")
|
2015-10-08 11:01:09 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.up?).must_equal false
|
2019-10-03 07:23:17 +00:00
|
|
|
_(resource.name).must_equal "Ethernet0"
|
2015-10-08 11:01:09 +00:00
|
|
|
_(resource.speed).must_equal 0
|
2020-05-19 03:42:25 +00:00
|
|
|
_(resource.ipv4_address).must_be_nil
|
2019-03-18 22:53:51 +00:00
|
|
|
_(resource.ipv4_address?).must_equal false
|
|
|
|
_(resource.ipv6_address?).must_equal false
|
|
|
|
_(resource.ipv4_addresses).must_be_empty
|
|
|
|
_(resource.ipv4_addresses_netmask).must_be_empty
|
2020-05-19 03:42:25 +00:00
|
|
|
_(resource.ipv6_address).must_be_nil
|
2019-03-18 22:53:51 +00:00
|
|
|
_(resource.ipv6_addresses).must_be_empty
|
|
|
|
_(resource.ipv4_cidrs).must_be_empty
|
|
|
|
_(resource.ipv6_cidrs).must_be_empty
|
2015-10-08 11:01:09 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify interface on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("interface", "vEthernet (Intel(R) PRO 1000 MT Network Connection - Virtual Switch)")
|
2015-10-08 11:01:09 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.up?).must_equal true
|
2019-10-03 07:23:17 +00:00
|
|
|
_(resource.name).must_equal "vEthernet (Intel(R) PRO 1000 MT Network Connection - Virtual Switch)"
|
2015-10-08 11:01:09 +00:00
|
|
|
_(resource.speed).must_equal 10000000
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.ipv4_cidrs).must_include "127.0.0.1/8"
|
2020-06-05 17:48:41 +00:00
|
|
|
_(resource.ipv4_address).must_equal "127.0.0.1"
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.ipv4_addresses).must_include "127.0.0.1"
|
|
|
|
_(resource.ipv4_addresses_netmask).must_include "127.0.0.1/255.0.0.0"
|
|
|
|
_(resource.ipv6_cidrs).must_include "::1/128"
|
2020-06-05 17:48:41 +00:00
|
|
|
_(resource.ipv6_address).must_equal "::1"
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.ipv6_addresses).must_include "::1"
|
2019-03-18 22:53:51 +00:00
|
|
|
_(resource.ipv4_address?).must_equal true
|
|
|
|
_(resource.ipv6_address?).must_equal true
|
2015-10-08 11:01:09 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify invalid interface on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("interface", "eth1")
|
2015-10-08 11:01:09 +00:00
|
|
|
_(resource.exists?).must_equal false
|
|
|
|
_(resource.up?).must_equal false
|
2019-10-03 07:23:17 +00:00
|
|
|
_(resource.name).must_be_nil
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.speed).must_be_nil
|
2019-03-18 22:53:51 +00:00
|
|
|
_(resource.ipv4_address?).must_equal false
|
|
|
|
_(resource.ipv6_address?).must_equal false
|
|
|
|
_(resource.ipv4_addresses).must_be_empty
|
|
|
|
_(resource.ipv4_addresses_netmask).must_be_empty
|
|
|
|
_(resource.ipv6_addresses).must_be_empty
|
|
|
|
_(resource.ipv4_cidrs).must_be_empty
|
|
|
|
_(resource.ipv6_cidrs).must_be_empty
|
2015-10-08 11:01:09 +00:00
|
|
|
end
|
|
|
|
|
2020-05-14 21:28:58 +00:00
|
|
|
it "verify interface on macos" do
|
2020-07-01 22:35:23 +00:00
|
|
|
resource = MockLoader.new(:macos10_10).load_resource("interface", "en0")
|
2020-05-14 21:28:58 +00:00
|
|
|
_(resource.exists?).must_equal true
|
|
|
|
_(resource.up?).must_equal true
|
|
|
|
_(resource.speed).must_equal 1000
|
|
|
|
_(resource.name).must_equal "en0"
|
|
|
|
_(resource.ipv4_cidrs).must_include "192.168.1.2/24"
|
2020-06-05 17:48:41 +00:00
|
|
|
_(resource.ipv4_address).must_equal "192.168.1.2"
|
2020-05-14 21:28:58 +00:00
|
|
|
_(resource.ipv4_addresses).must_include "192.168.1.2"
|
|
|
|
_(resource.ipv4_addresses_netmask).must_include "192.168.1.2/255.255.255.0"
|
|
|
|
_(resource.ipv6_cidrs).must_include "fe80::8b6:c2cc:2928:3b61/64"
|
2020-06-05 17:48:41 +00:00
|
|
|
_(resource.ipv6_address).must_equal "fe80::8b6:c2cc:2928:3b61"
|
2020-05-14 21:28:58 +00:00
|
|
|
_(resource.ipv6_addresses).must_include "fe80::8b6:c2cc:2928:3b61"
|
|
|
|
_(resource.ipv4_address?).must_equal true
|
|
|
|
_(resource.ipv6_address?).must_equal true
|
|
|
|
end
|
|
|
|
|
2015-10-08 11:01:09 +00:00
|
|
|
# undefined
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify interface on unsupported os" do
|
|
|
|
resource = MockLoader.new(:undefined).load_resource("interface", "eth0")
|
2015-10-08 11:01:09 +00:00
|
|
|
_(resource.exists?).must_equal false
|
|
|
|
_(resource.up?).must_equal false
|
2019-10-03 07:23:17 +00:00
|
|
|
_(resource.name).must_be_nil
|
2017-06-11 10:16:10 +00:00
|
|
|
_(resource.speed).must_be_nil
|
2015-10-08 11:01:09 +00:00
|
|
|
end
|
|
|
|
|
2015-10-08 10:11:55 +00:00
|
|
|
end
|