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/ldap/client_spec.rb
Views: 11788
# -*- coding: binary -*-12require 'spec_helper'3require 'rex/proto/ldap/client'45RSpec.describe Rex::Proto::LDAP::Client do6let(:host) { '127.0.0.1' }7let(:port) { 1234 }8let(:info) { "#{host}:#{port}" }910subject do11client = described_class.new(host: host, port: port)12client13end1415it_behaves_like 'session compatible client'1617let(:base_dn) { 'DC=ldap,DC=example,DC=com' }18let(:schema_dn) { 'CN=Schema,CN=Configuration,DC=ldap,DC=example,DC=com' }1920let(:root_dse_result_ldif) do21"dn: \n" \22"namingcontexts: #{base_dn}\n" \23"namingcontexts: CN=Configuration,DC=ldap,DC=example,DC=com\n" \24"namingcontexts: CN=Schema,CN=Configuration,DC=ldap,DC=example,DC=com\n" \25"namingcontexts: DC=DomainDnsZones,DC=ldap,DC=example,DC=com\n" \26"namingcontexts: DC=ForestDnsZones,DC=ldap,DC=example,DC=com\n" \27"supportedldapversion: 2\n" \28"supportedldapversion: 3\n" \29"supportedsaslmechanisms: GSS-SPNEGO\n" \30"supportedsaslmechanisms: GSSAPI\n" \31"supportedsaslmechanisms: NTLM\n"32end3334let(:schema_naming_context) do35"dn: \n" \36"schemanamingcontext: #{schema_dn}\n"37end3839let(:empty_response) do40"dn: \n"41end4243let(:schema_naming_context_result) do44root_dse_dataset = Net::LDAP::Dataset.read_ldif(StringIO.new(schema_naming_context))45root_dse_dataset.to_entries46end4748let(:root_dse_result) do49root_dse_dataset = Net::LDAP::Dataset.read_ldif(StringIO.new(root_dse_result_ldif))50root_dse_dataset.to_entries[0]51end5253let(:empty_response_result) do54root_dse_dataset = Net::LDAP::Dataset.read_ldif(StringIO.new(empty_response))55root_dse_dataset.to_entries56end5758describe '#naming_contexts' do5960before(:each) do61allow(subject).to receive(:search_root_dse).and_return(root_dse_result)62end6364it 'should cache the result' do65expect(subject).to receive(:search_root_dse)66subject.naming_contexts67expect(subject).not_to receive(:search_root_dse)68subject.naming_contexts69end7071context 'when no naming contexts are available' do72let(:root_dse_result_ldif) do73"dn: \n" \74"supportedldapversion: 2\n" \75"supportedldapversion: 3\n" \76"supportedsaslmechanisms: GSS-SPNEGO\n" \77"supportedsaslmechanisms: GSSAPI\n" \78"supportedsaslmechanisms: NTLM\n"79end8081it 'returns an empty array' do82expect(subject.naming_contexts).to be_empty83end84end8586context 'when naming contexts are available' do87it 'contains naming contexts' do88expect(subject.naming_contexts).not_to be_empty89end90end91end9293describe '#base_dn' do9495before(:each) do96allow(subject).to receive(:search_root_dse).and_return(root_dse_result)97end9899it 'should cache the result' do100expect(subject).to receive(:discover_base_dn).and_call_original101subject.base_dn102expect(subject).not_to receive(:discover_base_dn)103subject.base_dn104end105106context 'when no naming contexts are available' do107let(:root_dse_result_ldif) do108"dn: \n" \109"supportedldapversion: 2\n" \110"supportedldapversion: 3\n" \111"supportedsaslmechanisms: GSS-SPNEGO\n" \112"supportedsaslmechanisms: GSSAPI\n" \113"supportedsaslmechanisms: NTLM\n"114end115116it 'should not find the base dn' do117expect(subject.base_dn).to be_nil118end119end120121context 'when naming contexts are available' do122it 'contains naming contexts' do123expect(subject.base_dn).to eql(base_dn)124end125end126end127128describe '#schema_dn' do129130before(:each) do131allow(subject).to receive(:search).and_return(schema_naming_context_result)132end133134it 'should cache the result' do135expect(subject).to receive(:discover_schema_naming_context).and_call_original136subject.schema_dn137expect(subject).not_to receive(:discover_schema_naming_context)138subject.schema_dn139end140141context 'when the response does not contain the schema_dn' do142before(:each) do143allow(subject).to receive(:search).and_return(empty_response_result)144end145146it 'does not find the schema_dn' do147expect(subject.schema_dn).to be_nil148end149end150151context 'when the response does contain the schema_dn' do152it 'finds the schema_dn' do153expect(subject.schema_dn).to eql(schema_dn)154end155end156end157end158159160