Class: GitHub::Ldap
- Inherits:
-
Object
- Object
- GitHub::Ldap
- Extended by:
- Forwardable
- Defined in:
- lib/github/ldap.rb,
lib/github/ldap/domain.rb,
lib/github/ldap/filter.rb,
lib/github/ldap/server.rb
Defined Under Namespace
Modules: Filter Classes: Domain
Constant Summary collapse
- DEFAULT_FIXTURES_PATH =
Preconfigured user fixtures. If you want to use them for your own tests.
File.('fixtures.ldif', File.dirname(__FILE__))
- DEFAULT_SERVER_OPTIONS =
{ user_fixtures: DEFAULT_FIXTURES_PATH, user_domain: 'dc=github,dc=com', admin_user: 'uid=admin,dc=github,dc=com', admin_password: 'secret', quiet: true, port: 3897 }
Class Attribute Summary collapse
-
.ldap_server ⇒ Object
readonly
ldap_server: is the instance of the testing ldap server, you should never interact with it, but it’s used to grecefully stop it after your tests finalize.
-
.server_options ⇒ Object
readonly
server_options: is the options used to start the server, useful to know in development.
Class Method Summary collapse
-
.server_tmp ⇒ Object
Determine the temporal directory where the ldap server lives.
-
.start_server(options = {}) ⇒ Object
Start a testing server.
-
.stop_server ⇒ Object
Stop the testing server.
Instance Method Summary collapse
-
#check_encryption(encryption) ⇒ Object
Determine whether to use encryption or not.
-
#domain(base_name) ⇒ Object
Creates a new domain object to perform operations.
-
#initialize(options = {}) ⇒ Ldap
constructor
A new instance of Ldap.
-
#test_connection ⇒ Object
Utility method to check if the connection with the server can be stablished.
Constructor Details
#initialize(options = {}) ⇒ Ldap
Returns a new instance of Ldap.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/github/ldap.rb', line 24 def initialize( = {}) @uid = [:uid] || "sAMAccountName" @connection = Net::LDAP.new({host: [:host], port: [:port]}) @connection.authenticate([:admin_user], [:admin_password]) if encryption = check_encryption([:encryption]) @connection.encryption(encryption) end end |
Class Attribute Details
.ldap_server ⇒ Object (readonly)
ldap_server: is the instance of the testing ldap server,
you should never interact with it,
but it's used to grecefully stop it after your tests finalize.
26 27 28 |
# File 'lib/github/ldap/server.rb', line 26 def ldap_server @ldap_server end |
.server_options ⇒ Object (readonly)
server_options: is the options used to start the server,
useful to know in development.
21 22 23 |
# File 'lib/github/ldap/server.rb', line 21 def end |
Class Method Details
.server_tmp ⇒ Object
Determine the temporal directory where the ldap server lives. If there is no temporal directory in the environment we create one in the base path.
Returns the path to the temporal directory.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/github/ldap/server.rb', line 55 def self.server_tmp tmp = ENV['TMPDIR'] || ENV['TEMPDIR'] if tmp.nil? tmp = 'tmp' Dir.mkdir(tmp) unless File.directory?('tmp') end tmp end |
.start_server(options = {}) ⇒ Object
Start a testing server. If there is already a server initialized it doesn’t do anything.
options: is a hash with the custom options for the server.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/github/ldap/server.rb', line 33 def self.start_server( = {}) = DEFAULT_SERVER_OPTIONS.merge() [:allow_anonymous] = false [:ldif] = [:user_fixtures] [:domain] = [:user_domain] [:tmpdir] ||= server_tmp @ldap_server = Ladle::Server.new() @ldap_server.start end |
.stop_server ⇒ Object
Stop the testing server. If there is no server started this method doesn’t do anything.
47 48 49 |
# File 'lib/github/ldap/server.rb', line 47 def self.stop_server ldap_server && ldap_server.stop end |
Instance Method Details
#check_encryption(encryption) ⇒ Object
Determine whether to use encryption or not.
encryption: is the encryption method, either ‘ssl’, ‘tls’, ‘simple_tls’ or ‘start_tls’.
Returns the real encryption type.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/github/ldap.rb', line 41 def check_encryption(encryption) return unless encryption case encryption.downcase.to_sym when :ssl, :simple_tls :simple_tls when :tls, :start_tls :start_tls end end |
#domain(base_name) ⇒ Object
Creates a new domain object to perform operations
base_name: is the dn of the base root.
Returns a new Domain object.
67 68 69 |
# File 'lib/github/ldap.rb', line 67 def domain(base_name) Domain.new(base_name, @connection, @uid) end |
#test_connection ⇒ Object
Utility method to check if the connection with the server can be stablished. It tries to bind with the ldap auth default configuration.
Returns an OpenStruct with ‘code` and `message`. If `code` is 0, the operation succeeded and there is no message.
57 58 59 60 |
# File 'lib/github/ldap.rb', line 57 def test_connection @connection.bind last_operation_result end |