Skip to content

Commit

Permalink
rubocop specs
Browse files Browse the repository at this point in the history
  • Loading branch information
h00die committed Dec 21, 2024
1 parent 262e4b8 commit 2e3661a
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 183 deletions.
159 changes: 79 additions & 80 deletions spec/lib/msf/core/post/linux/kernel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,104 @@
end

describe '#uname' do
context 'it returns an ubuntu kernel' do
it 'returns the kernel information' do
allow(subject).to receive(:cmd_exec).and_return('Linux kali 6.11.2-amd64 #1 SMP PREEMPT_DYNAMIC Kali 6.11.2-1kali1 (2024-10-15) x86_64 GNU/Linux ')
expect(subject.uname).to eq('Linux kali 6.11.2-amd64 #1 SMP PREEMPT_DYNAMIC Kali 6.11.2-1kali1 (2024-10-15) x86_64 GNU/Linux')
context 'it returns an ubuntu kernel' do
it 'returns the kernel information' do
allow(subject).to receive(:cmd_exec).and_return('Linux kali 6.11.2-amd64 #1 SMP PREEMPT_DYNAMIC Kali 6.11.2-1kali1 (2024-10-15) x86_64 GNU/Linux ')
expect(subject.uname).to eq('Linux kali 6.11.2-amd64 #1 SMP PREEMPT_DYNAMIC Kali 6.11.2-1kali1 (2024-10-15) x86_64 GNU/Linux')
end
end
end
end

describe '#kernel_release' do
context 'it returns an ubuntu kernel release' do
it 'returns 6.11.2-amd64' do
allow(subject).to receive(:cmd_exec).and_return('6.11.2-amd64 ')
expect(subject.kernel_release).to eq('6.11.2-amd64')
context 'it returns an ubuntu kernel release' do
it 'returns 6.11.2-amd64' do
allow(subject).to receive(:cmd_exec).and_return('6.11.2-amd64 ')
expect(subject.kernel_release).to eq('6.11.2-amd64')
end
end
end
end

describe '#kernel_version' do
context 'it returns an ubuntu kernel version' do
it 'returns 6.11.2-amd64' do
allow(subject).to receive(:cmd_exec).and_return('#1 SMP PREEMPT_DYNAMIC Kali 6.11.2-1kali1 (2024-10-15) ')
expect(subject.kernel_version).to eq('#1 SMP PREEMPT_DYNAMIC Kali 6.11.2-1kali1 (2024-10-15)')
context 'it returns an ubuntu kernel version' do
it 'returns 6.11.2-amd64' do
allow(subject).to receive(:cmd_exec).and_return('#1 SMP PREEMPT_DYNAMIC Kali 6.11.2-1kali1 (2024-10-15) ')
expect(subject.kernel_version).to eq('#1 SMP PREEMPT_DYNAMIC Kali 6.11.2-1kali1 (2024-10-15)')
end
end
end
end

describe '#kernel_name' do
context 'it returns an ubuntu kernel name' do
it 'returns Linux' do
allow(subject).to receive(:cmd_exec).and_return('Linux ')
expect(subject.kernel_name).to eq('Linux')
context 'it returns an ubuntu kernel name' do
it 'returns Linux' do
allow(subject).to receive(:cmd_exec).and_return('Linux ')
expect(subject.kernel_name).to eq('Linux')
end
end
end
end

describe '#kernel_hardware' do
context 'it returns an ubuntu kernel hardware' do
it 'returns x86_64' do
allow(subject).to receive(:cmd_exec).and_return('x86_64 ')
expect(subject.kernel_hardware).to eq('x86_64')
context 'it returns an ubuntu kernel hardware' do
it 'returns x86_64' do
allow(subject).to receive(:cmd_exec).and_return('x86_64 ')
expect(subject.kernel_hardware).to eq('x86_64')
end
end
end
end

