Skip to content

Commit

Permalink
fix multiline blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jch committed Jan 8, 2016
1 parent 987c522 commit 0dec1d9
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 28 deletions.
8 changes: 4 additions & 4 deletions lib/net/ldap.rb
Expand Up @@ -775,10 +775,10 @@ def search(args = {})

instrument "search.net_ldap", args do |payload|
@result = use_connection(args) do |conn|
conn.search(args) { |entry|
conn.search(args) do |entry|
result_set << entry if result_set
yield entry if block_given?
}
end
end

if return_result_set
Expand Down Expand Up @@ -917,15 +917,15 @@ def bind(auth = @auth)
# end
def bind_as(args = {})
result = false
open { |me|
open do |me|
rs = search args
if rs and rs.first and dn = rs.first.dn
password = args[:password]
password = password.call if password.respond_to?(:call)
result = rs if bind(:method => :simple, :username => dn,
:password => password)
end
}
end
result
end

Expand Down
2 changes: 0 additions & 2 deletions lib/net/ldap/auth_adapter/gss_spnego.rb
Expand Up @@ -22,12 +22,10 @@ def bind(auth)
user, psw = [auth[:username] || auth[:dn], auth[:password]]
raise Net::LDAP::BindingInformationInvalidError, "Invalid binding information" unless (user && psw)

nego = proc { |challenge|
t2_msg = NTLM::Message.parse(challenge)
t3_msg = t2_msg.response({ :user => user, :password => psw },
{ :ntlmv2 => true })
t3_msg.serialize
}

Net::LDAP::AuthAdapter::Sasl.new(@connection).bind \
:method => :sasl,
Expand Down
4 changes: 2 additions & 2 deletions lib/net/ldap/auth_adapter/sasl.rb
Expand Up @@ -33,7 +33,7 @@ def bind(auth)
message_id = @connection.next_msgid

n = 0
loop {
loop do
sasl = [mech.to_ber, cred.to_ber].to_ber_contextspecific(3)
request = [
Net::LDAP::Connection::LdapVersion.to_ber, "".to_ber, sasl
Expand All @@ -50,7 +50,7 @@ def bind(auth)
raise Net::LDAP::SASLChallengeOverflowError, "sasl-challenge overflow" if ((n += 1) > MaxSaslChallenges)

cred = chall.call(pdu.result_server_sasl_creds)
}
end

raise Net::LDAP::SASLChallengeOverflowError, "why are we here?"
end
Expand Down
8 changes: 4 additions & 4 deletions lib/net/ldap/connection.rb
Expand Up @@ -500,14 +500,14 @@ def search(args = nil)
def self.modify_ops(operations)
ops = []
if operations
operations.each { |op, attrib, values|
operations.each do |op, attrib, values|
# TODO, fix the following line, which gives a bogus error if the
# opcode is invalid.
op_ber = MODIFY_OPERATIONS[op.to_sym].to_ber_enumerated
values = [ values ].flatten.map { |v| v.to_ber if v }.to_ber_set
values = [ attrib.to_s.to_ber, values ].to_ber_sequence
ops << [ op_ber, values ].to_ber
}
end
end
ops
end
Expand Down Expand Up @@ -594,9 +594,9 @@ def password_modify(args)
def add(args)
add_dn = args[:dn] or raise Net::LDAP::EmptyDNError, "Unable to add empty DN"
add_attrs = []
a = args[:attributes] and a.each { |k, v|
a = args[:attributes] and a.each do |k, v|
add_attrs << [ k.to_s.to_ber, Array(v).map { |m| m.to_ber}.to_ber_set ].to_ber_sequence
}
end

message_id = next_msgid
request = [add_dn.to_ber, add_attrs.to_ber_sequence].to_ber_appsequence(Net::LDAP::PDU::AddRequest)
Expand Down
4 changes: 2 additions & 2 deletions lib/net/ldap/entry.rb
Expand Up @@ -141,10 +141,10 @@ def attribute_names
# (possibly empty) \Array of data values.
def each # :yields: attribute-name, data-values-array
if block_given?
attribute_names.each {|a|
attribute_names.each do|a|
attr_name,values = a,self[a]
yield attr_name, values
}
end
end
end
alias_method :each_attribute, :each
Expand Down
4 changes: 2 additions & 2 deletions lib/net/ldap/filter.rb
Expand Up @@ -287,7 +287,7 @@ def parse_ber(ber)
when 0xa4 # context-specific constructed 4, "substring"
str = ""
final = false
ber.last.each { |b|
ber.last.each do |b|
case b.ber_identifier
when 0x80 # context-specific primitive 0, SubstringFilter "initial"
raise Net::LDAP::SubstringFilterError, "Unrecognized substring filter; bad initial value." if str.length > 0
Expand All @@ -298,7 +298,7 @@ def parse_ber(ber)
str += "*#{escape(b)}"
final = true
end
}
end
str += "*" unless final
eq(ber.first.to_s, str)
when 0xa5 # context-specific constructed 5, "greaterOrEqual"
Expand Down
12 changes: 6 additions & 6 deletions lib/net/snmp.rb
Expand Up @@ -227,9 +227,9 @@ def pdu_to_ber_string
error_status.to_ber,
error_index.to_ber,
[
@variables.map {|n,v|
@variables.map do|n,v|
[n.to_ber_oid, Net::BER::BerIdentifiedNull.new.to_ber].to_ber_sequence
}
end
].to_ber_sequence
].to_ber_contextspecific(0)
when :get_next_request
Expand All @@ -238,9 +238,9 @@ def pdu_to_ber_string
error_status.to_ber,
error_index.to_ber,
[
@variables.map {|n,v|
@variables.map do|n,v|
[n.to_ber_oid, Net::BER::BerIdentifiedNull.new.to_ber].to_ber_sequence
}
end
].to_ber_sequence
].to_ber_contextspecific(1)
when :get_response
Expand All @@ -249,9 +249,9 @@ def pdu_to_ber_string
error_status.to_ber,
error_index.to_ber,
[
@variables.map {|n,v|
@variables.map do|n,v|
[n.to_ber_oid, v.to_ber].to_ber_sequence
}
end
].to_ber_sequence
].to_ber_contextspecific(2)
else
Expand Down
4 changes: 2 additions & 2 deletions test/test_filter.rb
Expand Up @@ -13,11 +13,11 @@ def test_invalid_filter_string
end

def test_invalid_filter
assert_raises(Net::LDAP::OperatorError) {
assert_raises(Net::LDAP::OperatorError) do
# This test exists to prove that our constructor blocks unknown filter
# types. All filters must be constructed using helpers.
Filter.__send__(:new, :xx, nil, nil)
}
end
end

def test_to_s
Expand Down
8 changes: 4 additions & 4 deletions test/test_snmp.rb
Expand Up @@ -16,9 +16,9 @@ def self.raw_string(s)

def test_invalid_packet
data = "xxxx"
assert_raise(Net::BER::BerError) {
assert_raise(Net::BER::BerError) do
ary = data.read_ber(Net::SNMP::AsnSyntax)
}
end
end

# The method String#read_ber! added by Net::BER consumes a well-formed BER
Expand All @@ -40,9 +40,9 @@ def _test_consume_string
end

def test_weird_packet
assert_raise(Net::SnmpPdu::Error) {
assert_raise(Net::SnmpPdu::Error) do
Net::SnmpPdu.parse("aaaaaaaaaaaaaa")
}
end
end

def test_get_request
Expand Down

0 comments on commit 0dec1d9

Please sign in to comment.