How to use resolve method of Inspec Package

Best Inspec_ruby code snippet using Inspec.resolve

inspec_spec.rb

Source:inspec_spec.rb Github

copy

Full Screen

...205 end206 end207 end208 end209 describe "#resolve_config_inspec_tests" do210 context "when the entry is a string" do211 context "when the path does not exist" do212 it "returns the original string" do213 config[:inspec_tests] = ["test/integration/foo"]214 expect(File).to receive(:exist?).with("test/integration/foo").and_return(false)215 allow(File).to receive(:exist?).and_call_original216 expect(verifier.send(:resolve_config_inspec_tests)).to eq(["test/integration/foo"])217 end218 end219 context "when the path exists" do220 it "expands to an absolute path and returns a hash" do221 config[:inspec_tests] = ["test/integration/foo"]222 expect(File).to receive(:exist?).with("test/integration/foo").and_return(true)223 allow(File).to receive(:exist?).and_call_original224 expect(File).to receive(:expand_path).with("test/integration/foo").and_return("/absolute/path/to/foo")225 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ path: "/absolute/path/to/foo" }])226 end227 end228 end229 context "when the entry is a hash" do230 context "when the entry is a path" do231 it "expands the path to an absolute path and removes unnecessary keys" do232 config[:inspec_tests] = [{ name: "foo_profile", path: "test/integration/foo" }]233 expect(File).to receive(:expand_path).with("test/integration/foo").and_return("/absolute/path/to/foo")234 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ path: "/absolute/path/to/foo" }])235 end236 end237 context "when the entry is a url item" do238 it "returns a hash with unnecessary keys removed" do239 config[:inspec_tests] = [{ name: "foo_profile", url: "http://some.domain/profile" }]240 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ url: "http://some.domain/profile" }])241 end242 end243 context "when the entry is a git item" do244 it "returns a hash with unnecessary keys removed" do245 config[:inspec_tests] = [{ name: "foo_profile", git: "http://some.domain/profile" }]246 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ git: "http://some.domain/profile" }])247 end248 end249 context "when the entry is a compliance item" do250 it "returns a hash with unnecessary keys removed" do251 config[:inspec_tests] = [{ name: "foo_profile", compliance: "me/foo" }]252 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ compliance: "me/foo" }])253 end254 end255 context "when the entry only contains a name" do256 it "returns it as-is to be resolved on Supermarket" do257 config[:inspec_tests] = [{ name: "me/foo" }]258 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ name: "me/foo" }])259 end260 end261 context "when the entry contains no acceptable keys" do262 it "returns nil" do263 config[:inspec_tests] = [{ key1: "value1", key2: "value2" }]264 expect(verifier.send(:resolve_config_inspec_tests)).to eq([nil])265 end266 end267 end268 it "returns an array of properly formatted entries when multiple entries are supplied" do269 config[:inspec_tests] = [270 { name: "profile1", git: "me/profile1" },271 { name: "profile2", random_key: "random_value", compliance: "me/profile2" },272 { name: "profile3", url: "someurl", random_key: "what is this for?", another_random_key: 123 },273 { name: "profile4" },274 ]275 expect(verifier.send(:resolve_config_inspec_tests)).to eq([276 { git: "me/profile1" },277 { compliance: "me/profile2" },278 { url: "someurl" },279 { name: "profile4" },280 ])281 end282 end283 context "with an ssh transport" do284 let(:transport_config) do285 {286 hostname: "boogie",287 port: "I shouldn't be used",288 username: "dance",289 ssh_key: "/backstage/pass",290 keepalive: "keepalive",291 keepalive_interval: "forever",292 connection_timeout: "nope",293 connection_retries: "thousand",294 connection_retry_sleep: "sleepy",295 max_wait_until_ready: 42,296 compression: "maxyo",297 compression_level: "pico",298 forward_agent: true,299 }300 end301 let(:transport) do302 Kitchen::Transport::Ssh.new(transport_config)303 end304 let(:runner) do305 instance_double("Inspec::Runner")306 end307 before do308 allow(runner).to receive(:add_target)309 allow(runner).to receive(:run).and_return 0310 end311 it "constructs a Inspec::Runner using transport config data and state" do312 config[:sudo] = "jellybeans"313 config[:sudo_command] = "allyourbase"314 config[:proxy_command] = "gateway"315 config[:forward_agent] = true316 expect(Inspec::Runner).to receive(:new)317 .with(318 hash_including(319 "backend" => "ssh",320 "logger" => logger,321 "sudo" => "jellybeans",322 "sudo_command" => "allyourbase",323 "host" => "boogie",324 "port" => 123,325 "user" => "dance",326 "keepalive" => "keepalive",327 "keepalive_interval" => "forever",328 "connection_timeout" => "nope",329 "connection_retries" => "thousand",330 "connection_retry_sleep" => "sleepy",331 "max_wait_until_ready" => 42,332 "compression" => "maxyo",333 "compression_level" => "pico",334 "key_files" => ["/backstage/pass"],335 "proxy_command" => "gateway",336 "forward_agent" => true337 )338 )339 .and_return(runner)340 verifier.call(port: 123)341 end342 it "constructs a Inspec::Runner using transport config data(host and port)" do343 config[:host] = "192.168.33.40"344 config[:port] = 222345 expect(Inspec::Runner).to receive(:new)346 .with(347 hash_including(348 "backend" => "ssh",349 "host" => "192.168.33.40",350 "port" => 222351 )352 )353 .and_return(runner)354 verifier.call(port: 123)355 end356 it "constructs an Inspec::Runner with a specified inspec output format" do357 config[:format] = "documentation"358 expect(Inspec::Runner).to receive(:new)359 .with(360 hash_including(361 "format" => "documentation"362 )363 )364 .and_return(runner)365 verifier.call(port: 123)366 end367 it "constructs an Inspec::Runner with a controls filter" do368 config[:controls] = %w{a control}369 expect(Inspec::Runner).to receive(:new)370 .with(371 hash_including(372 controls: %w{a control}373 )374 )375 .and_return(runner)376 verifier.call(port: 123)377 end378 it "does not send keys_only=true to InSpec (which breaks SSH Agent usage)" do379 expect(Inspec::Runner).to receive(:new)380 .with(381 hash_not_including(382 "keys_only" => true383 )384 )385 .and_return(runner)386 verifier.call(port: 123)387 end388 it "provide platform and test suite to build output path" do389 allow(Inspec::Runner).to receive(:new).and_return(runner)390 expect(verifier).to receive(:runner_options).with(391 transport,392 {},393 "default",394 "germany"395 ).and_return({})396 verifier.call({})397 end398 it "custom inspec output path" do399 ensure_suite_directory("germany")400 config[:output] = "/tmp/inspec_results.xml"401 allow(Inspec::Runner).to receive(:new).and_return(runner)402 expect(runner).to receive(:add_target).with({ path: File.join(403 config[:test_base_path],404 "germany"405 ) }, hash_including(406 "output" => "/tmp/inspec_results.xml"407 ))408 verifier.call({})409 end410 it "resolve template format for inspec output path" do411 ensure_suite_directory("germany")412 config[:output] = "/tmp/%{platform}_%{suite}.xml"413 allow(Inspec::Runner).to receive(:new).and_return(runner)414 expect(runner).to receive(:add_target).with({ path: File.join(415 config[:test_base_path],416 "germany"417 ) }, hash_including(418 "output" => "/tmp/default_germany.xml"419 ))420 verifier.call({})421 end422 it "find test directory for runner" do423 ensure_suite_directory("germany")424 allow(Inspec::Runner).to receive(:new).and_return(runner)...

