How to use descriptions method of Inspec Package

Best Inspec_ruby code snippet using Inspec.descriptions

inspec_test.rb

Source:inspec_test.rb Github

copy

Full Screen

...83 { 'controls' => [84 {85 'id' => '1',86 'tags' => {},87 'descriptions' => {}88 },89 ] },90 ]91 }92 inspec_converter = InspecTools::Inspec.new(json.to_json)93 subject = inspec_converter.send(:parse_data_for_xccdf, json)94 refute subject['controls'].first.key?('cci')95 end96 def test_to_xccdf_no_value_when_no_fix97 json = {98 'profiles' => [99 { 'controls' => [100 {101 'id' => '1',102 'tags' => {},103 'descriptions' => {}104 },105 ] },106 ]107 }108 inspec_converter = InspecTools::Inspec.new(json.to_json)109 subject = inspec_converter.send(:parse_data_for_xccdf, json)110 assert subject['controls'].first.key?('fix')111 end112 def test_to_xccdf_no_value_when_no_fix_id113 json = {114 'profiles' => [115 { 'controls' => [116 {117 'id' => '1',118 'tags' => {},119 'descriptions' => {}120 },121 ] },122 ]123 }124 inspec_converter = InspecTools::Inspec.new(json.to_json)125 subject = inspec_converter.send(:parse_data_for_xccdf, json)126 refute subject['controls'].first.key?('fix_id')127 end128 def test_to_xccdf_no_value_when_no_gdescription129 json = {130 'profiles' => [131 { 'controls' => [132 {133 'id' => '1',134 'tags' => {},135 'descriptions' => {}136 },137 ] },138 ]139 }140 inspec_converter = InspecTools::Inspec.new(json.to_json)141 subject = inspec_converter.send(:parse_data_for_xccdf, json)142 refute subject['controls'].first.key?('gdescription')143 end144 def test_to_xccdf_no_value_when_no_gtitle145 json = {146 'profiles' => [147 { 'controls' => [148 {149 'id' => '1',150 'tags' => {},151 'descriptions' => {}152 },153 ] },154 ]155 }156 inspec_converter = InspecTools::Inspec.new(json.to_json)157 subject = inspec_converter.send(:parse_data_for_xccdf, json)158 refute subject['controls'].first.key?('gtitle')159 end160 def test_to_xccdf_no_gid_defaults_to_control_id161 json = {162 'profiles' => [163 { 'controls' => [164 {165 'id' => '1',166 'tags' => {},167 'descriptions' => {}168 },169 ] },170 ]171 }172 inspec_converter = InspecTools::Inspec.new(json.to_json)173 subject = inspec_converter.send(:parse_data_for_xccdf, json)174 assert_equal json['profiles'].first['controls'].first['id'], subject['controls'].first['gid']175 end176 def test__to_xccdf_no_rid_default_rid_value177 json = {178 'profiles' => [179 { 'controls' => [180 {181 'id' => '1',182 'tags' => { 'gid' => 'g_id_1' },183 'descriptions' => {}184 },185 ] },186 ]187 }188 inspec_converter = InspecTools::Inspec.new(json.to_json)189 subject = inspec_converter.send(:parse_data_for_xccdf, json)190 assert_equal "r_#{json['profiles'].first['controls'].first['tags']['gid']}", subject['controls'].first['rid']191 end192 def test_to_xccdf_no_value_when_no_rversion193 json = {194 'profiles' => [195 { 'controls' => [196 {197 'id' => '1',198 'tags' => {},199 'descriptions' => {}200 },201 ] },202 ]203 }204 inspec_converter = InspecTools::Inspec.new(json.to_json)205 subject = inspec_converter.send(:parse_data_for_xccdf, json)206 refute subject['controls'].first.key?('rversion')207 end208 def test_to_xccdf_no_value_when_no_rweight209 json = {210 'profiles' => [211 { 'controls' => [212 {213 'id' => '1',214 'tags' => {},215 'descriptions' => {}216 },217 ] },218 ]219 }220 inspec_converter = InspecTools::Inspec.new(json.to_json)221 subject = inspec_converter.send(:parse_data_for_xccdf, json)222 refute subject['controls'].first.key?('rweight')223 end224 def test_to_xccdf_default_value_when_no_severity225 json = {226 'profiles' => [227 { 'controls' => [228 {229 'id' => '1',230 'tags' => {},231 'descriptions' => {}232 },233 ] },234 ]235 }236 inspec_converter = InspecTools::Inspec.new(json.to_json)237 subject = inspec_converter.send(:parse_data_for_xccdf, json)238 assert_equal 'unknown', subject['controls'].first['severity']239 end240 def test_to_xccdf_no_value_when_no_title241 json = {242 'profiles' => [243 { 'controls' => [244 {245 'id' => '1',246 'tags' => {},247 'descriptions' => {}248 },249 ] },250 ]251 }252 inspec_converter = InspecTools::Inspec.new(json.to_json)253 subject = inspec_converter.send(:parse_data_for_xccdf, json)254 refute subject['controls'].first.key?('title')255 end256 def test_to_xccdf_run_end_time257 # Minimum JSON to create a converter object.258 json = {259 'profiles' => [260 { 'controls' => [261 {262 'id' => '1',263 'tags' => {},264 'descriptions' => {}265 },266 ] },267 ]268 }269 inspec_converter = InspecTools::Inspec.new(json.to_json)270 control = { 'controls' => [271 {272 'results' => [273 {274 'run_time' => 0.000101,275 'start_time' => '2019-10-17T08:00:02-04:00'276 },277 ]278 },279 {280 'results' => [281 {282 'run_time' => 2.426861,283 'start_time' => '2019-10-17T08:00:04-04:00'284 },285 {286 'run_time' => 2.0e-06,287 'start_time' => '2019-10-17T08:00:02-04:00'288 },289 ]290 },291 ] }292 assert_equal '2019-10-17T08:00:06-04:00', inspec_converter.send(:run_end_time, control).to_s293 end294 def test_to_xccdf_run_start_time295 # Minimum JSON to create a converter object.296 json = {297 'profiles' => [298 { 'controls' => [299 {300 'id' => '1',301 'tags' => {},302 'descriptions' => {}303 },304 ] },305 ]306 }307 inspec_converter = InspecTools::Inspec.new(json.to_json)308 control = { 'controls' => [309 {310 'results' => [311 {312 'run_time' => 0.000101,313 'start_time' => '2019-10-17T08:00:02-04:00'314 },315 ]316 },...

