spec/dap/proto/ldap_proto_spec.rb in dap-0.0.9 vs spec/dap/proto/ldap_proto_spec.rb in dap-0.0.10

- old
+ new

@@ -2,10 +2,11 @@ subject { described_class } describe '.decode_elem_length' do context 'testing lengths shorter than 128 bits' do data = ['301402'].pack('H*') + let(:decode_len) { subject.decode_elem_length(data) } it 'returns a Fixnum' do expect(decode_len.class).to eq(::Fixnum) end it 'returns value correctly' do @@ -13,21 +14,35 @@ end end context 'testing lengths greater than 128 bits' do data = ['308400000bc102010'].pack('H*') + let(:decode_len) { subject.decode_elem_length(data) } it 'returns a Fixnum' do expect(decode_len.class).to eq(::Fixnum) end it 'returns value correctly' do expect(decode_len).to eq(3015) end end + context 'testing with 3 byte length' do + data = ['3083015e0802010764'].pack('H*') + + let(:decode_len) { subject.decode_elem_length(data) } + it 'returns a Fixnum' do + expect(decode_len.class).to eq(::Fixnum) + end + it 'returns value correctly' do + expect(decode_len).to eq(89613) + end + end + context 'testing invalid length' do data = ['308400000bc1'].pack('H*') + let(:decode_len) { subject.decode_elem_length(data) } it 'returns nil as expected' do expect(decode_len).to eq(nil) end @@ -75,10 +90,48 @@ expect(split_messages.class).to eq(::Array) end end end + describe '.parse_ldapresult' do + + context 'testing valid data' do + hex = ['300c02010765070a010004000400'] + data = OpenSSL::ASN1.decode(hex.pack('H*')) + + let(:parse_ldapresult) { subject.parse_ldapresult(data.value[1]) } + it 'returns Hash as expected' do + expect(parse_ldapresult.class).to eq(::Hash) + end + + it 'returns results as expected' do + test_val = { 'resultCode' => 0, + 'resultDesc' => 'success', + 'resultMatchedDN' => '', + 'resultdiagMessage' => '' + } + expect(parse_ldapresult).to eq(test_val) + end + end + + context 'testing invalid data' do + hex = ['300702010765020400'] + data = OpenSSL::ASN1.decode(hex.pack('H*')) + + let(:parse_ldapresult) { subject.parse_ldapresult(data.value[1]) } + it 'returns Hash as expected' do + expect(parse_ldapresult.class).to eq(::Hash) + end + + it 'returns empty Hash as expected' do + test_val = {} + expect(parse_ldapresult).to eq(test_val) + end + end + + end + describe '.parse_messages' do context 'testing SearchResultEntry' do hex = ['3030020107642b040030273025040b6f626a656374436c6173'\ '7331160403746f70040f4f70656e4c444150726f6f74445345'] @@ -113,11 +166,30 @@ end it 'returns SearchResultDone value as expected' do test_val = ['SearchResultDone', { 'resultCode' => 0, + 'resultDesc' => 'success', 'resultMatchedDN' => '', 'resultdiagMessage' => '' + }] + expect(parse_message).to eq(test_val) + end + end + + context 'testing SearchResultDone - edge case #1' do + hex = ['300802010765000a0101'] + data = OpenSSL::ASN1.decode(hex.pack('H*')) + + let(:parse_message) { subject.parse_message(data) } + it 'returns Array as expected' do + expect(parse_message.class).to eq(::Array) + end + + it 'returns operationsError as expected' do + test_val = ['SearchResultDone', { + 'resultCode' => 1, + 'resultDesc' => 'operationsError' }] expect(parse_message).to eq(test_val) end end