Best Inspec_ruby code snippet using Inspec.valid
ssh_crypto.rb
Source:ssh_crypto.rb
2 name 'ssh_crypto'3 def ssh_version4 inspec.command('ssh -V 2>&1 | cut -f1 -d" " | cut -f2 -d"_"').stdout.to_f5 end6 def valid_ciphers7 # define a set of default ciphers8 ciphers53 = 'aes256-ctr,aes192-ctr,aes128-ctr'9 ciphers66 = 'chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr'10 ciphers = ciphers5311 # adjust ciphers based on OS + release12 case inspec.os[:name]13 when 'ubuntu'14 case inspec.os[:release]15 when '12.04'16 ciphers = ciphers5317 when '14.04', '15.10', '16.04', '18.04'18 ciphers = ciphers6619 end20 when 'debian'21 case inspec.os[:release]22 when /^6\./, /^7\./23 ciphers = ciphers5324 when /^8\./, /^9\./, /^10\./25 ciphers = ciphers6626 end27 when 'redhat', 'centos', 'oracle'28 case inspec.os[:release]29 when /^6\./30 ciphers = ciphers5331 when /^7\./, /^8\./32 ciphers = ciphers6633 end34 when 'amazon', 'fedora', 'alpine'35 ciphers = ciphers6636 when 'opensuse'37 case inspec.os[:release]38 when /^13\.2/39 ciphers = ciphers6640 when /^42\./41 ciphers = ciphers6642 end43 when 'mac_os_x'44 case inspec.os[:release]45 when /^10.9\./46 ciphers = ciphers5347 when /^10.10\./, /^10.11\./, /^10.12\./48 ciphers = ciphers6649 end50 end51 ciphers52 end53 def valid_kexs54 # define a set of default KEXs55 kex66 = 'curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256'56 kex59 = 'diffie-hellman-group-exchange-sha256'57 kex = kex5958 # adjust KEXs based on OS + release59 case inspec.os[:name]60 when 'ubuntu'61 case inspec.os[:release]62 when '12.04'63 kex = kex5964 when '14.04', '15.10', '16.04', '18.04'65 kex = kex6666 end67 when 'debian'68 case inspec.os[:release]69 when /^6\./70 kex = nil71 when /^7\./72 kex = kex5973 when /^8\./, /^9\./, /^10\./74 kex = kex6675 end76 when 'redhat', 'centos', 'oracle'77 case inspec.os[:release]78 when /^6\./79 kex = nil80 when /^7\./, /^8\./81 kex = kex6682 end83 when 'amazon', 'fedora', 'alpine'84 kex = kex6685 when 'opensuse'86 case inspec.os[:release]87 when /^13\.2/88 kex = kex6689 when /^42\./90 kex = kex6691 end92 when 'mac_os_x'93 case inspec.os[:release]94 when /^10.9\./95 kex = kex5996 when /^10.10\./, /^10.11\./, /^10.12\./97 kex = kex6698 end99 end100 kex101 end102 def valid_macs103 # define a set of default MACs104 macs66 = 'hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256'105 macs59 = 'hmac-sha2-512,hmac-sha2-256,hmac-ripemd160'106 macs53 = 'hmac-ripemd160,hmac-sha1'107 macs53_el65 = 'hmac-sha2-512,hmac-sha2-256'108 macs = macs59109 # adjust MACs based on OS + release110 case inspec.os[:name]111 when 'ubuntu'112 case inspec.os[:release]113 when '12.04'114 macs = macs59115 when '14.04', '15.10', '16.04', '18.04'116 macs = macs66117 end118 when 'debian'119 case inspec.os[:release]120 when /^6\./121 macs = macs53122 when /^7\./123 macs = macs59124 when /^8\./, /^9\./, /^10\./125 macs = macs66126 end127 when 'redhat', 'centos', 'oracle'128 case inspec.os[:release]129 when /^6\./130 # RedHat Enterprise Linux (and family) backported SHA2 support to their fork of OpenSSH 5.3 in RHEL 6.5.131 # See BZ#969565 at:132 # https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html-single/6.5_technical_notes/index#openssh133 # Because extended support (EUS) updates for 6.x minor releases is no longer available,134 # only the settings available for the supported (latest) 6.x release are recommended.135 macs = macs53_el65136 when /^7\./, /^8\./137 macs = macs66138 end139 when 'amazon', 'fedora', 'alpine'140 macs = macs66141 when 'opensuse'142 case inspec.os[:release]143 when /^13\.2/144 macs = macs66145 when /^42\./146 macs = macs66147 end148 when 'mac_os_x'149 case inspec.os[:release]150 when /^10.9\./151 macs = macs59152 when /^10.10\./, /^10.11\./, /^10.12\./153 macs = macs66154 end155 end156 macs157 end158 def valid_privseparation159 # define privilege separation set160 ps53 = 'yes'161 ps59 = 'sandbox'162 ps75 = nil163 ps = ps59164 # debian 7.x and newer has ssh 5.9+165 # ubuntu 12.04 and newer has ssh 5.9+166 case inspec.os[:name]167 when 'debian'168 case inspec.os[:release]169 when /^6\./170 ps = ps53171 when /^10\./172 ps = ps75173 end174 when 'redhat', 'centos', 'oracle'175 case inspec.os[:release]176 # redhat/centos/oracle 6.x has ssh 5.3177 when /^6\./178 ps = ps53179 when /^7\./180 ps = ps59181 when /^8\./182 ps = ps75183 end184 when 'ubuntu'185 case inspec.os[:release]186 when /^18\./187 ps = ps75188 end189 when 'fedora', 'alpine'190 ps = ps75191 end192 ps193 end194 # return a list of valid algoriths for a current platform195 def valid_algorithms196 alg53 = %w(rsa)197 alg60 = %w(rsa ecdsa)198 alg66 = %w(rsa ecdsa ed25519)199 alg = alg66 # probably its a best suitable set for everything unknown200 case inspec.os[:name]201 when 'ubuntu'202 case inspec.os[:release]203 when '12.04'204 alg = alg53205 when '14.04', '15.10', '16.04', '18.04'206 alg = alg66207 end208 when 'debian'209 case inspec.os[:release]210 when /^7\./211 alg = alg60212 when /^8\./, /^9\./213 alg = alg66214 end215 when 'redhat', 'centos', 'oracle'216 case inspec.os[:release]217 when /^6\./218 alg = alg53219 when /^7\./220 alg = alg66221 end222 when 'amazon', 'fedora', 'alpine'223 alg = alg66224 when 'opensuse'225 case inspec.os[:release]226 when /^13\.2/227 alg = alg66228 when /^42\./229 alg = alg66230 end231 when 'mac_os_x'232 case inspec.os[:release]233 when /^10.9\./234 alg53235 when /^10.10\./, /^10.11\./, /^10.12\./236 alg66237 end238 end239 alg240 end241 # returns the hostkeys value based on valid_algorithms242 def valid_hostkeys243 hostkeys = valid_algorithms.map { |alg| "/etc/ssh/ssh_host_#{alg}_key" }244 # its('HostKey') provides a string for a single-element value.245 # we have to return a string if we have a single-element246 # https://github.com/chef/inspec/issues/1434247 return hostkeys[0] if hostkeys.length == 1248 hostkeys249 end250end...
valid
Using AI Code Generation
1 it { should be_valid }2 it { should be_valid }3 it { should be_valid }4 it { should be_valid }5 it { should be_valid }6 it { should be_valid }7 it { should be_valid }8 it { should be_valid }9 it { should be_valid }10 it { should be_valid }11 it { should be_valid }12 it { should be_valid }13 it { should be_valid }14 it { should be_valid }15 it { should be_valid }16 it { should be_valid }
valid
Using AI Code Generation
1describe file('/etc/passwd') do2 it { should exist }3describe file('/etc/passwd') do4 it { should exist }5describe file('/etc/passwd') do6 it { should exist }7describe file('/etc/passwd') do8 it { should exist }9describe file('/etc/passwd') do10 it { should exist }11describe file('/etc/passwd') do12 it { should exist }13describe file('/etc/passwd') do14 it { should exist }15describe file('/etc/passwd') do16 it { should exist }17describe file('/etc/passwd') do18 it { should exist }19describe file('/etc/passwd') do20 it { should exist }21describe file('/etc/passwd') do22 it { should exist }23describe file('/etc/passwd') do24 it { should exist }25describe file('/etc/passwd') do26 it { should exist }27describe file('/etc/passwd') do28 it { should exist }29describe file('/etc/passwd') do
valid
Using AI Code Generation
1describe file('/tmp/1.txt') do2 it { should be_file }3describe file('/tmp/2.txt') do4 it { should be_file }5describe file('/tmp/3.txt') do6 it { should be_file }7describe file('/tmp/4.txt') do8 it { should be_file }9describe file('/tmp/5.txt') do10 it { should be_file }11describe file('/tmp/6.txt') do12 it { should be_file }13describe file('/tmp/7.txt') do14 it { should be_file }15describe file('/tmp/8.txt') do16 it { should be_file }17describe file('/tmp/9.txt') do18 it { should be_file }19describe file('/tmp/10.txt') do20 it { should be_file }21describe file('/tmp/11.txt') do22 it { should be_file }23describe file('/tmp/12.txt') do24 it { should be_file }25describe file('/tmp/13.txt') do26 it { should be_file }27describe file('/tmp/14.txt') do28 it { should be_file }
valid
Using AI Code Generation
1describe file('1.rb') do2 its('content') { should match(/valid\(\)/) }3describe file('2.rb') do4 its('content') { should match(/invalid\(\)/) }5describe file('3.rb') do6 its('content') { should match(/valid\(\)/) }7describe file('4.rb') do8 its('content') { should match(/invalid\(\)/) }9describe file('5.rb') do10 its('content') { should match(/valid\(\)/) }11describe file('6.rb') do12 its('content') { should match(/invalid\(\)/) }13describe file('7.rb') do14 its('content') { should match(/valid\(\)/) }15describe file('8.rb') do16 its('content') { should match(/invalid\(\)/) }17describe file('9.rb') do18 its('content') { should match(/valid\(\)/) }19describe file('10.rb') do20 its('content') { should match(/invalid\(\)/) }21describe file('11.rb') do22 its('content') { should match(/valid\(\)/) }23describe file('12.rb') do24 its('content') { should match(/invalid\(\)/) }
valid
Using AI Code Generation
1 expect('foo').to eq('foo')2 expect('foo').to eq('foo')3 expect('foo').to eq('foo')4 expect('foo').to eq('foo')5 expect('foo').to eq('foo')6 expect('foo').to eq('foo')7 expect('foo').to eq('foo')8 expect('foo').to eq('foo')9 expect('foo').to eq('foo')
valid
Using AI Code Generation
1describe file('test.txt') do2 its('content') { should match /hello/ }3describe file('test.txt') do4 its('content') { should match /hello/ }5describe file('test.txt') do6 its('content') { should match /hello/ }7describe file('test.txt') do8 its('content') { should match /hello/ }9describe file('test.txt') do10 its('content') { should match /hello/ }11describe file('test.txt') do12 its('content') { should match /hello/ }13describe file('test.txt') do14 its('content') { should match /hello/ }15describe file('test.txt') do16 its('content') { should match /hello/ }17describe file('test.txt') do18 its('content') { should match /hello/ }19describe file('test.txt') do20 its('content') { should match /hello/ }
valid
Using AI Code Generation
1describe file('/etc/passwd') do2 it { should exist }3describe file('/etc/passwd') do4 it { should exist }5describe file('/etc/passwd') do6 it { should exist }7describe file('/etc/passwd') do8 it { should exist }9describe file('/etc/passwd') do10 it { should exist }11describe file('/etc/passwd') do12 it { should exist }13describe file('/etc/passwd') do14 it { should exist }15describe file('/etc/passwd') do16 it { should exist }17describe file('/etc/passwd') do18 it { should exist }19describe file('/etc/passwd') do20 it { should exist }21describe file('/etc/passwd') do22 it { should exist }23describe file('/etc/passwd') do24 it { should exist }25describe file('/etc/passwd') do26 it { should exist }27describe file('/etc/passwd') do28 it { should exist }29describe file('/etc/passwd') do
valid
Using AI Code Generation
1describe file('/tmp/1.txt') do2 it { should be_file }3describe file('/tmp/2.txt') do4 it { should be_file }5describe file('/tmp/3.txt') do6 it { should be_file }7describe file('/tmp/4.txt') do8 it { should be_file }9describe file('/tmp/5.txt') do10 it { should be_file }11describe file('/tmp/6.txt') do12 it { should be_file }13describe file('/tmp/7.txt') do14 it { should be_file }15describe file('/tmp/8.txt') do16 it { should be_file }17describe file('/tmp/9.txt') do18 it { should be_file }19describe file('/tmp/10.txt') do20 it { should be_file }21describe file('/tmp/11.txt') do22 it { should be_file }23describe file('/tmp/12.txt') do24 it { should be_file }25describe file('/tmp/13.txt') do26 it { should be_file }27describe file('/tmp/14.txt') do28 it { should be_file }
valid
Using AI Code Generation
1describe file('1.rb') do2 its('content') { should match(/valid\(\)/) }3describe file('2.rb') do4 its('content') { should match(/invalid\(\)/) }5describe file('3.rb') do6 its('content') { should match(/valid\(\)/) }7describe file('4.rb') do8 its('content') { should match(/invalid\(\)/) }9describe file('5.rb') do10 its('content') { should match(/valid\(\)/) }11describe file('6.rb') do12 its('content') { should match(/invalid\(\)/) }13describe file('7.rb') do14 its('content') { should match(/valid\(\)/) }15describe file('8.rb') do16 its('content') { should match(/invalid\(\)/) }17describe file('9.rb') do18 its('content') { should match(/valid\(\)/) }19describe file('10.rb') do20 its('content') { should match(/invalid\(\)/) }21describe file('11.rb') do22 its('content') { should match(/valid\(\)/) }23describe file('12.rb') do24 its('content') { should match(/invalid\(\)/) }
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!!