Full Screen

Full Screen

objects_test.rb

Source:objects_test.rb Github

copy

Full Screen

...253 control = Inspec::Object::Control.new254 control.add_test(obj1)255 control.id = "sample.control.id"256 control.title = "Sample Control Important Title"257 control.descriptions = {258 default: "The most critical control the world has ever seen",259 rationale: "It is needed to save the planet",260 'more info': "Insert clever joke here",261 }262 control.refs = ["simple ref", { ref: "title", url: "my url" }]263 control.impact = 1.0264 _(control.to_ruby).must_equal '265control "sample.control.id" do266 title "Sample Control Important Title"267 desc "The most critical control the world has ever seen"268 desc "rationale", "It is needed to save the planet"269 desc "more info", "Insert clever joke here"270 impact 1.0271 ref "simple ref"272 ref ({:ref=>"title", :url=>"my url"})273 describe command("ls /etc") do274 its("exit_status") { should eq 0 }275 end276end277'.strip278 end279 it "constructs a control with only_if" do280 control = Inspec::Object::Control.new281 control.add_test(obj1)282 control.only_if = "package('ntp').installed?"283 control.id = "sample.control.id"284 control.title = "Sample Control Important Title"285 control.descriptions = {286 default: "The most critical control the world has ever seen",287 rationale: "It is needed to save the planet",288 'more info': "Insert clever joke here",289 }290 control.refs = ["simple ref", { ref: "title", url: "my url" }]291 control.impact = 1.0292 _(control.to_ruby).must_equal '293control "sample.control.id" do294 title "Sample Control Important Title"295 desc "The most critical control the world has ever seen"296 desc "rationale", "It is needed to save the planet"297 desc "more info", "Insert clever joke here"298 impact 1.0299 ref "simple ref"300 ref ({:ref=>"title", :url=>"my url"})301 only_if { package(\'ntp\').installed? }302 describe command("ls /etc") do303 its("exit_status") { should eq 0 }304 end305end306'.strip307 end308 it "constructs a multiline desc in a control with indentation" do309 control = Inspec::Object::Control.new310 control.descriptions[:default] = "Multiline\n control"311 _(control.to_ruby).must_equal '312control nil do313 desc "314 Multiline315 control316 "317end318'.strip319 end320 it "ignores empty control descriptions" do321 control = Inspec::Object::Control.new322 x = '323control nil do324end325'.strip326 control.descriptions[:default] = ""327 _(control.to_ruby).must_equal x328 control.descriptions[:default] = nil329 _(control.to_ruby).must_equal x330 end331 it "handles non-string descriptions" do332 control = Inspec::Object::Control.new333 control.descriptions[:default] = 123334 _(control.to_ruby).must_equal '335control nil do336 desc "123"337end338'.strip339 end340 end341 describe "Inspec::Object::Variable, take #1" do342 it "constructs a control with variable to instantiate a resource only once" do343 control = Inspec::Object::Control.new344 variable = Inspec::Object::Value.new([["command", "which grep"]])345 variable_id = variable.name_variable.to_s346 obj1 = Inspec::Object::Test.new347 obj1.variables.push(variable)348 obj1.qualifier.push([variable_id])349 obj1.qualifier.push(["exit_status"])350 obj1.matcher = "eq"351 obj1.expectation = 0352 control.add_test(obj1)353 obj2 = Inspec::Object::Test.new354 obj2.qualifier.push([variable_id.to_s])355 obj2.qualifier.push(["stdout"])356 obj2.matcher = "contain"357 obj2.expectation = "grep"358 control.add_test(obj2)359 control.id = "variable.control.id"360 control.title = "Variable Control Important Title"361 control.descriptions[:default] = "The most variable control the world has ever seen"362 control.impact = 1.0363 _(control.to_ruby).must_equal '364control "variable.control.id" do365 title "Variable Control Important Title"366 desc "The most variable control the world has ever seen"367 impact 1.0368 a = command("which grep")369 describe a do370 its("exit_status") { should eq 0 }371 end372 describe a do373 its("stdout") { should contain "grep" }374 end375end376'.strip377 end378 end379 describe "Inspec::Object::Variable, take #2" do380 it "constructs a control with variable, loop and var reference" do381 control = Inspec::Object::Control.new382 command_value = %r{^/usr/bin/chrony}383 pid_filter = ">"384 pid_value = 0385 loopy = Inspec::Object::EachLoop.new386 loopy.qualifier = [["processes", command_value]]387 loopy.qualifier.push(["where { pid #{pid_filter} #{pid_value} }.entries"])388 obj = loopy.add_test389 variable = Inspec::Object::Value.new([['passwd.where { user == "_chrony" }.uids.first']])390 variable_id = variable.name_variable.to_s391 obj.variables.push(variable)392 obj.qualifier = [["user(entry.user)"], ["uid"]]393 obj.matcher = "cmp #{variable_id}"394 control.add_test(obj)395 control.id = "variable.control.id"396 control.impact = 0.1397 _(control.to_ruby).must_equal '398control "variable.control.id" do399 impact 0.1400 a = passwd.where { user == "_chrony" }.uids.first401 describe user(entry.user) do402 its("uid") { should cmp a }403 end404end405'.strip406 end407 end408 describe "Inspec::Object::Tag" do409 it "constructs a tag with key and value" do410 control = Inspec::Object::Control.new411 res1 = { name: "key", value: "value" }412 tag1 = Inspec::Object::Tag.new(res1[:name], res1[:value])413 _(tag1.to_hash).must_equal res1414 control.add_tag(tag1)415 res2 = { name: "key2", value: %w{a b} }416 tag2 = Inspec::Object::Tag.new(res2[:name], res2[:value])417 _(tag2.to_hash).must_equal res2418 control.add_tag(tag2)419 control.id = "tag.control.id"420 _(control.to_ruby).must_equal '421control "tag.control.id" do422 tag key: "value"423 tag key2: ["a", "b"]424end425'.strip426 control_hash = {427 id: "tag.control.id",428 title: nil,429 descriptions: {},430 impact: nil,431 tests: [],432 tags: [{433 name: "key",434 value: "value",435 }, {436 name: "key2",437 value: %w{a b},438 }],439 }440 _(control.to_hash).must_equal control_hash441 end442 end443 describe "Inspec::Object::Input" do...