describe '#kernel_arch' do
context 'it returns an ubuntu kernel arch' do
it 'returns x64' do
allow(subject).to receive(:cmd_exec).and_return('x86_64 ')
expect(subject.kernel_arch).to eq('x64')
end
it 'returns aarch64' do
allow(subject).to receive(:cmd_exec).and_return('aarch64 ')
expect(subject.kernel_arch).to eq('aarch64')
end
it 'returns aarch64' do
allow(subject).to receive(:cmd_exec).and_return('arm ')
expect(subject.kernel_arch).to eq('armle')
end
it 'returns x86' do
allow(subject).to receive(:cmd_exec).and_return('i686 ')
expect(subject.kernel_arch).to eq('x86')
end
it 'returns ppc' do
allow(subject).to receive(:cmd_exec).and_return('ppc ')
expect(subject.kernel_arch).to eq('ppc')
end
it 'returns ppc64' do
allow(subject).to receive(:cmd_exec).and_return('ppc64 ')
expect(subject.kernel_arch).to eq('ppc64')
context 'it returns an ubuntu kernel arch' do
it 'returns x64' do
allow(subject).to receive(:cmd_exec).and_return('x86_64 ')
expect(subject.kernel_arch).to eq('x64')
end
it 'returns aarch64' do
allow(subject).to receive(:cmd_exec).and_return('aarch64 ')
expect(subject.kernel_arch).to eq('aarch64')
end
it 'returns aarch64' do
allow(subject).to receive(:cmd_exec).and_return('arm ')
expect(subject.kernel_arch).to eq('armle')
end
it 'returns x86' do
allow(subject).to receive(:cmd_exec).and_return('i686 ')
expect(subject.kernel_arch).to eq('x86')
end
it 'returns ppc' do
allow(subject).to receive(:cmd_exec).and_return('ppc ')
expect(subject.kernel_arch).to eq('ppc')
end
it 'returns ppc64' do
allow(subject).to receive(:cmd_exec).and_return('ppc64 ')
expect(subject.kernel_arch).to eq('ppc64')
end
it 'returns ppc64le' do
allow(subject).to receive(:cmd_exec).and_return('ppc64le ')
expect(subject.kernel_arch).to eq('ppc64le')
end
it 'returns mips' do
allow(subject).to receive(:cmd_exec).and_return('mips ')
expect(subject.kernel_arch).to eq('mips')
end
it 'returns mips64' do
allow(subject).to receive(:cmd_exec).and_return('mips64 ')
expect(subject.kernel_arch).to eq('mips64')
end
it 'returns sparc' do
allow(subject).to receive(:cmd_exec).and_return('sparc ')
expect(subject.kernel_arch).to eq('sparc')
end
it 'returns riscv32le' do
allow(subject).to receive(:cmd_exec).and_return('riscv32 ')
expect(subject.kernel_arch).to eq('riscv32le')
end
it 'returns riscv64le' do
allow(subject).to receive(:cmd_exec).and_return('riscv64 ')
expect(subject.kernel_arch).to eq('riscv64le')
end
it 'returns loongarch64' do
allow(subject).to receive(:cmd_exec).and_return('loongarch64 ')
expect(subject.kernel_arch).to eq('loongarch64')
end
end
it 'returns ppc64le' do
allow(subject).to receive(:cmd_exec).and_return('ppc64le ')
expect(subject.kernel_arch).to eq('ppc64le')
end
it 'returns mips' do
allow(subject).to receive(:cmd_exec).and_return('mips ')
expect(subject.kernel_arch).to eq('mips')
end
it 'returns mips64' do
allow(subject).to receive(:cmd_exec).and_return('mips64 ')
expect(subject.kernel_arch).to eq('mips64')
end
it 'returns sparc' do
allow(subject).to receive(:cmd_exec).and_return('sparc ')
expect(subject.kernel_arch).to eq('sparc')
end
it 'returns riscv32le' do
allow(subject).to receive(:cmd_exec).and_return('riscv32 ')
expect(subject.kernel_arch).to eq('riscv32le')
end
it 'returns riscv64le' do
allow(subject).to receive(:cmd_exec).and_return('riscv64 ')
expect(subject.kernel_arch).to eq('riscv64le')
end
it 'returns loongarch64' do
allow(subject).to receive(:cmd_exec).and_return('loongarch64 ')
expect(subject.kernel_arch).to eq('loongarch64')
end

end
end
end
end
38 changes: 19 additions & 19 deletions spec/lib/msf/core/post/linux/packages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,72 @@
describe '#installed_package_version' do
context 'when the OS isnt supported' do
it 'returns nil' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"", :distro=>"unsupported", :version=>""})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: '', distro: 'unsupported', version: '' })
expect(subject.installed_package_version('test')).to be_nil
end
end

context 'when the Ubuntu/Debian package isnt installed' do
it 'returns nil' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"Linux ubuntu22 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux", :distro=>"ubuntu", :version=>"Ubuntu 22.04.5 LTS"})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: 'Linux ubuntu22 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux', distro: 'ubuntu', version: 'Ubuntu 22.04.5 LTS' })
allow(subject).to receive(:cmd_exec).and_return('dpkg-query: no packages found matching example')
expect(subject.installed_package_version('test')).to be_nil
end
end

context 'when the Ubuntu/Debian package is installed' do
it 'returns 3.5-5ubuntu2.1' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"Linux ubuntu22 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux", :distro=>"ubuntu", :version=>"Ubuntu 22.04.5 LTS"})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: 'Linux ubuntu22 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux', distro: 'ubuntu', version: 'Ubuntu 22.04.5 LTS' })
allow(subject).to receive(:cmd_exec).and_return('3.5-5ubuntu2.1')
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('3.5-5ubuntu2.1'))
end
end

context 'when the Ubuntu/Debian package is installed with a + in the version number' do
it 'returns 1.34.dfsg.pre.1ubuntu0.1.22.04.2' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"Linux ubuntu22 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux", :distro=>"ubuntu", :version=>"Ubuntu 22.04.5 LTS"})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: 'Linux ubuntu22 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux', distro: 'ubuntu', version: 'Ubuntu 22.04.5 LTS' })
allow(subject).to receive(:cmd_exec).and_return('1.34+dfsg-1ubuntu0.1.22.04.2')
expect(subject.installed_package_version('test')).to eq(Rex::Version.new("1.34.dfsg.pre.1ubuntu0.1.22.04.2"))
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('1.34.dfsg.pre.1ubuntu0.1.22.04.2'))
end
end

context 'when distro is redhat or fedora' do
it 'returns the package version' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"", :distro=>"redhat", :version=>""})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: '', distro: 'redhat', version: '' })
allow(subject).to receive(:cmd_exec).and_return('curl-8.2.1-3.fc39.x86_64')
expect(subject.installed_package_version('curl')).to eq(Rex::Version.new('8.2.1-3.fc39'))
expect(subject.installed_package_version('curl')).to eq(Rex::Version.new('8.2.1-3.fc39'))
end
end

context 'when distro is solaris' do
it 'returns the package version' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"", :distro=>"solaris", :version=>""})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: '', distro: 'solaris', version: '' })
allow(subject).to receive(:cmd_exec).and_return('State: Installed\nVersion: 1.2.3')
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('1.2.3'))
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('1.2.3'))
end
end

context 'when distro is freebsd' do
it 'returns the package version' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"", :distro=>"freebsd", :version=>""})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: '', distro: 'freebsd', version: '' })
allow(subject).to receive(:cmd_exec).and_return('Version : 1.2.3')
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('1.2.3'))
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('1.2.3'))
end
end

context 'when distro is gentoo' do
it 'returns the package version' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"", :distro=>"gentoo", :version=>""})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: '', distro: 'gentoo', version: '' })
allow(subject).to receive(:cmd_exec).and_return('sys-devel/gcc-4.3.2-r3')
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('4.3.2-r3'))
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('4.3.2-r3'))
end
end

context 'when distro is arch' do
it 'returns the package version' do
allow(subject).to receive(:get_sysinfo).and_return({:kernel=>"", :distro=>"arch", :version=>""})
allow(subject).to receive(:get_sysinfo).and_return({ kernel: '', distro: 'arch', version: '' })
allow(subject).to receive(:cmd_exec).and_return('Version : 1.2.3')
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('1.2.3'))
expect(subject.installed_package_version('test')).to eq(Rex::Version.new('1.2.3'))
end
end
end
Expand Down
Loading

0 comments on commit 2e3661a

Please sign in to comment.