Best Inspec_ruby code snippet using InspecPlugins.Compliance.clean
api_test.rb
Source:api_test.rb
...107 describe 'automate/compliance is? checks' do108 describe 'when the config has a compliance server_type' do109 it 'automate/compliance server is? methods return correctly' do110 config = InspecPlugins::Compliance::Configuration.new111 config.clean112 config['server_type'] = 'compliance'113 InspecPlugins::Compliance::API.is_compliance_server?(config).must_equal true114 InspecPlugins::Compliance::API.is_automate_server?(config).must_equal false115 InspecPlugins::Compliance::API.is_automate_server_pre_080?(config).must_equal false116 InspecPlugins::Compliance::API.is_automate_server_080_and_later?(config).must_equal false117 InspecPlugins::Compliance::API.is_automate2_server?(config).must_equal false118 end119 end120 describe 'when the config has a automate2 server_type' do121 it 'automate/compliance server is? methods return correctly' do122 config = InspecPlugins::Compliance::Configuration.new123 config.clean124 config['server_type'] = 'automate2'125 InspecPlugins::Compliance::API.is_compliance_server?(config).must_equal false126 InspecPlugins::Compliance::API.is_automate_server?(config).must_equal false127 InspecPlugins::Compliance::API.is_automate_server_pre_080?(config).must_equal false128 InspecPlugins::Compliance::API.is_automate_server_080_and_later?(config).must_equal false129 InspecPlugins::Compliance::API.is_automate2_server?(config).must_equal true130 end131 end132 describe 'when the config has an automate server_type and no version key' do133 it 'automate/compliance server is? methods return correctly' do134 config = InspecPlugins::Compliance::Configuration.new135 config.clean136 config['server_type'] = 'automate'137 InspecPlugins::Compliance::API.is_compliance_server?(config).must_equal false138 InspecPlugins::Compliance::API.is_automate_server?(config).must_equal true139 InspecPlugins::Compliance::API.is_automate_server_pre_080?(config).must_equal true140 InspecPlugins::Compliance::API.is_automate_server_080_and_later?(config).must_equal false141 InspecPlugins::Compliance::API.is_automate2_server?(config).must_equal false142 end143 end144 describe 'when the config has an automate server_type and a version key that is not a hash' do145 it 'automate/compliance server is? methods return correctly' do146 config = InspecPlugins::Compliance::Configuration.new147 config.clean148 config['server_type'] = 'automate'149 config['version'] = '1.2.3'150 InspecPlugins::Compliance::API.is_compliance_server?(config).must_equal false151 InspecPlugins::Compliance::API.is_automate_server?(config).must_equal true152 InspecPlugins::Compliance::API.is_automate_server_pre_080?(config).must_equal true153 InspecPlugins::Compliance::API.is_automate_server_080_and_later?(config).must_equal false154 InspecPlugins::Compliance::API.is_automate2_server?(config).must_equal false155 end156 end157 describe 'when the config has an automate server_type and a version hash with no version' do158 it 'automate/compliance server is? methods return correctly' do159 config = InspecPlugins::Compliance::Configuration.new160 config.clean161 config['server_type'] = 'automate'162 config['version'] = {}163 InspecPlugins::Compliance::API.is_compliance_server?(config).must_equal false164 InspecPlugins::Compliance::API.is_automate_server?(config).must_equal true165 InspecPlugins::Compliance::API.is_automate_server_pre_080?(config).must_equal true166 InspecPlugins::Compliance::API.is_automate_server_080_and_later?(config).must_equal false167 end168 end169 describe 'when the config has an automate server_type and a version hash with a version' do170 it 'automate/compliance server is? methods return correctly' do171 config = InspecPlugins::Compliance::Configuration.new172 config.clean173 config['server_type'] = 'automate'174 config['version'] = { 'version' => '0.8.1' }175 InspecPlugins::Compliance::API.is_compliance_server?(config).must_equal false176 InspecPlugins::Compliance::API.is_automate_server?(config).must_equal true177 InspecPlugins::Compliance::API.is_automate_server_pre_080?(config).must_equal false178 InspecPlugins::Compliance::API.is_automate_server_080_and_later?(config).must_equal true179 end180 end181 end182 describe '.server_version_from_config' do183 it 'returns nil when the config has no version key' do184 config = {}185 InspecPlugins::Compliance::API.server_version_from_config(config).must_be_nil186 end187 it 'returns nil when the version value is not a hash' do188 config = { 'version' => '123' }189 InspecPlugins::Compliance::API.server_version_from_config(config).must_be_nil190 end191 it 'returns nil when the version value is a hash but has no version key inside' do192 config = { 'version' => {} }193 InspecPlugins::Compliance::API.server_version_from_config(config).must_be_nil194 end195 it 'returns the version if the version value is a hash containing a version' do196 config = { 'version' => { 'version' => '1.2.3' } }197 InspecPlugins::Compliance::API.server_version_from_config(config).must_equal '1.2.3'198 end199 end200 describe 'profile_split' do201 it 'handles a profile without version' do202 InspecPlugins::Compliance::API.profile_split('admin/apache-baseline').must_equal ['admin', 'apache-baseline', nil]203 end204 it 'handles a profile with a version' do205 InspecPlugins::Compliance::API.profile_split('admin/apache-baseline#2.0.1').must_equal ['admin', 'apache-baseline', '2.0.1']206 end207 end208 describe 'target_url' do209 it 'handles a automate profile with and without version' do210 config = InspecPlugins::Compliance::Configuration.new211 config.clean212 config['server_type'] = 'automate'213 config['server'] = 'https://myautomate'214 config['version'] = '1.6.99'215 InspecPlugins::Compliance::API.target_url(config, 'admin/apache-baseline').must_equal 'https://myautomate/profiles/admin/apache-baseline/tar'216 InspecPlugins::Compliance::API.target_url(config, 'admin/apache-baseline#2.0.2').must_equal 'https://myautomate/profiles/admin/apache-baseline/version/2.0.2/tar'217 end218 it 'handles a chef-compliance profile with and without version' do219 config = InspecPlugins::Compliance::Configuration.new220 config.clean221 config['server_type'] = 'compliance'222 config['server'] = 'https://mychefcompliance'223 config['version'] = '1.1.2'224 InspecPlugins::Compliance::API.target_url(config, 'admin/apache-baseline').must_equal 'https://mychefcompliance/owners/admin/compliance/apache-baseline/tar'225 InspecPlugins::Compliance::API.target_url(config, 'admin/apache-baseline#2.0.2').must_equal 'https://mychefcompliance/owners/admin/compliance/apache-baseline/tar'226 end227 end228 describe 'exist?' do229 it 'works with profiles returned by Automate' do230 # ruby 2.3.3 has issues running stub_requests properly231 # skipping for that specific version232 return if RUBY_VERSION = '2.3.3'233 config = InspecPlugins::Compliance::Configuration.new234 config.clean235 config['owner'] = 'admin'236 config['server_type'] = 'automate'237 config['server'] = 'https://myautomate'238 config['version'] = '1.6.99'239 config['automate'] = { 'ent'=>'automate', 'token_type'=>'dctoken' }240 config['version'] = { 'api'=> 'compliance', 'version'=>'0.8.24' }241 242 stub_request(:get, 'https://myautomate/profiles/admin')243 .with(headers: { 'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Chef-Delivery-Enterprise'=>'automate', 'User-Agent'=>'Ruby', 'X-Data-Collector-Token'=>'' })244 .to_return(status: 200, body: profiles_response.to_json, headers: {})245 InspecPlugins::Compliance::API.exist?(config, 'admin/apache-baseline').must_equal true246 InspecPlugins::Compliance::API.exist?(config, 'admin/apache-baseline#2.0.1').must_equal true247 InspecPlugins::Compliance::API.exist?(config, 'admin/apache-baseline#2.0.999').must_equal false248 InspecPlugins::Compliance::API.exist?(config, 'admin/missing-in-action').must_equal false...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!