Full Screen

Full Screen

host.rb

Source:host.rb Github

copy

Full Screen

...45 end46 end47 # if we get the IP adress, the host is resolvable48 def resolvable?(type = nil)49 warn "The `host` resource ignores #{type} parameters. Continue to resolve host." if !type.nil?50 resolve.nil? || resolve.empty? ? false : true51 end52 def reachable?(port = nil, proto = nil, timeout = nil)53 fail "Use `host` resource with host('#{@hostname}', port: #{port}, proto: '#{proto}') parameters." if !port.nil? || !proto.nil? || !timeout.nil?54 ping.nil? ? false : ping55 end56 # returns all A records of the IP adress, will return an array57 def ipaddress58 resolve.nil? || resolve.empty? ? nil : resolve59 end60 def to_s61 "Host #{@hostname}"62 end63 private64 def ping65 return @ping_cache if defined?(@ping_cache)66 @ping_cache = @host_provider.ping(@hostname, @port, @proto) if !@host_provider.nil?67 end68 def resolve69 return @ip_cache if defined?(@ip_cache)70 @ip_cache = @host_provider.resolve(@hostname) if !@host_provider.nil?71 end72 end73 class HostProvider74 attr_reader :inspec75 def initialize(inspec)76 @inspec = inspec77 end78 end79 class LinuxHostProvider < HostProvider80 # ping is difficult to achieve, since we are not sure81 def ping(hostname, _port = nil, _proto = nil)82 # fall back to ping, but we can only test ICMP packages with ping83 # therefore we have to skip the test, if we do not have everything on the node to run the test84 ping = inspec.command("ping -w 1 -c 1 #{hostname}")85 ping.exit_status.to_i != 0 ? false : true86 end87 def resolve(hostname)88 # TODO: we rely on getent hosts for now, but it prefers to return IPv6, only then IPv489 cmd = inspec.command("getent hosts #{hostname}")90 return nil if cmd.exit_status.to_i != 091 # extract ip adress92 resolve = /^\s*(?<ip>\S+)\s+(.*)\s*$/.match(cmd.stdout.chomp)93 [resolve[1]] if resolve94 end95 end96 # Windows97 # TODO: UDP is not supported yey, we need a custom ps1 script to add udp support98 # @see http://blogs.technet.com/b/josebda/archive/2015/04/18/windows-powershell-equivalents-for-common-networking-commands-ipconfig-ping-nslookup.aspx99 # @see http://blogs.technet.com/b/heyscriptingguy/archive/2014/03/19/creating-a-port-scanner-with-windows-powershell.aspx100 class WindowsHostProvider < HostProvider101 def ping(hostname, port = nil, proto = nil)102 # TODO: abort if we cannot run it via udp103 return nil if proto == 'udp'104 # ICMP: Test-NetConnection www.microsoft.com105 # TCP and port: Test-NetConnection -ComputerName www.microsoft.com -RemotePort 80106 request = "Test-NetConnection -ComputerName #{hostname}"107 request += " -RemotePort #{port}" unless port.nil?108 request += '| Select-Object -Property ComputerName, RemoteAddress, RemotePort, SourceAddress, PingSucceeded | ConvertTo-Json'109 p request110 request += '| Select-Object -Property ComputerName, PingSucceeded | ConvertTo-Json'111 cmd = inspec.command(request)112 begin113 ping = JSON.parse(cmd.stdout)114 rescue JSON::ParserError => _e115 return nil116 end117 ping['PingSucceeded']118 end119 def resolve(hostname)120 cmd = inspec.command("Resolve-DnsName –Type A #{hostname} | ConvertTo-Json")121 begin122 resolv = JSON.parse(cmd.stdout)123 rescue JSON::ParserError => _e124 return nil125 end126 resolv = [resolv] unless resolv.is_a?(Array)127 resolv.map { |entry| entry['IPAddress'] }128 end129 end130end...

