Added inheritance test for windows

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2022-06-29 17:10:54 +05:30
parent 8bcfc38fe0
commit 5617ed819c
7 changed files with 53 additions and 7 deletions

View file

@ -350,24 +350,24 @@ module Inspec
def load_libraries def load_libraries
return @runner_context if @libraries_loaded return @runner_context if @libraries_loaded
locked_dependencies.dep_list.each_with_index do |(_name, dep), x| locked_dependencies.dep_list.each_with_index do |(_name, dep), index|
d = dep.profile d = dep.profile
# this will force a dependent profile load so we are only going to add # this will force a dependent profile load so we are only going to add
# this metadata if the parent profile is supported. # this metadata if the parent profile is supported.
if @supports_platform && !d.supports_platform? if @supports_platform && !d.supports_platform?
# since ruby 1.9 hashes are ordered so we can just use index values here # since ruby 1.9 hashes are ordered so we can just use index values here
# TODO: NO! this is a violation of encapsulation to an extreme # TODO: NO! this is a violation of encapsulation to an extreme
if metadata.dependencies[x] if metadata.dependencies[index]
metadata.dependencies[x][:status] = "skipped" metadata.dependencies[index][:status] = "skipped"
msg = "Skipping profile: '#{d.name}' on unsupported platform: '#{d.backend.platform.name}/#{d.backend.platform.release}'." msg = "Skipping profile: '#{d.name}' on unsupported platform: '#{d.backend.platform.name}/#{d.backend.platform.release}'."
metadata.dependencies[x][:status_message] = msg metadata.dependencies[index][:status_message] = msg
metadata.dependencies[x][:skip_message] = msg # Repeat as skip_message for backward compatibility metadata.dependencies[index][:skip_message] = msg # Repeat as skip_message for backward compatibility
end end
next next
elsif metadata.dependencies[x] elsif metadata.dependencies[index]
# Currently wrapper profiles will load all dependencies, and then we # Currently wrapper profiles will load all dependencies, and then we
# load them again when we dive down. This needs to be re-done. # load them again when we dive down. This needs to be re-done.
metadata.dependencies[x][:status] = "loaded" metadata.dependencies[index][:status] = "loaded"
end end
# rubocop:disable Layout/ExtraSpacing # rubocop:disable Layout/ExtraSpacing

View file

@ -0,0 +1,15 @@
name: child-profile-1
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0
supports:
platform: os
depends:
- name: ssh
git: https://github.com/dev-sec/windows-baseline.git
tag: 2.1.8

View file

@ -0,0 +1,14 @@
name: child-profile-2
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0
supports:
platform: os
depends:
- name: ssh
git: https://github.com/dev-sec/windows-baseline.git
tag: 2.1.6

View file

@ -0,0 +1,2 @@
include_controls "child-profile-1"
include_controls "child-profile-2"

View file

@ -0,0 +1,15 @@
name: parent-profile
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0
supports:
platform: os
depends:
- name: child-profile-2
path: ../child-profile-2
- name: child-profile-1
path: ../child-profile-1