Skip to content

Commit 2a93bb1

Browse files
committed
✅ More tests
1 parent d15ac84 commit 2a93bb1

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

spec/omniauth/strategies/ldap_spec.rb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def make_env(path = "/auth/ldap", props = {})
347347
it "escapes special characters in username when building filter" do
348348
allow(@adaptor).to receive(:filter).and_return("uid=%{username}")
349349
# '(' => \28 and ')' => \29 per RFC 4515 escaping
350-
expect(Net::LDAP::Filter).to receive(:construct).with("uid=al\\28ice\\29")
350+
expect(Net::LDAP::Filter).to receive(:construct).with('uid=al\28ice\29')
351351
post("/auth/ldap/callback", {username: "al(ice)", password: "secret"})
352352
end
353353

@@ -444,8 +444,8 @@ def make_env(path = "/auth/ldap", props = {})
444444

445445
it 'should map user info according to customized mapping' do
446446
post('/auth/ldap/callback', {:username => 'ping', :password => 'password'})
447-
auth_hash.info.phone.should == '444-444-4444'
448-
auth_hash.info.mobile.should == '444-444-4444'
447+
expect(auth_hash.info.phone).to eq '444-444-4444'
448+
expect(auth_hash.info.mobile).to eq '444-444-4444'
449449
end
450450
end
451451
end
@@ -604,7 +604,7 @@ def connection_returning(entry)
604604
connection: connection_returning(entry),
605605
filter: "uid=%{username}",
606606
)
607-
expect(Net::LDAP::Filter).to receive(:construct).with("uid=al\\28ice\\29").and_call_original
607+
expect(Net::LDAP::Filter).to receive(:construct).with('uid=al\28ice\29').and_call_original
608608

609609
post "/auth/ldap/callback", nil, {"REMOTE_USER" => "al(ice)"}
610610
expect(last_response).not_to be_redirect
@@ -632,5 +632,41 @@ def connection_returning(entry)
632632
post "/auth/ldap/callback", nil, {"REMOTE_USER" => "[email protected]"}
633633
expect(last_response).not_to be_redirect
634634
end
635+
636+
context "with custom mapping option" do
637+
let(:app) do
638+
Rack::Builder.new do
639+
use OmniAuth::Test::PhonySession
640+
use MyHeaderProvider,
641+
name: "ldap",
642+
title: "Header LDAP",
643+
host: "ldap.example.com",
644+
base: "dc=example,dc=com",
645+
uid: "uid",
646+
header_auth: true,
647+
header_name: "REMOTE_USER",
648+
name_proc: proc { |n| n },
649+
mapping: { "phone" => "mobile" }
650+
run lambda { |env| [404, {"Content-Type" => "text/plain"}, [env.key?("omniauth.auth").to_s]] }
651+
end.to_app
652+
end
653+
654+
it "applies the custom mapping in header SSO path" do
655+
entry = Net::LDAP::Entry.from_single_ldif_string(%{dn: cn=bob, dc=example, dc=com
656+
uid: bob
657+
mobile: 444-444-4444
658+
telephonenumber: 555-555-5555
659+
})
660+
allow(@adaptor).to receive(:connection).and_return(connection_returning(entry))
661+
662+
post "/auth/ldap/callback", nil, {"REMOTE_USER" => "bob"}
663+
expect(last_response).not_to be_redirect
664+
auth = last_request.env["omniauth.auth"]
665+
# phone should come from mobile due to custom mapping override
666+
expect(auth.info.phone).to eq "444-444-4444"
667+
# mobile remains available as well
668+
expect(auth.info.mobile).to eq "444-444-4444"
669+
end
670+
end
635671
end
636672
end

0 commit comments

Comments
 (0)