ldap_groups_lookup 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89497393dbd1cb8187e740a5867c0758a6a47eb79ae4719bf2e09ba0952011ac
4
- data.tar.gz: e9e7db4530168f315c7b7463beeb395d94aa49411fc2a7d92cba6152136600ce
3
+ metadata.gz: 03dc7b2a955c218d89b8f2e50c630c132763812ba9ab49d40d8ec943f1d18ed6
4
+ data.tar.gz: 8e7f97b9c2ecb249ba28878b62f25334439da70b697c158ca632c6856c9fbe01
5
5
  SHA512:
6
- metadata.gz: be721599c153b22b93fc7769377610619d24d74973e3316f7ebd427341a1c5830cc71d45df67cb78671773347c865999b65e18e2cf349759e005d42c84b5b337
7
- data.tar.gz: f5f4aa7a0d10008ee984cc495076fb669b6113bf8ac52012f8c6806f7b14cb8c1ac12bd340a98a1585168be8cb2101d29da1aa6aef154d04d8222e6f3e8c9f11
6
+ metadata.gz: d093962f123dea981ef105d2186d760205671d2f529465bdd1f9c235e03b81c822d37a31e3e057c9ee2c06ef628b6d23fa63c844fe527f4f8792a1ff33017234
7
+ data.tar.gz: c8100e276441ffa86ac707844bc41cb2e199e7acacdcd15cf06c45507c8ccd22ff966222e78b0100e925e40d1724e6557fe9d42596c5bb48a28ba1515c677e98
@@ -0,0 +1,38 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "main" ]
13
+ pull_request:
14
+ branches: [ "main" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.7', '3.2']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ # uses: ruby/setup-ruby@v1
33
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Run tests
38
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # IU LDAP Groups Lookup
2
2
 
3
+ ## Usage
4
+
3
5
  Adds an LDAPGroupsLookup that can be included in a a class to provide an #ldap_groups instance method:
4
6
 
5
- ```
7
+ ```ruby
6
8
  class User
7
9
  attr_accessor :ldap_lookup_key
8
10
  include LDAPGroupsLookup::Behavior
@@ -16,7 +18,7 @@ u.member_of_ldap_group?(['Some-Group'])
16
18
 
17
19
  The LDAP search will be run by the value of #ldap_lookup_key, so your instance object must provide that through some means:
18
20
 
19
- ```
21
+ ```ruby
20
22
  class User < ActiveRecord::Base
21
23
  validates :username, presence: true, uniqueness: true
22
24
  alias_attribute :ldap_lookup_key, :username
@@ -27,3 +29,22 @@ u = User.find_by(username: 'some_username')
27
29
  u.ldap_groups
28
30
  u.member_of_ldap_group?(['Some-Group'])
29
31
  ```
32
+
33
+ ## Configuration
34
+
35
+ Create a file `config/ldap_groups_lookup.yml` that looks like:
36
+
37
+ ```yaml
38
+ :enabled: true
39
+ :host: ads.example.net
40
+ :port: 636
41
+ :auth:
42
+ :method: :simple
43
+ :username: example
44
+ :password: changeme
45
+ :tree: dc=ads,dc=example,dc=net
46
+ :account_ou: ou=Accounts
47
+ :group_ou: ou=Groups
48
+ :member_whitelist:
49
+ - OU=Groups
50
+ ```
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ['lib']
18
18
  gem.required_ruby_version = '>= 2.3.0'
19
+ gem.metadata = { "rubygems_mfa_required" => "true" }
19
20
 
20
21
  gem.add_dependency 'net-ldap'
21
22
  gem.add_development_dependency 'rake'
@@ -9,7 +9,7 @@ module LDAPGroupsLookup
9
9
  def service
10
10
  return nil if config[:enabled] == false
11
11
  if @ldap_service.nil?
12
- @ldap_service = Net::LDAP.new(host: config[:host], auth: config[:auth])
12
+ @ldap_service = Net::LDAP.new(host: config[:host], port: config[:port] || Net::LDAP::DefaultPort, auth: config[:auth])
13
13
  raise Net::LDAP::Error unless @ldap_service.bind
14
14
  end
15
15
  @ldap_service
@@ -45,13 +45,17 @@ module LDAPGroupsLookup
45
45
  config[:tree]
46
46
  end
47
47
 
48
+ def member_whitelist
49
+ config[:member_whitelist].to_a
50
+ end
51
+
48
52
  private
49
53
 
50
54
  def configure(value)
51
55
  if value.nil? || value.is_a?(Hash)
52
56
  @config = value
53
57
  elsif value.is_a?(String)
54
- if File.exists?(value)
58
+ if File.exist?(value)
55
59
  @config = YAML.load(ERB.new(File.read(value)).result)
56
60
  else
57
61
  @config = { enabled: false }
@@ -57,7 +57,9 @@ module LDAPGroupsLookup
57
57
  next if seen.include? g
58
58
  seen << g
59
59
  member_groups = members.collect do |mg|
60
- dn_to_cn(mg) if (mg.include?('OU=Groups') || mg.include?('OU=Applications'))
60
+ dn_to_cn(mg) if member_whitelist.empty? || member_whitelist.any? do |fil|
61
+ mg.include? fil
62
+ end
61
63
  end
62
64
  member_groups.compact!
63
65
  return true if walk_ldap_members(member_groups, dn, seen)
@@ -1,5 +1,5 @@
1
1
  # Gem version release tracking
2
2
  module LDAPGroupsLookup
3
3
  # Define release version
4
- VERSION = '0.6.1'.freeze
4
+ VERSION = '0.8.0'.freeze
5
5
  end
@@ -1,9 +1,12 @@
1
1
  :enabled: true
2
2
  :host: ads.example.net
3
+ :port: 636
3
4
  :auth:
4
5
  :method: :simple
5
6
  :username: example
6
7
  :password: changeme
7
8
  :tree: dc=ads,dc=example,dc=net
8
9
  :account_ou: ou=Accounts
9
- :group_ou: ou=Groups
10
+ :group_ou: ou=Groups
11
+ :member_whitelist:
12
+ - OU=Groups
@@ -28,7 +28,7 @@ RSpec.describe LDAPGroupsLookup do
28
28
  context 'when the config file is missing' do
29
29
  before do
30
30
  allow(LDAPGroupsLookup).to receive(:config).and_call_original
31
- expect(File).to receive(:exists?).with(/config\/ldap_groups_lookup\.yml$/)
31
+ expect(File).to receive(:exist?).with(/config\/ldap_groups_lookup\.yml$/)
32
32
  end
33
33
  it 'should return nil' do
34
34
  expect(LDAPGroupsLookup.service).to be_nil
@@ -216,16 +216,39 @@ RSpec.describe LDAPGroupsLookup do
216
216
  end
217
217
  end
218
218
  context 'when searching for a group that user is a nested member of' do
219
- it 'should return true' do
219
+ before do
220
220
  expect(@service).to receive(:search).with(
221
221
  hash_including(filter: Net::LDAP::Filter.equals('cn', 'Top-Group'))).and_return([@top_group])
222
- expect(@service).to receive(:search).with(
222
+ allow(@service).to receive(:search).with(
223
223
  hash_including(filter: Net::LDAP::Filter.equals('cn', 'Nested-Group'),
224
224
  attributes: ['member;range=0-*'])).and_return([@nested_group_page_1])
225
- expect(@service).to receive(:search).with(
225
+ allow(@service).to receive(:search).with(
226
226
  hash_including(filter: Net::LDAP::Filter.equals('cn', 'Nested-Group'),
227
227
  attributes: ['member;range=1-*'])).and_return([@nested_group_page_2])
228
- expect(user.member_of_ldap_group?('Top-Group')).to eq(true)
228
+ end
229
+ context 'when the group is whitelisted' do
230
+ before do
231
+ allow(LDAPGroupsLookup).to receive(:member_whitelist).and_return(['OU=Groups'])
232
+ end
233
+ it 'should return true' do
234
+ expect(user.member_of_ldap_group?('Top-Group')).to eq(true)
235
+ end
236
+ end
237
+ context 'when the whitelist is empty' do
238
+ before do
239
+ allow(LDAPGroupsLookup).to receive(:member_whitelist).and_return([])
240
+ end
241
+ it 'should return true (whitelisting is disabled)' do
242
+ expect(user.member_of_ldap_group?('Top-Group')).to eq(true)
243
+ end
244
+ end
245
+ context 'when the group is not whitelisted' do
246
+ before do
247
+ allow(LDAPGroupsLookup).to receive(:member_whitelist).and_return(['OU=Not-A-Match'])
248
+ end
249
+ it 'should return false' do
250
+ expect(user.member_of_ldap_group?('Top-Group')).to eq(false)
251
+ end
229
252
  end
230
253
  end
231
254
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldap_groups_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Ploshay
8
8
  - Daniel Pierce
9
9
  - Avalon Media System
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-06-27 00:00:00.000000000 Z
13
+ date: 2024-11-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: net-ldap
@@ -77,9 +77,9 @@ executables: []
77
77
  extensions: []
78
78
  extra_rdoc_files: []
79
79
  files:
80
+ - ".github/workflows/ruby.yml"
80
81
  - ".gitignore"
81
82
  - ".rspec"
82
- - ".travis.yml"
83
83
  - Gemfile
84
84
  - LICENSE
85
85
  - README.md
@@ -95,8 +95,9 @@ files:
95
95
  - spec/spec_helper.rb
96
96
  homepage: http://github.com/IUBLibTech/ldap_groups_lookup
97
97
  licenses: []
98
- metadata: {}
99
- post_install_message:
98
+ metadata:
99
+ rubygems_mfa_required: 'true'
100
+ post_install_message:
100
101
  rdoc_options: []
101
102
  require_paths:
102
103
  - lib
@@ -111,9 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  - !ruby/object:Gem::Version
112
113
  version: '0'
113
114
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.7.6.2
116
- signing_key:
115
+ rubygems_version: 3.5.17
116
+ signing_key:
117
117
  specification_version: 4
118
118
  summary: Provides easy access to the list of LDAP groups a username is a member of.
119
119
  test_files:
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3
4
- - 2.4
5
- - 2.5