Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code/tests to apply almost rubocop rules #60

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true

[*.rdoc]
max_line_length = off
trim_trailing_whitespace = false
22 changes: 16 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
*.swp
.idea
.bin
.bundle
*.gem
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

/Gemfile.lock
.rvmrc
.ruby-gemset
.ruby-version
Gemfile.lock
*.gem
/vendor/bundle

# Misc.
.DS_Store
*.swp
/.idea/
96 changes: 20 additions & 76 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,92 +1,36 @@
LineLength:
Max: 120

ParameterLists:
Max: 5

MethodLength:
Max: 15

CollectionMethods:
# remove this once we pick either map or collect, inject or reduce, etc
PreferredMethods: {}
AllCops:
TargetRubyVersion: 2.3

StringLiterals:
Style/Documentation:
Enabled: false

SpaceAroundBraces:
Enabled: false # remove me

RedundantSelf:
Enabled: false # remove me

Encoding:
Enabled: false # remove me?

RedundantReturn:
Enabled: false # remove me

SpaceInsideHashLiteralBraces:
Enabled: false # remove me

Void:
Enabled: false # remove me

BlockNesting:
Enabled: false # remove me

AvoidPerlBackrefs:
Enabled: false # remove me

Documentation:
Enabled: false # remove me

# end TODO

# AllCops:
# Excludes:

SpaceInsideHashLiteralBraces:
EnforcedStyleIsWithSpaces: false

HashSyntax:
Enabled: false # don't force 1.9 hash syntax

SpaceInsideHashLiteralBraces:
Enabled: false # allow spaces (eg { :a => 1 })

LeadingCommentSpace:
Enabled: false

IfUnlessModifier:
Enabled: false
Metrics/LineLength:
Max: 120

RescueModifier:
Gemspec/RequiredRubyVersion:
Enabled: false

AssignmentInCondition:
Style/ExpandPathArguments:
Enabled: false

FavorUnlessOverNegatedIf:
Enabled: false
Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%w': '[]'

WhileUntilModifier:
Style/SymbolArray:
Enabled: false

AlignParameters:
Enabled: false # don't care if parameters are not aligned

ParenthesesAroundCondition:
Enabled: false
Naming/UncommunicativeMethodParamName:
AllowedNames:
- cn
- dn

DotPosition:
Style/ClassAndModuleChildren:
Enabled: false

Lambda:
Enabled: false # don't require -> for single line lambdas

HashMethods:
Enabled: false
Metrics/ClassLength:
Exclude:
- 'test/**/*'

ReduceArguments:
Layout/EndOfLine:
Enabled: false
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
sudo: false
language: ruby
cache: bundler
rvm:
- '1.9.3'
- '2.0.0'
- '2.0.0'
- '2.1.8'
- '2.2.4'
- '2.3.0'

script:
- "./travis/ldapfluff_up_to_snuff.sh"
- 1.9.3
- 2.0
- 2.3
- ruby
- jruby
before_script: bundle exec rubocop
script: bundle exec rake
13 changes: 2 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# vim:ft=ruby
# frozen_string_literal: true

source 'https://rubygems.org'

if RUBY_VERSION.start_with? '1.9'
gem 'net-ldap', '< 0.13'
end

unless RUBY_VERSION >= '2.2'
gem 'activesupport', '< 5'
end

# Specify gem's dependencies in the gemspec file
gemspec

gem 'rubocop', :group => :test if RUBY_VERSION >= '2.0'
31 changes: 20 additions & 11 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ It exposes these methods:
user_list(gid)
returns the set of users that belong to an LDAP group

is_in_groups?(uid, grouplist)
user_in_groups?(uid, grouplist)
returns true if the user provided is in all of the groups listed in grouplist

valid_user?(uid)
Expand All @@ -34,10 +34,10 @@ It exposes these methods:
valid_group?(uid)
returns true if the group provided exists

find_user(uid)
find_user(uid, only = nil)
returns the LDAP entry of the user if found, nil if not found

find_group(gid)
find_group(gid, only = nil)
returns the LDAP entry of the group if found, nil if not found

