CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/proto/mysql/client_spec.rb
Views: 11788
1
# -*- coding: binary -*-
2
3
require 'spec_helper'
4
require 'rex/proto/mysql/client'
5
6
RSpec.describe Rex::Proto::MySQL::Client do
7
let(:host) { '127.0.0.1' }
8
let(:port) { 1234 }
9
let(:info) { "#{host}:#{port}" }
10
let(:db_name) { 'my_db_name' }
11
12
subject do
13
addr_info = instance_double(Addrinfo, ip_address: host, ip_port: port)
14
socket = instance_double(Socket, remote_address: addr_info)
15
client = described_class.new(io: socket)
16
allow(client).to receive(:session_track).and_return({ 1 => [db_name] })
17
client
18
end
19
20
it { is_expected.to be_a ::Mysql }
21
22
it_behaves_like 'session compatible SQL client'
23
24
describe '#current_database' do
25
context 'we have not selected a database yet' do
26
before(:each) do
27
allow(subject).to receive(:session_track).and_return({})
28
end
29
30
it 'returns an empty database name' do
31
expect(subject.current_database).to eq('')
32
end
33
end
34
end
35
36
describe '#map_compile_os_to_platform' do
37
[
38
{ info: 'linux', expected: Msf::Platform::Linux.realname },
39
{ info: 'linux2.6', expected: Msf::Platform::Linux.realname },
40
{ info: 'debian-linux-gnu', expected: Msf::Platform::Linux.realname },
41
{ info: 'win', expected: Msf::Platform::Windows.realname },
42
{ info: 'windows', expected: Msf::Platform::Windows.realname },
43
{ info: 'darwin', expected: Msf::Platform::OSX.realname },
44
{ info: 'osx', expected: Msf::Platform::OSX.realname },
45
{ info: 'macos', expected: Msf::Platform::OSX.realname },
46
{ info: 'unix', expected: Msf::Platform::Unix.realname },
47
{ info: 'solaris', expected: Msf::Platform::Solaris.realname },
48
{ info: '', expected: '' },
49
{ info: 'blank', expected: 'blank' },
50
{ info: nil, expected: '' },
51
].each do |test|
52
it "correctly identifies '#{test[:info]}' as '#{test[:expected]}'" do
53
expect(subject.map_compile_os_to_platform(test[:info])).to eq(test[:expected])
54
end
55
end
56
end
57
58
describe '#map_compile_arch_to_architecture' do
59
[
60
{ info: 'x86_64', expected: ARCH_X86_64 },
61
{ info: 'x86_x64', expected: ARCH_X86_64 },
62
{ info: 'x64', expected: ARCH_X86_64 },
63
{ info: '64', expected: ARCH_X86_64 },
64
{ info: 'x86', expected: ARCH_X86 },
65
{ info: '86', expected: ARCH_X86 },
66
{ info: 'i686', expected: ARCH_X86 },
67
{ info: 'arm64', expected: ARCH_AARCH64 },
68
{ info: 'arm', expected: ARCH_ARMLE },
69
{ info: 'sparc', expected: ARCH_SPARC },
70
{ info: 'sparc64', expected: ARCH_SPARC64 },
71
{ info: '', expected: '' },
72
{ info: 'blank', expected: 'blank' },
73
{ info: nil, expected: '' },
74
].each do |test|
75
it "correctly identifies '#{test[:info]}' as '#{test[:expected]}'" do
76
expect(subject.map_compile_arch_to_architecture(test[:info])).to eq(test[:expected])
77
end
78
end
79
end
80
end
81
82