Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/proto/postgresql/client_spec.rb
Views: 11789
# -*- coding: binary -*-12require 'spec_helper'3require 'postgres/postgres-pr/connection'45RSpec.describe Msf::Db::PostgresPR::Connection do6let(:host) { '127.0.0.1' }7let(:port) { 1234 }8let(:info) { "#{host}:#{port}" }9let(:db_name) { 'my_db_name' }10let(:socket) { double(Rex::Socket, peerhost: host, peerport: port) }11let(:message) { Msf::Db::PostgresPR::ReadyForQuery.new('') }1213subject do14allow(socket).to receive(:<<)15allow(Msf::Db::PostgresPR::Message).to receive(:read).and_return(message)16allow(Rex::Socket).to receive(:create).and_return(socket)17client = described_class.new(db_name, 'username', 'password', "tcp://#{host}:#{port}")18client19end2021it_behaves_like 'session compatible SQL client'2223describe '#map_compile_os_to_platform' do24[25{ info: 'linux', expected: Msf::Platform::Linux.realname },26{ info: 'linux2.6', expected: Msf::Platform::Linux.realname },27{ info: 'debian-linux-gnu', expected: Msf::Platform::Linux.realname },28{ info: 'win', expected: Msf::Platform::Windows.realname },29{ info: 'windows', expected: Msf::Platform::Windows.realname },30{ info: 'darwin', expected: Msf::Platform::OSX.realname },31{ info: 'osx', expected: Msf::Platform::OSX.realname },32{ info: 'macos', expected: Msf::Platform::OSX.realname },33{ info: 'solaris', expected: Msf::Platform::Solaris.realname },34{ info: 'aix', expected: Msf::Platform::AIX.realname },35{ info: 'hpux', expected: Msf::Platform::HPUX.realname },36{ info: 'irix', expected: Msf::Platform::Irix.realname },37].each do |test|38it "correctly identifies '#{test[:info]}' as '#{test[:expected]}'" do39expect(subject.map_compile_os_to_platform(test[:info])).to eq(test[:expected])40end41end42end4344describe '#map_compile_arch_to_architecture' do45[46{ info: 'x86_64', expected: ARCH_X86_64 },47{ info: 'x86_x64', expected: ARCH_X86_64 },48{ info: 'x64', expected: ARCH_X86_64 },49{ info: '64', expected: ARCH_X86_64 },50{ info: 'x86', expected: ARCH_X86 },51{ info: '86', expected: ARCH_X86 },52{ info: 'i686', expected: ARCH_X86 },53{ info: 'arm64', expected: ARCH_AARCH64 },54{ info: 'arm', expected: ARCH_ARMLE },55{ info: 'sparc', expected: ARCH_SPARC },56{ info: 'sparc64', expected: ARCH_SPARC64 },57{ info: 'ppc', expected: ARCH_PPC },58{ info: 'mips', expected: ARCH_MIPS },59].each do |test|60it "correctly identifies '#{test[:info]}' as '#{test[:expected]}'" do61expect(subject.map_compile_arch_to_architecture(test[:info])).to eq(test[:expected])62end63end64end6566describe '#detect_platform_and_arch' do67[68{ version: 'PostgreSQL 9.4.26 on x86_64-pc-linux-gnu (Debian 9.4.26-1.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit', expected: { arch: 'x86_64', platform: 'Linux' } },69{ version: 'PostgreSQL 14.11 (Debian 14.11-1.pgdg120+2) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit', expected: { arch: 'x86_64', platform: 'Linux' } },70{ version: 'PostgreSQL 14.11 (Homebrew) on x86_64-apple-darwin22.6.0, compiled by Apple clang version 15.0.0 (clang-1500.1.0.2.5), 64-bit', expected: { arch: 'x86_64', platform: 'OSX' } },71{72version: 'PostgreSQL 14.11 (Homebrew) <arch>-<platform>, compiled by <platform> clang version 15.0.0 (clang-1500.1.0.2.5), <arch>',73expected: {74arch: 'postgresql 14.11 (homebrew) <arch>-<platform>, compiled by <platform> clang version 15.0.0 (clang-1500.1.0.2.5), <arch>',75platform: 'postgresql 14.11 (homebrew) <arch>-<platform>, compiled by <platform> clang version 15.0.0 (clang-1500.1.0.2.5), <arch>'76}77}78].each do |test|79context "when the database is version #{test[:version]}" do80it "returns #{test[:expected]}" do81mock_query_result = instance_double Msf::Db::PostgresPR::Connection::Result, rows: [[test[:version]]]82allow(subject).to receive(:query).with('select version()').and_return(mock_query_result)8384expect(subject.detect_platform_and_arch).to eq test[:expected]85end86end87end88end89end909192