These methods are handy for using LDAP for both authentication and authorization.
Expand All @@ -49,23 +49,25 @@ Your global configuration must provide information about your LDAP host to funct
host: # ip address or hostname
port: # port
encryption: # blank, :simple_tls, or :start_tls
base_dn: # base DN for LDAP auth, eg dc=redhat,dc=com
base_dn: # base DN for LDAP auth, eg dc=redhat,dc=com
group_base: # base DN for your LDAP groups, eg ou=Groups,dc=redhat,dc=com
use_netgroups: # false by default, use true if you want to use netgroup triples,
# supported only for server type :free_ipa and :posix
server_type: # type of server. default == :posix. :active_directory, :posix, :free_ipa
ad_domain: # domain for your users if using active directory, eg redhat.com
server_type: # type of server. default == :posix. :active_directory, :posix, :free_ipa
ad_domain: # domain for your users if using active directory, eg redhat.com
service_user: # service account for authenticating LDAP calls. required unless you enable anon
service_pass: # service password for authenticating LDAP calls. required unless you enable anon
anon_queries: # false by default, true if you don't want to use the service user
instrumentation_service: # nil by default, an object that supports the ActiveSupport::Notifications API

You can pass these arguments as a hash to LdapFluff to get a valid LdapFluff object.

ldap_config = { :host => "freeipa.localdomain", :port => 389, :encryption => nil, :base_dn => "DC=mydomain,DC=com",
:group_base => "DC=groups,DC=mydomain,DC=com", :attr_login => "uid", :server_type => :free_ipa,
:service_user => "admin", :search_filter => "(objectClass=*)", :service_pass => "mypass",
:anon_queries => false }
ldap_config = {
:host => "freeipa.localdomain", :port => 389, :encryption => nil, :base_dn => "DC=mydomain,DC=com",
:group_base => "DC=groups,DC=mydomain,DC=com", :attr_login => "uid", :server_type => :free_ipa,
:service_user => "admin", :search_filter => "(objectClass=*)", :service_pass => "mypass",
:anon_queries => false
}

fluff = LdapFluff.new(ldap_config)
fluff.valid_user?("admin") # returns true
Expand Down Expand Up @@ -99,6 +101,13 @@ ActiveSupport::Notifications. ldap_fluff will use this and also pass it to net-
When using Rails, pass `:instrumentation_service => ActiveSupport::Notifications` and then subscribe to, and
optionally log events (e.g. https://gist.github.com/mnutt/566725).

=== License
== Development

After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake` to run the tests.
You can also run `irb -r bundler/setup -r ldap_fluff` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`.

== License

ldap_fluff is licensed under the GPLv2. Please read LICENSE for more information.
20 changes: 9 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
require 'rubygems'
require 'rake/testtask'

# The default task is run if rake is given no explicit arguments.
desc 'Default Task'
task :default => :test
# frozen_string_literal: true

# Test Tasks ---------------------------------------------------------
require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new('test') do |t|
t.libs = %w[lib test]
t.test_files = FileList['test/**/*.rb']
t.verbose = true
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end

task default: :test
32 changes: 19 additions & 13 deletions ldap_fluff.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# frozen_string_literal: true

Gem::Specification.new do |s|
s.name = 'ldap_fluff'
s.version = '0.4.7'
s.version = '0.5.1'
s.summary = 'LDAP querying tools for Active Directory, FreeIPA and POSIX-style'
s.description = 'Simple library for binding & group querying on top of various LDAP implementations'
s.homepage = 'https://github.com/theforeman/ldap_fluff'
s.license = 'GPLv2'
s.files = Dir['lib/**/*.rb'] + Dir['test/**/*.rb'] + ['README.rdoc', 'LICENSE']
s.extra_rdoc_files = ['README.rdoc', 'LICENSE']

s.require_path = 'lib'
s.test_files = Dir['test/**/*.rb']
s.extra_rdoc_files = %w[README.rdoc LICENSE]
s.files = s.extra_rdoc_files + Dir['lib/**/*.rb']

s.require_paths = ['lib']
s.test_files = Dir['test/**/*.rb']

s.authors = ['Jordan O\'Mara', 'Daniel Lobato', 'Petr Chalupa', 'Adam Price', 'Marek Hulan', 'Dominic Cleal']
s.email = %w[[email protected] [email protected] [email protected] [email protected] [email protected]
[email protected]]

s.required_ruby_version = '>= 1.9.3'

s.has_rdoc = true
s.author = ['Jordan O\'Mara', 'Daniel Lobato', 'Petr Chalupa', 'Adam Price', 'Marek Hulan', 'Dominic Cleal']
s.email = %w([email protected] [email protected] [email protected] [email protected] [email protected] [email protected])
s.add_dependency 'net-ldap', '~> 0.12'

s.required_ruby_version = ">= 1.9.3"
s.add_development_dependency 'bundler', '>= 1.14'
s.add_development_dependency 'rake', '>= 10.0'

s.add_dependency('net-ldap', '>= 0.3.1')
s.add_dependency('activesupport')
s.add_development_dependency('rake')
s.add_development_dependency('minitest')
s.add_development_dependency 'minitest', '~> 5.0'
s.add_development_dependency 'rubocop'
end
Loading