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/mssql/client_spec.rb
Views: 11789
# -*- coding: binary -*-12require 'spec_helper'3require 'rex/proto/mysql/client'45RSpec.describe Rex::Proto::MSSQL::Client do6let(:host) { '127.0.0.1' }7let(:port) { 1234 }8let(:info) { "#{host}:#{port}" }9let(:db_name) { 'my_db_name' }10let(:framework_module) { ::Msf::Module.new }1112subject do13client = described_class.new(framework_module, nil, host, port)14client.current_database = db_name15client16end1718it_behaves_like 'session compatible SQL client'1920describe '#map_compile_os_to_platform' do21[22{ info: 'linux', expected: Msf::Platform::Linux.realname },23{ info: 'windows', expected: Msf::Platform::Windows.realname },24{ info: 'win', expected: Msf::Platform::Windows.realname },25].each do |test|26it "correctly identifies '#{test[:info]}' as '#{test[:expected]}'" do27expect(subject.map_compile_os_to_platform(test[:info])).to eq(test[:expected])28end29end30end3132describe '#map_compile_arch_to_architecture' do33[34{ info: 'x64', expected: ARCH_X86_64 },35{ info: 'x86', expected: ARCH_X86 },36{ info: '64', expected: ARCH_X86_64 },37{ info: '32-bit', expected: ARCH_X86 },38].each do |test|39it "correctly identifies '#{test[:info]}' as '#{test[:expected]}'" do40expect(subject.map_compile_arch_to_architecture(test[:info])).to eq(test[:expected])41end42end43end4445describe '#detect_platform_and_arch' do46[47{ version: 'Microsoft SQL Server 2022 (RTM-CU12) (KB5033663) - 16.0.4115.5 (X64) Mar 4 2024 08:56:10 Copyright (C) 2022 Microsoft Corporation Developer Edition (64-bit) on Linux (Ubuntu 22.04.4 LTS) <X64>', expected: { arch: 'x86_64', platform: 'Linux' } },48{ version: 'Microsoft SQL Server 2022 (RTM) - 16.0.1000.6 (X64) Oct 8 2022 05:58:25 Copyright (C) 2022 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2022 Standard 10.0 <X64> (Build 20348: ) (Hypervisor)', expected: { arch: 'x86_64', platform: 'Windows' } },49{ version: 'Microsoft SQL Server 2022 (RTM) - 16.0.1000.6 (32) Oct 8 2022 05:58:25 Copyright (C) 2022 Microsoft Corporation Developer Edition (2-bit) on Mac Standard 10.0 <??> (Build 20348: ) (Hypervisor)', expected: { arch: '32', platform: 'mac' } },50{ version: 'unknown', expected: { arch: 'unknown', platform: 'unknown' } },51].each do |test|52context "when the database is version #{test[:version]}" do53it "returns #{test[:expected]}" do54mock_query_result = { rows: [[test[:version]]] }55allow(subject).to receive(:query).with('select @@version').and_return(mock_query_result)5657expect(subject.detect_platform_and_arch).to eq test[:expected]58end59end60end61end62describe '#current_database' do63context 'we have not selected a database yet' do64subject do65described_class.new(framework_module, nil, host, port)66end6768it 'returns an empty database name' do69expect(subject.current_database).to eq('')70end71end72end7374context '#parse_prelogin_response' do75let(:buf) { "\x00\x00\x15\x00\x06\x01\x00\e\x00\x01\x02\x00\x1C\x00\x01\x03\x00\x1D\x00\x00\xFF\x10\x00\x03\xE8\x00\x00\x02\x00" }76let(:client) { Rex::Proto::MSSQL::Client.allocate }7778it 'correctly parses a prelogin response' do79result = client.parse_prelogin_response(buf)80expect(result).to eq({ version: '16.0.1000', encryption: 2 })81end82end83end848586