Full Screen

Full Screen

rule.rb

Source:rule.rb Github

copy

Full Screen

...145 "#{component.prefix}-#{rule_id}",146 SEVERITIES_MAP[rule_severity] || rule_severity,147 srg_rule.title, # original srg title148 title,149 srg_rule.disa_rule_descriptions.first.vuln_discussion, # original srg vuln discussion150 disa_rule_descriptions.first.vuln_discussion,151 status,152 srg_rule.checks.first.content, # original SRG check content153 export_checktext,154 srg_rule.fixtext, # original SRG fix text155 export_fixtext,156 status_justification,157 disa_rule_descriptions.first.mitigations,158 artifact_description,159 vendor_comments_with_satisfactions160 ]161 end162 def displayed_name163 "#{component[:prefix]}-#{rule_id}"164 end165 def update_inspec_code166 desc = disa_rule_descriptions.first167 control = Inspec::Object::Control.new168 control.add_header('# -*- encoding : utf-8 -*-')169 control.id = "#{component[:prefix]}-#{rule_id}"170 control.title = title171 control.descriptions[:default] = desc[:vuln_discussion] if desc.present?172 control.descriptions[:rationale] = ''173 control.descriptions[:check] = checks.first&.content174 control.descriptions[:fix] = fixtext175 control.impact = RuleConstants::IMPACTS_MAP[rule_severity]176 control.add_tag(Inspec::Object::Tag.new('severity', rule_severity))177 control.add_tag(Inspec::Object::Tag.new('gtitle', version))178 control.add_tag(Inspec::Object::Tag.new('satisfies', satisfies.pluck(:version).sort)) if satisfies.present?179 control.add_tag(Inspec::Object::Tag.new('gid', nil))180 control.add_tag(Inspec::Object::Tag.new('rid', nil))181 control.add_tag(Inspec::Object::Tag.new('stig_id', "#{component[:prefix]}-#{rule_id}"))182 control.add_tag(Inspec::Object::Tag.new('cci', ([ident] + satisfies.pluck(:ident)).uniq.sort)) if ident.present?183 control.add_tag(Inspec::Object::Tag.new('nist', ([nist_control_family] +184 satisfies.map(&:nist_control_family)).uniq.sort))185 if desc.present?186 %i[false_negatives false_positives documentable mitigations severity_override_guidance potential_impacts187 third_party_tools mitigation_control responsibility ia_controls].each do |field|188 control.add_tag(Inspec::Object::Tag.new(field.to_s, desc[field])) if desc[field].present?189 end190 end191 control.add_post_body(inspec_control_body) if inspec_control_body.present?192 self.inspec_control_file = control.to_ruby193 end194 def update_satisfied_by_inspec_code195 sb = satisfied_by.first196 return if sb.nil?197 # trigger update_inspec_code callback198 sb.save199 end200 def basic_fields201 {202 rule_id: rule_id,203 title: title,204 vuln_discussion: disa_rule_descriptions.first&.vuln_discussion,205 check: export_checktext,206 fix: export_fixtext207 }208 end209 private210 def export_fixtext211 satisfied_by.size.positive? ? satisfied_by.first.fixtext : fixtext212 end213 def export_checktext214 satisfied_by.size.positive? ? satisfied_by.first.checks.first&.content : checks.first&.content215 end216 def vendor_comments_with_satisfactions217 comments = []218 comments << vendor_comments if vendor_comments.present?219 if satisfied_by.present?220 comments << "Satisfied By: #{satisfied_by.map { |r| "#{component.prefix}-#{r.rule_id}" }.join(', ')}."221 end222 if satisfies.present?223 comments << "Satisfies: #{satisfies.map { |r| "#{component.prefix}-#{r.rule_id}" }.join(', ')}."224 end225 comments.join('. ')226 end227 def cannot_be_locked_and_under_review228 return unless locked && review_requestor_id.present?229 errors.add(:base, 'Control cannot be under review and locked at the same time.')230 end231 ##232 # Check to ensure that "review fields" are not changed233 # in the same `.save` action as any "non-review fields"234 def review_fields_cannot_change_with_other_fields235 review_fields = Set.new(%w[review_requestor_id locked changes_requested])236 ignored_fields = %w[updated_at created_at]237 changed_filtered = changed.reject { |f| ignored_fields.include? f }238 any_review_fields_changed = changed_filtered.any? { |field| review_fields.include? field }239 any_non_review_fields_changed = changed_filtered.any? { |field| review_fields.exclude? field }240 # Break early if review and non-review fields have not changed together241 return unless any_review_fields_changed && any_non_review_fields_changed242 errors.add(:base, 'Cannot update review-related attributes with other non-review-related attributes')243 end244 def set_rule_id245 self.rule_id = (component.largest_rule_id + 1).to_s.rjust(6, '0') if rule_id.blank?246 end247 ##248 # Rules should never be deleted if they are under review or locked249 # This checks *_was to cover the case where an attrubute was changed before attempting to destroy250 def prevent_destroy_if_under_review_or_locked251 # Allow deletion if it is due to the parent being deleted252 return if destroyed_by_association.present?253 # Abort if under review and trying to delete254 if review_requestor_id_was.present?255 errors.add(:base, 'Control is under review and cannot be destroyed')256 throw(:abort)257 end258 # Abort if locked and trying to delete259 return unless locked_was260 errors.add(:base, 'Control is locked and cannot be destroyed')261 throw(:abort)262 end263 ##264 # This before_save callback method exists because if there are no changes on a record, but a audit_comment265 # is provided, then an Audited::Audit record will be created with no audited_changes. This makes histories266 # unnecessarily confusing.267 #268 # This method addresses that issue by checking the record and its dependent records to see if they are269 # new records, changed, or marked for deletion. If any of those criteria are true, then the audited_comment270 # will be applied ONLY to the correct places.271 #272 def apply_audit_comment273 comment = audit_comment274 return if comment.nil?275 self.audit_comment = nil unless new_record? || changed?276 (rule_descriptions + disa_rule_descriptions + checks + additional_answers).each do |record|277 record.audit_comment = comment if record.new_record? || record.changed? || record._destroy278 end279 end280 def update_component_rules_count281 component.rules_count = component.rules.where(deleted_at: nil).size282 component.save283 end284end...

Full Screen

Full Screen

descriptions

Using AI Code Generation

copy

Full Screen

1 expect(1).to eq(1)2 expect(1).to eq(1)3 expect(1).to eq(1)4 expect(1).to eq(1)5 expect(1).to eq(1)6 expect(1).to eq(1)7 expect(1).to eq(1)8 expect(1).to eq(1)

Full Screen

Full Screen

descriptions

Using AI Code Generation

copy

Full Screen

1 its('descriptions') { should include 'Check for descriptions' }2 its('descriptions') { should include 'Check for descriptions' }3 its('descriptions') { should include 'Check for descriptions' }4 its('descriptions') { should include 'Check for descriptions' }5 its('descriptions') { should include 'Check for descriptions' }

Full Screen

Full Screen

descriptions

Using AI Code Generation

copy

Full Screen

1 describe file('/etc/passwd') do2 it { should exist }3 describe file('/etc/passwd') do4 it { should exist }5 describe file('/etc/passwd') do6 it { should exist }7 describe file('/etc/passwd') do8 it { should exist }9 describe file('/etc/passwd')

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