lita-activedirectory 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2116b9afea5a43594d2a05dcb820478bf7dc77b
4
- data.tar.gz: 3064e8736c414881a2f8315e03078156d907d377
3
+ metadata.gz: 412986b1be4db4a3d2784fa4801428741f52db16
4
+ data.tar.gz: ccd12b861e7828310332e03443e7c2de3593bf46
5
5
  SHA512:
6
- metadata.gz: 5bd717b7b920ea433a22c91f66d96c7ebf01387d9b46410f87b4cbb1b8aba5dd82ac151c526ae457f4857ca88f413e6f2de6e1243dabd7f4e42dc761f85c7880
7
- data.tar.gz: 5a328472b8201cbf8cf0edb32400e4bf2e2f7ec192fc449aa94219a473902483685cce4aa49ec1ad5c028af7db3a10f79f9c9b56f9a52558f7ae5c2a8380195d
6
+ metadata.gz: 83f7c00513b82d81387530b8e7a2405cf5c266d6b88cdda5f36676d46cc05a99a9cb64d9f00a94e22e1a78ba9fb1a9583fb71c89bbbafc0a25de00ae6b0290a7
7
+ data.tar.gz: d9dcca88b3e7cf255da6422e91582d402cf2829b24f9db0b0fc5c46dd417d3766b7fbe93ab46ee18d7a544f9fb5b736b16ae09fb0ce2f62d8df7aefc10a362cf
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ dump.rdb
data/.rubocop.yml CHANGED
@@ -17,3 +17,11 @@ Metrics/MethodLength:
17
17
 
18
18
  Metrics/ClassLength:
19
19
  Max: 150
