Skip to content

Commit 5d3e400

Browse files
committed
Merge pull request #61 from github/local-activedirectory-integration-testing
Local ActiveDirectory integration testing
2 parents b8407ed + f95f985 commit 5d3e400

File tree

7 files changed

+115
-7
lines changed

7 files changed

+115
-7
lines changed

test/membership_validators/active_directory_test.rb

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require_relative '../test_helper'
22

3-
# NOTE: Since this strategy is targeted at ActiveDirectory and we don't have
4-
# AD setup in CI, we stub out actual queries and test against what AD *would*
5-
# respond with.
3+
class GitHubLdapActiveDirectoryMembershipValidatorsStubbedTest < GitHub::Ldap::Test
4+
# Only run when AD integration tests aren't run
5+
def run(*)
6+
self.class.test_env != "activedirectory" ? super : self
7+
end
68

7-
class GitHubLdapActiveDirectoryMembershipValidatorsTest < GitHub::Ldap::Test
89
def setup
910
@ldap = GitHub::Ldap.new(options.merge(search_domains: %w(dc=github,dc=com)))
1011
@domain = @ldap.domain("dc=github,dc=com")
@@ -66,3 +67,60 @@ def test_does_not_validate_user_not_in_any_group
6667
end
6768
end
6869
end
70+
71+
# See test/support/vm/activedirectory/README.md for details
72+
class GitHubLdapActiveDirectoryMembershipValidatorsIntegrationTest < GitHub::Ldap::Test
73+
# Only run this test suite if ActiveDirectory is configured
74+
def run(*)
75+
self.class.test_env == "activedirectory" ? super : self
76+
end
77+
78+
def setup
79+
@ldap = GitHub::Ldap.new(options)
80+
@domain = @ldap.domain(options[:search_domains])
81+
@entry = @domain.user?('user1')
82+
@validator = GitHub::Ldap::MembershipValidators::ActiveDirectory
83+
end
84+
85+
def make_validator(groups)
86+
groups = @domain.groups(groups)
87+
@validator.new(@ldap, groups)
88+
end
89+
90+
def test_validates_user_in_group
91+
validator = make_validator(%w(nested-group1))
92+
assert validator.perform(@entry)
93+
end
94+
95+
def test_validates_user_in_child_group
96+
validator = make_validator(%w(n-depth-nested-group1))
97+
assert validator.perform(@entry)
98+
end
99+
100+
def test_validates_user_in_grandchild_group
101+
validator = make_validator(%w(n-depth-nested-group2))
102+
assert validator.perform(@entry)
103+
end
104+
105+
def test_validates_user_in_great_grandchild_group
106+
validator = make_validator(%w(n-depth-nested-group3))
107+
assert validator.perform(@entry)
108+
end
109+
110+
def test_does_not_validate_user_not_in_group
111+
validator = make_validator(%w(ghe-admins))
112+
refute validator.perform(@entry)
113+
end
114+
115+
def test_does_not_validate_user_not_in_any_group
116+
skip "update AD ldif to have a groupless user"
117+
@entry = @domain.user?('groupless-user1')
118+
validator = make_validator(%w(all-users))
119+
refute validator.perform(@entry)
120+
end
121+
122+
def test_validates_user_in_posix_group
123+
validator = make_validator(%w(posix-group1))
124+
assert validator.perform(@entry)
125+
end
126+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
env.sh
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Local ActiveDirectory Integration Testing
2+
3+
Integration tests are not run for ActiveDirectory in continuous integration
4+
because we cannot install a Windows VM on TravisCI. To test ActiveDirectory,
5+
configure a local VM with AD running (this is left as an exercise for the
6+
reader).
7+
8+
To run integration tests against the local ActiveDirectory VM, from the project
9+
root run:
10+
11+
``` bash
12+
# duplicate example env.sh for specific config
13+
$ cp test/support/vm/activedirectory/env.sh{.example,}
14+
15+
# edit env.sh and fill in with your VM's values, then
16+
$ source test/support/vm/activedirectory/env.sh
17+
18+
# run all tests against AD
19+
$ time bundle exec rake
20+
21+
# run a specific test file against AD
22+
$ time bundle exec ruby test/membership_validators/active_directory_test.rb
23+
24+
# reset environment to test other LDAP servers
25+
$ source test/support/vm/activedirectory/reset-env.sh
26+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copy this to ad-env.sh, and fill in with your own values
2+
3+
export TESTENV=activedirectory
4+
export INTEGRATION_HOST=123.123.123.123
5+
export INTEGRATION_PORT=389
6+
export INTEGRATION_USER="CN=Administrator,CN=Users,DC=ad,DC=example,DC=com"
7+
export INTEGRATION_PASSWORD='passworD1'
8+
export INTEGRATION_SEARCH_DOMAINS='CN=Users,DC=example,DC=com'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
unset TESTENV
2+
unset INTEGRATION_HOST
3+
unset INTEGRATION_PORT
4+
unset INTEGRATION_USER
5+
unset INTEGRATION_PASSWORD
6+
unset INTEGRATION_SEARCH_DOMAINS

test/support/vm/openldap/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ $ ip=$(vagrant ssh -- "ifconfig eth1 | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]
1616
$ cd ../../../..
1717

1818
# run all tests against OpenLDAP
19-
$ time TESTENV=openldap OPENLDAP_HOST=$ip bundle exec rake
19+
$ time TESTENV=openldap INTEGRATION_HOST=$ip bundle exec rake
2020

2121
# run a specific test file against OpenLDAP
22-
$ time TESTENV=openldap OPENLDAP_HOST=$ip bundle exec ruby test/membership_validators/recursive_test.rb
22+
$ time TESTENV=openldap INTEGRATION_HOST=$ip bundle exec ruby test/membership_validators/recursive_test.rb
2323

2424
# run OpenLDAP tests by default
2525
$ export TESTENV=openldap

test/test_helper.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,23 @@ def options
7171
instrumentation_service: @service
7272
when "openldap"
7373
{
74-
host: ENV.fetch("OPENLDAP_HOST", "localhost"),
74+
host: ENV.fetch("INTEGRATION_HOST", "localhost"),
7575
port: 389,
7676
admin_user: 'uid=admin,dc=github,dc=com',
7777
admin_password: 'passworD1',
7878
search_domains: %w(dc=github,dc=com),
7979
uid: 'uid',
8080
instrumentation_service: @service
8181
}
82+
when "activedirectory"
83+
{
84+
host: ENV.fetch("INTEGRATION_HOST"),
85+
port: ENV.fetch("INTEGRATION_PORT", 389),
86+
admin_user: ENV.fetch("INTEGRATION_USER"),
87+
admin_password: ENV.fetch("INTEGRATION_PASSWORD"),
88+
search_domains: ENV.fetch("INTEGRATION_SEARCH_DOMAINS"),
89+
instrumentation_service: @service
90+
}
8291
end
8392
end
8493
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy