Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require "minitest/mock"
require "test_helper"
class LoginTest < ActionDispatch::IntegrationTest
fixtures :pkis, :organizations, :users
def setup
@ldap_mock = Minitest::Mock.new
@ldap_mock.expect :tap, LdapStub.new
end
def test_admin_login
# get the login page
get "/"
assert_equal 200, status
# post the login and follow through to the home page
post "/discovery", email: users(:zm).email
follow_redirect!
assert_equal 200, status
assert_equal "/auth/default", path
Net::LDAP.stub :new, @ldap_mock do
post "/auth/default/callback", username: "zm", password: "foo"
@ldap_mock.verify
end
follow_redirect!
assert_equal 200, status
assert_equal "/dashboard", path
end
class LdapStub
def bind_as(*)
[bind_as_result]
end
def get_operation_result
Struct.new(:code, :inspect).new.tap do |obj|
obj.code = 0
end
end
private
def bind_as_result
e = Net::LDAP::Entry.new "CN=Zoran Majstorovi\xC4\x87,CN=Users,DC=promdm,DC=net"
e[:cn] = ["Zoran Majstorovi\xC4\x87"]
e[:sn] = ["Majstorovi\xC4\x87"]
e[:givenname] = ["Zoran"]
e[:displayname] = ["Zoran Majstorovi\xC4\x87"]
e[:memberof] = [
"CN=Test \xC4\x8D\xC4\x87\xC5\xBE\xC4\x91\xC5\xA1\xC4\x8C\xC4\x86\xC5\xBD\xC4\x90\xC5\xA0,OU=Korisnici,DC=promdm,DC=net",
"CN=donja,OU=Korisnici,DC=promdm,DC=net",
"CN=promdmadmins,CN=Users,DC=promdm,DC=net",
"CN=Domain Admins,CN=Users,DC=promdm,DC=net"
]
e[:name] = ["Zoran Majstorovi\xC4\x87"]
e[:samaccountname] = ["zm"]
e[:userprincipalname] = ["zm@promdm.net"]
e[:mail] = ["zm@promdm.net"]
e
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.