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/nuuo/client_request_spec.rb
Views: 11789
# -*- coding:binary -*-12RSpec.describe Rex::Proto::Nuuo::ClientRequest do3subject(:client_request) {4opts = {5'user_session' => user_session,6'headers' => headers_hash,7'data' => data8}9described_class.new(opts)10}11let(:user_session) {nil}12let(:headers_hash) {{}}13let(:data) {nil}1415describe '#to_s' do16context 'given no additional options' do17it 'returns a USERLOGIN request' do18expect(client_request.to_s).to eq("USERLOGIN NUCM/1.0\r\n\r\n")19end20end2122context 'given a headers hash' do23let(:headers_hash) {{24'TestHeader' => 'TestValue',25'TestHeader1' => 'TestValue1'26}}27it 'dumps the headers after the method line' do28expect(client_request.to_s).to eq("USERLOGIN NUCM/1.0\r\nTestHeader: TestValue\r\nTestHeader1: TestValue1\r\n\r\n")29end30end3132context 'given a user_session and User-Session-No header' do33let(:user_session) {'0'}34let(:headers_hash) {{'User-Session-No' => '1'}}3536it 'prefers the User-Session-No in the headers hash' do37expect(client_request.to_s).to eq("USERLOGIN NUCM/1.0\r\nUser-Session-No: 1\r\n\r\n")38end39end40end4142describe '#set_method' do43it 'returns the method variable' do44expect(client_request.set_method).to eq('USERLOGIN')45end46end4748describe '#set_proto_version' do49it 'returns the protocol and version separated by /' do50expect(client_request.set_proto_version).to eq("NUCM/1.0\r\n")51end52end535455describe '#set_header' do5657context 'given no user session number' do58let(:user_session) {nil}5960it 'returns an empty header' do61expect(client_request.set_header('user_session', 'User-Session-No')).to eq('')62end63end6465context 'given user session number' do66let(:user_session) {'987'}6768it 'returns a User-Session-No header' do69expect(client_request.set_header('user_session', 'User-Session-No')).to eq("User-Session-No: 987\r\n")70end71end7273context 'given a nonexistent key' do74it 'returns an empty header' do75expect(client_request.set_header('DoesNotExist', 'DoesNotExist')).to eq('')76end77end7879context 'given a key specified in the headers hash' do80let(:user_session) {'987'}81let(:headers_hash) {{'User-Session-No' => '1000'}}8283it 'returns an empty header' do84expect(client_request.set_header('user_session', 'User-Session-No')).to eq('')85end86end8788end8990describe '#set_extra_headers' do91context 'given an empty headers hash' do92it 'returns an empty string' do93expect(client_request.set_extra_headers).to eq('')94end95end9697context 'given a headers hash' do98let(:headers_hash) {{99'Header' => 'Value',100'Another' => 'One'101}}102103it 'returns formatted headers' do104expect(client_request.set_extra_headers).to eq("Header: Value\r\nAnother: One\r\n")105end106end107end108109describe '#set_body' do110context 'given an empty body variable' do111it 'returns \r\n' do112expect(client_request.set_body).to eq("\r\n")113end114end115116context 'given body content' do117let(:data) {"test data"}118119it 'returns \r\n followed by the body content' do120expect(client_request.set_body).to eq("\r\ntest data")121end122end123end124125describe '#set_formatted_header' do126let(:name) {'HeaderName'}127let(:value) {'HeaderValue'}128129it 'creates a request header' do130expect(subject.set_formatted_header(name, value)).to eq("HeaderName: HeaderValue\r\n")131end132end133end134135136