Skip to content

Commit 49c0265

Browse files
committed
Merge pull request #217 from astockwell/feature/obscure_auth
obscure auth password upon #inspect, added test, closes #216
2 parents e7fde22 + 02ec36e commit 49c0265

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/net/ldap.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,13 @@ def paged_searches_supported?
11951195
@server_caps[:supportedcontrol].include?(Net::LDAP::LDAPControls::PAGED_RESULTS)
11961196
end
11971197

1198+
# Mask auth password
1199+
def inspect
1200+
inspected = super
1201+
inspected.gsub! @auth[:password], "*******" if @auth[:password]
1202+
inspected
1203+
end
1204+
11981205
private
11991206

12001207
# Yields an open connection if there is one, otherwise establishes a new

test/test_ldap.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,11 @@ def test_instrument_search_with_size
5757
assert_equal "(uid=user1)", payload[:filter]
5858
assert_equal result.size, payload[:size]
5959
end
60+
61+
def test_obscure_auth
62+
password = "opensesame"
63+
assert_include(@subject.inspect, "anonymous")
64+
@subject.auth "joe_user", password
65+
assert_not_include(@subject.inspect, password)
66+
end
6067
end

0 commit comments

Comments
 (0)