Skip to content

Commit f008a49

Browse files
committed
Add simple, stubbed ActiveDirectory membership validator tests
1 parent 22333a0 commit f008a49

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
require_relative '../test_helper'
2+
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.
6+
7+
class GitHubLdapActiveDirectoryMembershipValidatorsTest < GitHub::Ldap::Test
8+
def setup
9+
@ldap = GitHub::Ldap.new(options.merge(search_domains: %w(dc=github,dc=com)))
10+
@domain = @ldap.domain("dc=github,dc=com")
11+
@entry = @domain.user?('user1')
12+
@validator = GitHub::Ldap::MembershipValidators::ActiveDirectory
13+
end
14+
15+
def make_validator(groups)
16+
groups = @domain.groups(groups)
17+
@validator.new(@ldap, groups)
18+
end
19+
20+
# Stub search to return the given results.
21+
def stub_search(result)
22+
@ldap.stub :search, result do
23+
yield
24+
end
25+
end
26+
27+
def test_validates_user_in_group
28+
stub_search [@entry] do
29+
validator = make_validator(%w(nested-group1))
30+
assert validator.perform(@entry)
31+
end
32+
end
33+
34+
def test_validates_user_in_child_group
35+
stub_search [@entry] do
36+
validator = make_validator(%w(n-depth-nested-group1))
37+
assert validator.perform(@entry)
38+
end
39+
end
40+
41+
def test_validates_user_in_grandchild_group
42+
stub_search [@entry] do
43+
validator = make_validator(%w(n-depth-nested-group2))
44+
assert validator.perform(@entry)
45+
end
46+
end
47+
48+
def test_validates_user_in_great_grandchild_group
49+
stub_search [@entry] do
50+
validator = make_validator(%w(n-depth-nested-group3))
51+
assert validator.perform(@entry)
52+
end
53+
end
54+
55+
def test_does_not_validate_user_not_in_group
56+
stub_search [] do
57+
validator = make_validator(%w(ghe-admins))
58+
refute validator.perform(@entry)
59+
end
60+
end
61+
62+
def test_does_not_validate_user_not_in_any_group
63+
entry = @domain.user?('groupless-user1')
64+
65+
stub_search [] do
66+
validator = make_validator(%w(all-users))
67+
refute validator.perform(entry)
68+
end
69+
end
70+
71+
def test_validates_user_in_posix_group
72+
stub_search [@entry] do
73+
validator = make_validator(%w(posix-group1))
74+
assert validator.perform(@entry)
75+
end
76+
end
77+
end

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require 'github/ldap'
1111
require 'github/ldap/server'
1212

13+
require 'minitest/mock'
1314
require 'minitest/autorun'
1415

1516
if ENV.fetch('TESTENV', "apacheds") == "apacheds"

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