Skip to content
Open
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ rvm:
- ruby-head
env:
- "rake=0.9"
script: "bundle exec rspec -t no_ad"
before_script: "mkdir log"
script: "bundle exec rspec -c"
before_install:
- travis/before_install.sh
before_script:
- travis/before_script.sh
notifications:
email: false
matrix:
Expand Down
5 changes: 3 additions & 2 deletions lib/adauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def self.connection
# Connects to ActiveDirectory using the query user details
def self.connect
@logger.info('connection') { "Connecting to AD as \"#{@config.query_user}\"" }
@connection = Adauth::Connection.new(connection_hash(@config.query_user, @config.query_password)).bind
@connection = Adauth::Connection.new(connection_hash(@config.query_user, @config.query_password, @config.query_user_dn)).bind
end

# Generates a hash for the connection class, takes a username and password
def self.connection_hash(user, password)
def self.connection_hash(user, password, bind_dn = false)
{
:domain => @config.domain,
:server => @config.server,
Expand All @@ -60,6 +60,7 @@ def self.connection_hash(user, password)
:allow_fallback => @config.allow_fallback,
:username => user,
:password => password,
:bind_dn => bind_dn,
:anonymous_bind => @config.anonymous_bind
}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/adauth/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Adauth
class Config
attr_accessor :domain, :port, :base, :server, :encryption, :query_user, :query_password, :allow_fallback,
:allowed_groups, :denied_groups, :allowed_ous, :denied_ous, :contains_nested_groups,
:anonymous_bind
:anonymous_bind, :query_user_dn

def initialize
@port = 389
Expand Down
4 changes: 3 additions & 1 deletion lib/adauth/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def bind

raise "Anonymous Bind is disabled" if @config[:password] == "" && !(@config[:anonymous_bind])

conn.auth "#{@config[:username]}@#{@config[:domain]}", @config[:password]
auth_name = @config[:bind_dn] ? @config[:bind_dn] : "#{@config[:username]}@#{@config[:domain]}"

conn.auth auth_name, @config[:password]

begin
Timeout::timeout(10){
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def default_config
c.server = test_data("domain", "server")
c.encryption = test_data("domain", "encryption").to_sym if test_data("domain", "encryption")
c.allow_fallback = test_data("domain", "allow_fallback") if test_data("domain", "allow_fallback")
c.query_user_dn = test_data("domain", "query_user_dn") if test_data("domain", "query_user_dn")
c.query_user = test_data("domain", "query_user")
c.query_password = test_data("domain", "query_password")
end
Expand Down
5 changes: 5 additions & 0 deletions travis/before_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

set -e

sudo apt-get install -y ldap-utils slapd
56 changes: 56 additions & 0 deletions travis/before_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

# Create the Logs directory
mkdir log

# Generate admin password
password="secret"
crypted_password=`slappasswd -s $password`
echo "crtpyed password: ${crypted_password}"

# Apply the administrator password
cat <<EOF | sudo ldapmodify -Y EXTERNAL -H ldapi:///
version: 1
dn: olcDatabase={1}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: ${crypted_password}
-
EOF

sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f travis/ldif/phonetic-attribute-options.ldif

# Calculate base and domain name
base="dc=`echo get slapd/domain | sudo debconf-communicate slapd | sed -e 's/^0 //' | sed -e 's/^\.//; s/\./,dc=/g'`"
domain="`echo get slapd/domain | sudo debconf-communicate slapd | sed -e 's/^0 //'`"

# Create the query user ldif file
cat <<EOF > travis/ldif/query_user.ldif
dn: cn=adauth,${base}
cn: Adauth
objectClass: account
objectClass: top
userPassword: ${crypted_password}
sn: Tests
EOF

# Add the new user
sudo ldapadd -D "cn=admin,${base}" -w $password -x -f travis/ldif/query_user.ldif

# Generate the tests config file
cat <<EOF > spec/test_data.yml
domain:
domain: ${domain}
port: 389
base: ${base}
server: 127.0.0.1
query_user: adauth
query_user_dn: cn=admin,${base}
query_password: ${password}
breakable_user: foo
breakable_password: bar
testable_ou: Foo
EOF

# Output the config file for debugging purposes
cat spec/test_data.yml
5 changes: 5 additions & 0 deletions travis/ldif/phonetic-attribute-options.ldif
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
dn: cn=config
changetype: modify
add: olcAttributeOptions
olcAttributeOptions: phonetic lang-