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/postgres/postgres-pr/message_spec.rb
Views: 11784
require 'postgres/postgres-pr/message'12RSpec.describe Msf::Db::PostgresPR::Message do3let(:mock_socket_clazz) do4Class.new do5include Rex::IO::Stream67def initialize(data)8@read_data = data || ''9end1011def read(n, _opts = {})12result, remaining = @read_data[0...n], @read_data[n..-1]13@read_data = remaining14result15end16end17end1819def mock_socket(data)20mock_socket_clazz.new(data)21end2223describe '.read' do24let(:startup) { false }25let(:stream_bytes) { '' }26let(:result) { described_class.read(mock_socket(stream_bytes), startup) }2728context 'when reading a SASL authentication message' do29# Offered SASL mechanisms30let(:stream_bytes) { "R\x00\x00\x00\x17\x00\x00\x00\nSCRAM-SHA-256\x00\x00".b }3132it 'parses a SCRAM-SHA-256 message' do33expect(result).to be_a(Msf::Db::PostgresPR::AuthenticationSASL)34expect(result.mechanisms).to eq(['SCRAM-SHA-256'])35expect(result.dump).to eq(stream_bytes)36end37end3839context 'when reading a SASL continue message' do40# First SCRAM-SHA-256 server message41# https://datatracker.ietf.org/doc/html/rfc7677#section-342let(:stream_bytes) do43"R\x00\x00\x00\\\x00\x00\x00\vr=2kRpTcHEFyoG+UgDEpRBdVcJLTWh5WtxARhYOHcG27i7YxAi,s=GNpgixWS5E4INbrMf665Kw==,i=4096".b44end4546it 'parses a generic SASL message' do47expect(result).to be_a(Msf::Db::PostgresPR::AuthenticationSASLContinue)48expect(result.value).to eq('r=2kRpTcHEFyoG+UgDEpRBdVcJLTWh5WtxARhYOHcG27i7YxAi,s=GNpgixWS5E4INbrMf665Kw==,i=4096')49expect(result.dump).to eq(stream_bytes)50end51end5253context 'when reading a SASL final message' do54# Final SCRAM-SHA-256 server message55# https://datatracker.ietf.org/doc/html/rfc7677#section-356let(:stream_bytes) do57"R\x00\x00\x006\x00\x00\x00\fv=b10lbmDELI8EHr/DM47cmcVcwn2n4TgQC4d1gaE6QHI=".b58end5960it 'parses a generic SASL message' do61expect(result).to be_a(Msf::Db::PostgresPR::AuthenticationSASLFinal)62expect(result.value).to eq('v=b10lbmDELI8EHr/DM47cmcVcwn2n4TgQC4d1gaE6QHI=')63expect(result.dump).to eq(stream_bytes)64end65end66end6768describe Msf::Db::PostgresPR::SASLResponseMessage do69# Final SCRAM-SHA-256 client message70# https://datatracker.ietf.org/doc/html/rfc7677#section-371let(:stream_bytes) do72"p\x00\x00\x00lc=biws,r=8P6L/8Vv+sEUZitMm7hnoNppbiGwnpKXKGXU1HqFPGjD6gtm,p=lpmyxOY7t6U+um1eCG/LLGS0fiFsieTgDv0EwJ8etso=".b73end7475describe '#parse' do76it 'parses the value' do77subject.parse(Msf::Db::Buffer.new(stream_bytes))78expect(subject).to be_a(described_class)79expect(subject.value).to eq('c=biws,r=8P6L/8Vv+sEUZitMm7hnoNppbiGwnpKXKGXU1HqFPGjD6gtm,p=lpmyxOY7t6U+um1eCG/LLGS0fiFsieTgDv0EwJ8etso=')80end81end8283describe '#dump' do84it 'dumps the value' do85subject.parse(Msf::Db::Buffer.new(stream_bytes))86expect(subject.dump).to eq(stream_bytes)87end88end89end90end919293