20
+
21
+ Metrics/BlockLength:
22
+ Max: 30
23
+ Exclude:
24
+ - '*.gemspec'
25
+ - Rakefile
26
+ - 'spec/**/*_spec.rb'
27
+ - 'spec/spec_helper.rb'
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # lita-activedirectory
2
- [![Build Status](https://travis-ci.org/knuedge/lita-activedirectory.svg?branch=master)](https://travis-ci.org/knuedge/lita-activedirectory)
2
+ [![Build Status](https://travis-ci.org/knuedge/lita-activedirectory.svg?branch=master)](https://travis-ci.org/knuedge/lita-activedirectory) [![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://tldrlegal.com/license/mit-license) [![Gem](https://img.shields.io/gem/v/formatador.svg)](https://rubygems.org/gems/lita-activedirectory) [![Code Climate](https://codeclimate.com/github/knuedge/lita-activedirectory/badges/gpa.svg)](https://codeclimate.com/github/knuedge/lita-activedirectory)
3
3
 
4
4
  A [Lita](https://www.lita.io/) handler plugin for basic interactions with Active Directory.
5
5
 
@@ -33,4 +33,7 @@ The user account specified in `config.handlers.activedirectory.username` must ha
33
33
  ### List a User's Group Memberships
34
34
  `<username> groups>`
35
35
 
36
+ ### List a Group's Members
37
+ `group <groupname> members`
38
+
36
39
 
@@ -31,6 +31,13 @@ module Lita
31
31
  help: { t('help.user_groups.syntax') => t('help.user_groups.desc') }
32
32
  )
33
33
 
34
+ route(
35
+ /^(group)\s+(\S+)\s+(members)$/i,
36
+ :group_members,
37
+ command: true,
38
+ help: { t('help.group_members.syntax') => t('help.group_members.desc') }
39
+ )
40
+
34
41
  include ::Utils::Cratususer
35
42
 
36
43
  def user_locked?(response)
@@ -63,6 +70,19 @@ module Lita
63
70
  end
64
71
  end
65
72
 
73
+ def group_members(response)
74
+ group = response.matches[0][1]
75
+ response.reply_with_mention(t('replies.group_members.working'))
76
+ result = group_mem_query(group)
77
+ if result.nil?
78
+ response.reply_with_mention(
79
+ t('replies.group_members.error, group: group')
80
+ )
81
+ else
82
+ response.reply result
83
+ end
84
+ end
85
+
66
86
  private
67
87
 
68
88
  def handle_user_query(response, user, result)
@@ -36,6 +36,17 @@ module Utils
36
36
  groups.map(&:name).join("\n")
37
37
  end
38
38
 
39
+ def group_mem_query(groupname)
40
+ cratus_connect
41
+ group = begin
42
+ Cratus::Group.new(groupname.to_s)
43
+ rescue
44
+ nil
45
+ end
46
+ members = group.members
47
+ members.map(&:fullname).join("\n")
48
+ end
49
+
39
50
  def unlock_user(username)
40
51
  ldap = Cratus::LDAP.connection
41
52
  ldap.replace_attribute Cratus::User.new(username.to_s).dn, :lockouttime, '0'
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-activedirectory'
3
- spec.version = '0.2.6'
3
+ spec.version = '0.2.7'
4
4
  spec.authors = ['Daniel Schaaff']
5
5
  spec.email = ['dschaaff@knuedge.com']
6
6
  spec.description = 'ldap/active directory instructions for Lita'
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rack-test'
26
26
  spec.add_development_dependency 'rspec', '>= 3.0.0'
27
27
  spec.add_development_dependency 'simplecov'
28
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
28
29
  spec.add_development_dependency 'coveralls'
29
30
  spec.add_development_dependency 'rubocop'
30
31
  spec.add_development_dependency 'travis', '~> 1.8'
data/locales/en.yml CHANGED
@@ -12,6 +12,9 @@ en:
12
12
  user_groups:
13
13
  syntax: <username> groups
14
14
  desc: lists all group memberships for the given username
15
+ group_members:
16
+ syntax: group <groupname> members
17
+ desc: lists all members of the given group
15
18
  replies:
16
19
  user_locked?:
17
20
  working: let me check on that
@@ -27,3 +30,6 @@ en:
27
30
  success: "'%{user}' is a member of"
28
31
  not_found: "could not find any groups that '%{user}' is a member of"
29
32
  error: "That did not work, double check the '%{user}' is a valid samAccountName"
33
+ group_members:
34
+ working: Give me a second to search
35
+ error: "That did not work, double check the '%{group}' is a valid group name"
@@ -1,4 +1,78 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Lita::Handlers::Activedirectory, lita_handler: true do
4
+ before do
5
+ registry.config.handlers.activedirectory.host = 'ldap.example.com'
6
+ registry.config.handlers.activedirectory.basedn = 'dc=example,dc=com'
7
+ registry.config.handlers.activedirectory.user_basedn = 'ou=users,dc=example,dc=com'
8
+ registry.config.handlers.activedirectory.group_basedn = 'ou=groups,dc=example,dc=com'
9
+ registry.config.handlers.activedirectory.username = 'user'
10
+ registry.config.handlers.activedirectory.password = 'pass'
11
+ end
12
+
13
+ it 'should have the necessary routes' do
14
+ is_expected.to route_command('is jdoe locked').to(:user_locked?)
15
+ is_expected.to route_command('is jdoe locked?').to(:user_locked?)
16
+ is_expected.to route_command('unlock jdoe').to(:unlock)
17
+ is_expected.to route_command('jdoe groups').to(:user_groups)
18
+ is_expected.to route_command('group foo members').to(:group_members)
19
+ end
20
+
21
+ let(:locked_user) do
22
+ testuser = instance_double(
23
+ 'Cratus::User',
24
+ dn: 'cn=jdoe,dc=example,dc=com',
25
+ lockouttime: '124',
26
+ locked?: true
27
+ )
28
+ testuser
29
+ end
30
+
31
+ let(:unlocked_user) do
32
+ testuser = instance_double(
33
+ 'Cratus::User',
34
+ dn: 'cn=jdoe,dc=example,dc=com',
35
+ lockouttime: '0',
36
+ locked?: false
37
+ )
38
+ testuser
39
+ end
40
+
41
+ describe '#user_locked?' do
42
+ it 'lets you know if the user is locked' do
43
+ allow(Cratus::LDAP).to receive(:connect).and_return(true)
44
+ allow(Cratus::User).to receive(:new).and_return(locked_user)
45
+ send_command('is jdoe locked?')
46
+ expect(replies.first).to eq('let me check on that')
47
+ expect(replies.last).to eq("looks like 'jdoe' is locked")
48
+ end
49
+ it 'lets you know if a user is not locked' do
50
+ allow(Cratus::LDAP).to receive(:connect).and_return(true)
51
+ allow(Cratus::User).to receive(:new).and_return(unlocked_user)
52
+ send_command('is jdoe locked?')
53
+ expect(replies.first).to eq('let me check on that')
54
+ expect(replies.last).to eq("'jdoe' is not locked")
55
+ end
56
+ end
57
+
58
+ describe '#unlock' do
59
+ it 'unlocks the user when locked' do
60
+ allow(Cratus::LDAP).to receive(:connect).and_return(true)
61
+ allow(Cratus::LDAP).to receive(:connection).and_return(true)
62
+ allow(Cratus::User).to receive(:new).and_return(locked_user)
63
+ allow(Cratus::LDAP.connection).to receive(:replace_attribute).and_return(true)
64
+ send_command('unlock jdoe')
65
+ expect(replies.first).to eq('lets see what we can do')
66
+ expect(replies.last).to eq("'jdoe' has been unlocked")
67
+ end
68
+ it 'lets you know if the user is not locked' do
69
+ allow(Cratus::LDAP).to receive(:connect).and_return(true)
70
+ allow(Cratus::LDAP).to receive(:connection).and_return(true)
71
+ allow(Cratus::User).to receive(:new).and_return(unlocked_user)
72
+ allow(Cratus::LDAP.connection).to receive(:replace_attribute).and_return(true)
73
+ send_command('unlock jdoe')
74
+ expect(replies.first).to eq('lets see what we can do')
75
+ expect(replies.last).to eq("'jdoe' is not locked")
76
+ end
77
+ end
4
78
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'simplecov'
2
- require 'coveralls'
2
+ # require 'coveralls'
3
3
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
4
  SimpleCov::Formatter::HTMLFormatter,
5
- Coveralls::SimpleCov::Formatter
5
+ # Coveralls::SimpleCov::Formatter
6
6
  ]
7
7
  SimpleCov.start { add_filter '/spec/' }
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-activedirectory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schaaff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-15 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: codeclimate-test-reporter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.0.0
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: coveralls
127
141
  requirement: !ruby/object:Gem::Requirement