Full Screen

Full Screen

system.rb

Source:system.rb Github

copy

Full Screen

1# frozen_string_literal: true2require 'kitchen/pulumi/error'3require 'kitchen/pulumi/inspec_with_hosts'4require 'kitchen/pulumi/inspec_without_hosts'5require 'kitchen/pulumi/system_inputs_resolver'6require 'kitchen/pulumi/system_hosts_resolver'7module Kitchen8 module Pulumi9 # System is the class of objects which are verified by the Pulumi Verifier.10 class System11 # #add_inputs adds Inspec Inputs to the system.12 #13 # @param inputs [#to_hash] the inputs to be added.14 # @return [self]15 def add_inputs(inputs:)16 @inputs = @inputs.merge Hash inputs17 self18 end19 # #add_hosts adds hosts to the system.20 #21 # @param hosts [#to_arr,#to_a] the hosts to be added.22 # @return [self]23 def add_hosts(hosts:)24 @hosts += Array hosts25 self26 end27 # #each_host enumerates each host of the system.28 #29 # @yieldparam host [::String] the next host.30 # @return [self]31 def each_host32 @hosts.each do |host|33 yield host: host34 end35 self36 end37 # #to_s returns a string representation of the system.38 #39 # @return [::String] the name of the system.40 def to_s41 @mapping.fetch :name42 end43 # #verify verifies the system by executing InSpec.44 #45 # @param pulumi_inputs [::Hash] the Pulumi input values to be utilized as46 # InSpec profile Input.47 # @param pulumi_outputs [::Hash] the Pulumi output values to be utilized as48 # InSpec profile Input.49 # @param inspec_options [::Hash] the options to be passed to InSpec.50 # @return [self]51 def verify(pulumi_inputs:, pulumi_outputs:, inspec_options:)52 resolve(pulumi_inputs: pulumi_inputs, pulumi_outputs: pulumi_outputs)53 execute_inspec(options: inspec_options)54 self55 rescue StandardError => e56 raise ::Kitchen::Pulumi::Error, "#{self}: #{e.message}"57 end58 private59 def execute_inspec(options:)60 inspec.new(61 options: options_with_inputs(options: options),62 profile_locations: @mapping.fetch(:profile_locations),63 ).exec(system: self)64 end65 def initialize(mapping:)66 @inputs = {}67 @hosts = mapping.fetch :hosts do68 []69 end70 @mapping = mapping71 end72 def inspec73 if @hosts.empty?74 ::Kitchen::Pulumi::InSpecWithoutHosts75 else76 ::Kitchen::Pulumi::InSpecWithHosts77 end78 end79 def options_with_inputs(options:)80 options.merge(inputs: @inputs)81 end82 def resolve(pulumi_inputs:, pulumi_outputs:)83 resolve_inputs(pulumi_inputs: pulumi_inputs, pulumi_outputs: pulumi_outputs)84 resolve_hosts(pulumi_outputs: pulumi_outputs)85 end86 def resolve_inputs(pulumi_inputs:, pulumi_outputs:)87 ::Kitchen::Pulumi::SystemInputsResolver.new(88 pulumi_inputs: pulumi_inputs, pulumi_outputs: pulumi_outputs, system: self,89 ).resolve90 self91 end92 def resolve_hosts(pulumi_outputs:)93 return self unless @mapping.key?(:hosts_output)94 ::Kitchen::Pulumi::SystemHostsResolver.new(outputs: pulumi_outputs).resolve(95 hosts_output: @mapping.fetch(:hosts_output),96 system: self,97 )98 self99 end100 end101 end102end...

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1puts Inspec::Input.resolve('my_input')2puts Inspec::Input.resolve('my_input')3puts Inspec::Input.resolve('my_input')4puts Inspec::Input.resolve('my_input')5puts Inspec::Input.resolve('my_input')6puts Inspec::Input.resolve('my_input')7puts Inspec::Input.resolve('my_input')8puts Inspec::Input.resolve('my_input')9puts Inspec::Input.resolve('my_input')10puts Inspec::Input.resolve('my_input')11puts Inspec::Input.resolve('my_input')12puts Inspec::Input.resolve('my_input')13puts Inspec::Input.resolve('my_input')14puts Inspec::Input.resolve('my_input')15puts Inspec::Input.resolve('my_input')

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1puts Inspec::Input.resolve("my_value")2puts Inspec::Input.input("my_value")3puts Inspec::Input.input("my_value")4puts Inspec::Input.input("my_value")5puts Inspec::Input.input("my_value")6puts Inspec::Input.input("my_value")7puts Inspec::Input.input("my_value")8puts Inspec::Input.input("my_value")9puts Inspec::Input.input("my_value")10puts Inspec::Input.input("my_value")11puts Inspec::Input.input("my_value")12puts Inspec::Input.input("my_value")13puts Inspec::Input.input("my_value")14puts Inspec::Input.input("my_value")15puts Inspec::Input.input("my_value")

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1 expect(inspec.resolve('2.rb')).to eq '2'2 expect(inspec.resolve('3.rb')).to eq '3'3 expect(inspec.resolve('4.rb')).to eq '4'4 expect(inspec.resolve('5.rb')).to eq '5'5 expect(inspec.resolve('6.rb')).to eq '6'6 expect(inspec.resolve('7.rb')).to eq '7'7 expect(inspec.resolve('8.rb')).to eq '8'8 expect(inspec.resolve('9.rb')).to eq '9'9 expect(inspec.resolve('10.rb')).to eq '10'

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1Inspec . resolve ( '1.rb' )2Inspec . resolve ( '/tmp/inspec/1.rb' )3Inspec . resolve ( ' /tmp/inspec/1.rb ' )4Inspec . resolve ( ' /tmp/inspec/1.rb ' , ' /tmp/inspec ' )5Inspec . resolve ( ' /tmp/inspec/1.rb ' , ' /tmp/inspec ' , ' /tmp/inspec ' )6Inspec . resolve ( ' /tmp/inspec/1.rb ' , ' /tmp/inspec ' , ' /tmp/inspec ' , ' /tmp/inspec ' )7Inspec . resolve ( ' /tmp/inspec/1.rb ' , ' /tmp/inspec ' , ' /tmp/inspec ' , ' /tmp/inspec ' , ' /tmp/inspec ' )8Inspec . resolve ( ' /tmp/inspec/1.rb ' , ' /tmp/inspec ' , ' /tmp/inspec ' , ' /tmp/inspec ' , ' /tmp/inspec ' , ' /tmp/inspec ' )

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1file_path = Inspec.resolve('files/1.txt')2describe file(file_path) do3 its('content') { should match /Hello/ }4file_path = Inspec.resolve('files/2.txt')5describe file(file_path) do6 its('content') { should match /World/ }7files_path = File.join(__dir__, 'files')8 describe file(files_path) do9 it { should exist }10 describe file(files_path) do11 it { should exist }

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1puts Inspec.resolve('path_to_profile')2puts Inspec.resolve('path_to_profile')3puts Inspec.resolve('path_to_profile')4puts Inspec.resolve('path_to_profile')5puts Inspec.resolve('path_to_profile')6puts Inspec.resolve('path_to_profile')7puts Inspec.resolve('path_to_profile')8puts Inspec.resolve('path_to_profile')9puts Inspec.resolve('path_to_profile')10puts Inspec.resolve('path_to_profile')

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1Inspec::BaseCLI.inspec_exec('exec', target, 'test.rb')2describe file('/tmp') do3 it { should exist }

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1file = Inspec::InputRegistry.resolve('file')2file = Inspec::InputRegistry.resolve('file')3Inspec::InputRegistry.resolve(input_name)4file = Inspec::InputRegistry.resolve('file')

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1 expect(inspec.resolve('2.rb')).to eq '2'2 expect(inspec.resolve('3.rb')).to eq '3'3 expect(inspec.resolve('4.rb')).to eq '4'4 expect(inspec.resolve('5.rb')).to eq '5'5 expect(inspec.resolve('6.rb')).to eq '6'6 expect(inspec.resolve('7.rb')).to eq '7'7 expect(inspec.resolve('8.rb')).to eq '8'8 expect(inspec.resolve('9.rb')).to eq '9'9 expect(inspec.resolve('10.rb')).to eq '10'

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1file_path = Inspec.resolve('files/1.txt')2describe file(file_path) do3 its('content') { should match /Hello/ }4file_path = Inspec.resolve('files/2.txt')5describe file(file_path) do6 its('content') { should match /World/ }7files_path = File.join(__dir__, 'files')8 describe file(files_path) do9 it { should exist }10 describe file(files_path) do11 it { should exist }

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1puts Inspec.resolve('path_to_profile')2puts Inspec.resolve('path_to_profile')3puts Inspec.resolve('path_to_profile')4puts Inspec.resolve('path_to_profile')5puts Inspec.resolve('path_to_profile')6puts Inspec.resolve('path_to_profile')7puts Inspec.resolve('path_to_profile')8puts Inspec.resolve('path_to_profile')9puts Inspec.resolve('path_to_profile')10puts Inspec.resolve('path_to_profile')

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Inspec_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful