From e0f17dde356367050f6197cf48fa6d69cf84f536 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Fri, 30 Aug 2013 09:51:07 +0100 Subject: [PATCH 01/14] make changes to travis settings for ldap testing --- .travis.yml | 5 +++- travis/before_install.sh | 5 ++++ travis/before_script.sh | 31 +++++++++++++++++++++ travis/ldif/phonetic-attribute-options.ldif | 5 ++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 travis/before_install.sh create mode 100755 travis/before_script.sh create mode 100644 travis/ldif/phonetic-attribute-options.ldif diff --git a/.travis.yml b/.travis.yml index a52b50b..db33558 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,10 @@ rvm: env: - "rake=0.9" script: "bundle exec rspec -t no_ad" -before_script: "mkdir log" +before_install: + - travis/before_install.sh +before_script: + - travis/before_script.sh notifications: email: false matrix: diff --git a/travis/before_install.sh b/travis/before_install.sh new file mode 100755 index 0000000..0e164bc --- /dev/null +++ b/travis/before_install.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +sudo apt-get install -y ldap-utils slapd diff --git a/travis/before_script.sh b/travis/before_script.sh new file mode 100755 index 0000000..e63177c --- /dev/null +++ b/travis/before_script.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +mkdir log + +password = "secret" +crypted_password = `slappasswd -s $password` +cat < spec/test_data.yml +domain: + domain: ed-itsolutions.com + port: 389 + base: ${base} + server: 127.0.0.1 + query_user: admin + query_password: ${password} + breakable_user: foo + breakable_password: bar + testable_ou: Foo +EOF diff --git a/travis/ldif/phonetic-attribute-options.ldif b/travis/ldif/phonetic-attribute-options.ldif new file mode 100644 index 0000000..d5211d9 --- /dev/null +++ b/travis/ldif/phonetic-attribute-options.ldif @@ -0,0 +1,5 @@ +version: 1 +dn: cn=config +changetype: modify +add: olcAttributeOptions +olcAttributeOptions: phonetic lang- \ No newline at end of file From c406d80af5a40f805b48d8b9514e29f2bc068dd5 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Fri, 30 Aug 2013 10:53:11 +0100 Subject: [PATCH 02/14] echo test_data.yml so we can see it in the build --- travis/before_script.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/travis/before_script.sh b/travis/before_script.sh index e63177c..f56cddb 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -2,8 +2,8 @@ mkdir log -password = "secret" -crypted_password = `slappasswd -s $password` +password="secret" +crypted_password=`slappasswd -s $password` cat < Date: Fri, 30 Aug 2013 13:27:50 +0100 Subject: [PATCH 03/14] update before script and remove no_ad (tests will fail now) --- .travis.yml | 2 +- travis/before_script.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index db33558..b4b2ddb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ rvm: - ruby-head env: - "rake=0.9" -script: "bundle exec rspec -t no_ad" +script: "bundle exec rspec -c" before_install: - travis/before_install.sh before_script: diff --git a/travis/before_script.sh b/travis/before_script.sh index f56cddb..69879e3 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -16,10 +16,11 @@ EOF sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f travis/ldif/phonetic-attribute-options.ldif base="dc=`echo get slapd/domain | sudo debconf-communicate slapd | sed -e 's/^0 //' | sed -e 's/^\.//; s/\./,dc=/g'`" +domain="dc=`echo get slapd/domain | sudo debconf-communicate slapd | sed -e 's/^0 //'" cat < spec/test_data.yml domain: - domain: ed-itsolutions.com + domain: ${domain} port: 389 base: ${base} server: 127.0.0.1 From 297bf6e583e3250c42d5ea0c9953531758c73b51 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Fri, 30 Aug 2013 13:28:50 +0100 Subject: [PATCH 04/14] syntax error --- travis/before_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/before_script.sh b/travis/before_script.sh index 69879e3..6187c07 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -16,7 +16,7 @@ EOF sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f travis/ldif/phonetic-attribute-options.ldif base="dc=`echo get slapd/domain | sudo debconf-communicate slapd | sed -e 's/^0 //' | sed -e 's/^\.//; s/\./,dc=/g'`" -domain="dc=`echo get slapd/domain | sudo debconf-communicate slapd | sed -e 's/^0 //'" +domain="`echo get slapd/domain | sudo debconf-communicate slapd | sed -e 's/^0 //'`" cat < spec/test_data.yml domain: From 50fb6ad196890ef588cd8d71600afb5051c53f31 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Tue, 3 Sep 2013 13:39:11 +0100 Subject: [PATCH 05/14] add trailing line --- travis/ldif/phonetic-attribute-options.ldif | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/ldif/phonetic-attribute-options.ldif b/travis/ldif/phonetic-attribute-options.ldif index d5211d9..d72fec5 100644 --- a/travis/ldif/phonetic-attribute-options.ldif +++ b/travis/ldif/phonetic-attribute-options.ldif @@ -2,4 +2,4 @@ version: 1 dn: cn=config changetype: modify add: olcAttributeOptions -olcAttributeOptions: phonetic lang- \ No newline at end of file +olcAttributeOptions: phonetic lang- From d522189920e987cf369added7162c3145f2dbb38 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Tue, 3 Sep 2013 13:45:09 +0100 Subject: [PATCH 06/14] echo the crypted password and add query_user_base to generated test_data.yml --- travis/before_script.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/travis/before_script.sh b/travis/before_script.sh index 6187c07..591ab50 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -4,6 +4,7 @@ mkdir log password="secret" crypted_password=`slappasswd -s $password` +echo "crtpyed password: #{crypted_password}" cat < Date: Tue, 3 Sep 2013 13:47:35 +0100 Subject: [PATCH 07/14] shell, not ruby --- travis/before_script.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/travis/before_script.sh b/travis/before_script.sh index 591ab50..ec2c83e 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -4,7 +4,7 @@ mkdir log password="secret" crypted_password=`slappasswd -s $password` -echo "crtpyed password: #{crypted_password}" +echo "crtpyed password: ${crypted_password}" cat < Date: Tue, 3 Sep 2013 13:55:42 +0100 Subject: [PATCH 08/14] use bind_dn if present --- lib/adauth.rb | 5 +++-- lib/adauth/config.rb | 2 +- lib/adauth/connection.rb | 2 ++ spec/spec_helper.rb | 1 + travis/before_script.sh | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/adauth.rb b/lib/adauth.rb index e2bcd06..7a6a69d 100644 --- a/lib/adauth.rb +++ b/lib/adauth.rb @@ -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, @@ -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 diff --git a/lib/adauth/config.rb b/lib/adauth/config.rb index 5bc8ff4..3efce25 100644 --- a/lib/adauth/config.rb +++ b/lib/adauth/config.rb @@ -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 diff --git a/lib/adauth/connection.rb b/lib/adauth/connection.rb index 2b6ceee..4100002 100644 --- a/lib/adauth/connection.rb +++ b/lib/adauth/connection.rb @@ -25,6 +25,8 @@ def bind raise "Anonymous Bind is disabled" if @config[:password] == "" && !(@config[:anonymous_bind]) + @config[:bind_dn] + conn.auth "#{@config[:username]}@#{@config[:domain]}", @config[:password] begin diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b7458cb..46c9810 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/travis/before_script.sh b/travis/before_script.sh index ec2c83e..7ea65a7 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -26,7 +26,7 @@ domain: base: ${base} server: 127.0.0.1 query_user: admin - query_user_base: cn=admin,${base} + query_user_dn: cn=admin,${base} query_password: ${password} breakable_user: foo breakable_password: bar From 5800fa6aa2de62f31d0f8c56f8da2bc4570e00c9 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Tue, 3 Sep 2013 13:56:27 +0100 Subject: [PATCH 09/14] use bind_dn if present --- lib/adauth/connection.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/adauth/connection.rb b/lib/adauth/connection.rb index 4100002..bd7ef97 100644 --- a/lib/adauth/connection.rb +++ b/lib/adauth/connection.rb @@ -25,9 +25,9 @@ def bind raise "Anonymous Bind is disabled" if @config[:password] == "" && !(@config[:anonymous_bind]) - @config[:bind_dn] + auth_name = @config[:bind_dn] ? @config[:bind_dn] : "#{@config[:username]}@#{@config[:domain]}" - conn.auth "#{@config[:username]}@#{@config[:domain]}", @config[:password] + conn.auth auth_name, @config[:password] begin Timeout::timeout(10){ From 831746b4934019a6e78bb37135748035a761dad0 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Tue, 3 Sep 2013 14:13:38 +0100 Subject: [PATCH 10/14] create a test user --- travis/before_script.sh | 11 ++++++++++- travis/ldif/query_user.ldif | 0 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 travis/ldif/query_user.ldif diff --git a/travis/before_script.sh b/travis/before_script.sh index 7ea65a7..4b9677a 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -19,13 +19,22 @@ sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f travis/ldif/phonetic-attribute-optio 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 //'`" +cat < spec/test_data.yml domain: domain: ${domain} port: 389 base: ${base} server: 127.0.0.1 - query_user: admin + query_user: adauth query_user_dn: cn=admin,${base} query_password: ${password} breakable_user: foo diff --git a/travis/ldif/query_user.ldif b/travis/ldif/query_user.ldif new file mode 100644 index 0000000..e69de29 From 41d84786fdb563e68bb6b090c6e3cb00d1ee94fb Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Tue, 3 Sep 2013 14:26:10 +0100 Subject: [PATCH 11/14] generate a user and add it to ldap --- travis/before_script.sh | 19 +++++++++++++++---- travis/ldif/query_user.ldif | 0 2 files changed, 15 insertions(+), 4 deletions(-) delete mode 100644 travis/ldif/query_user.ldif diff --git a/travis/before_script.sh b/travis/before_script.sh index 4b9677a..3a325c9 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -1,10 +1,14 @@ #!/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 < travis/ldif/query_user.ldif dn: cn=adauth,${base} -changetype: add +cn: Adauth objectClass: user objectClass: top -userPassword: ${password} +userPassword: ${crypted_password} +sn: Tests EOF +# Add the new user +sudo ldapadd -D "cn=admin,${base}" -W -x -f travis/ldif/query_user.ldif + +# Generate the tests config file cat < spec/test_data.yml domain: domain: ${domain} @@ -42,4 +52,5 @@ domain: testable_ou: Foo EOF +# Output the config file for debugging purposes cat spec/test_data.yml diff --git a/travis/ldif/query_user.ldif b/travis/ldif/query_user.ldif deleted file mode 100644 index e69de29..0000000 From 5b8b09c43bc701fde7fbbcff6ac396d3d9a04533 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Tue, 3 Sep 2013 14:31:38 +0100 Subject: [PATCH 12/14] pass password to ldapadd --- travis/before_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/before_script.sh b/travis/before_script.sh index 3a325c9..5088184 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -35,7 +35,7 @@ sn: Tests EOF # Add the new user -sudo ldapadd -D "cn=admin,${base}" -W -x -f travis/ldif/query_user.ldif +sudo ldapadd -D "cn=admin,${base}" -W -w $password -x -f travis/ldif/query_user.ldif # Generate the tests config file cat < spec/test_data.yml From 92f13b304a91a814c9f33b6fd05b07b6c0acfce0 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Tue, 3 Sep 2013 14:33:56 +0100 Subject: [PATCH 13/14] pass password to ldapadd (rtfm) --- travis/before_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/before_script.sh b/travis/before_script.sh index 5088184..decab60 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -35,7 +35,7 @@ sn: Tests EOF # Add the new user -sudo ldapadd -D "cn=admin,${base}" -W -w $password -x -f travis/ldif/query_user.ldif +sudo ldapadd -D "cn=admin,${base}" -w $password -x -f travis/ldif/query_user.ldif # Generate the tests config file cat < spec/test_data.yml From c25b9f6dc1152f9286193f1b1364dcb9fadfdc79 Mon Sep 17 00:00:00 2001 From: Adam Laycock Date: Thu, 5 Sep 2013 12:46:22 +0100 Subject: [PATCH 14/14] change object class --- travis/before_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/before_script.sh b/travis/before_script.sh index decab60..20202d6 100755 --- a/travis/before_script.sh +++ b/travis/before_script.sh @@ -28,7 +28,7 @@ domain="`echo get slapd/domain | sudo debconf-communicate slapd | sed -e 's/^0 / cat < travis/ldif/query_user.ldif dn: cn=adauth,${base} cn: Adauth -objectClass: user +objectClass: account objectClass: top userPassword: ${crypted_password} sn: Tests