ldap-filter 0.0.2 → 0.1.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.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Eduardo Gutierrez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -3,10 +3,15 @@ module LDAP
3
3
  class Base
4
4
  attr_accessor :key, :value
5
5
 
6
- def initialize key, value, inverse=false
6
+ def initialize key, value, options={}
7
+ options = {
8
+ inverse: false
9
+ }.merge! options
10
+
7
11
  @key = key
8
12
  @value = value.to_s
9
- @not = inverse
13
+ @wildcard_placements = [options[:wildcard]].flatten
14
+ @not = options[:inverse]
10
15
  end
11
16
 
12
17
  def to_s
@@ -36,7 +41,21 @@ module LDAP
36
41
  private
37
42
 
38
43
  def condition
39
- [@key, '=', @value].join
44
+ [
45
+ @key, '=',
46
+ wildcard(:left),
47
+ value_with_wildcards,
48
+ wildcard(:right)
49
+ ].join
50
+ end
51
+
52
+ def value_with_wildcards
53
+ return @value unless @wildcard_placements.include? :inside
54
+ @value.split.join('*')
55
+ end
56
+
57
+ def wildcard position
58
+ '*' if @wildcard_placements.include? position
40
59
  end
41
60
  end
42
61
  end
@@ -46,10 +46,11 @@ module LDAP
46
46
 
47
47
  def populate_from_hash mappings
48
48
  raise ArgumentError, 'compound filters require more than one key' if mappings.keys.size < 2
49
- mappings.map do |key, values|
50
- case values
51
- when Array then Compound.new('|', key, *values)
52
- else Base.new(key, values)
49
+ mappings.map do |key, values_or_options|
50
+ case values_or_options
51
+ when Array then Compound.new('|', key, *values_or_options)
52
+ when Hash then Base.new(key, values_or_options.delete(:value), values_or_options)
53
+ else Base.new(key, values_or_options)
53
54
  end
54
55
  end
55
56
  end
@@ -1,5 +1,5 @@
1
1
  module LDAP
2
2
  module Filter
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -46,6 +46,27 @@ module LDAP
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ describe "uses options to place wildcards" do
51
+ it "after the value" do
52
+ filter = Base.new :sn, 'Smith', wildcard: :right
53
+ filter.to_s.should eq '(sn=Smith*)'
54
+ end
55
+
56
+ it "before the value" do
57
+ filter = Base.new :sn, 'Smith', wildcard: :left
58
+ filter.to_s.should eq '(sn=*Smith)'
59
+ end
60
+
61
+ it "inbetween pieces of the string" do
62
+ filter = Base.new :cn, 'John Smith', wildcard: :inside
63
+ filter.to_s.should eq '(cn=John*Smith)'
64
+ end
65
+
66
+ it "around the value using :left and :right options" do
67
+ filter = Base.new :sn, 'Smith', wildcard: [:left, :right]
68
+ end
69
+ end
49
70
  end
50
71
  end
51
72
  end
@@ -38,6 +38,16 @@ module LDAP
38
38
  it "so long as more than one key is supplied" do
39
39
  expect { Compound.new('|', { givenName: 'John' }) }.to raise_error ArgumentError
40
40
  end
41
+
42
+ it "with options for the base filter" do
43
+ attributes = {
44
+ givenName: { value: 'Jo', wildcard: :right },
45
+ cn: { value: 'John Smith', wildcard: :inside }
46
+ }
47
+
48
+ filter = Compound.new(operator, attributes)
49
+ filter.to_s.should eq '(&(givenName=Jo*)(cn=John*Smith))'
50
+ end
41
51
  end
42
52
 
43
53
  describe "can be built from an array of string values" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldap-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-29 00:00:00.000000000 Z
12
+ date: 2012-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70149773001600 !ruby/object:Gem::Requirement
16
+ requirement: &70202009069580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70149773001600
24
+ version_requirements: *70202009069580
25
25
  description: DSL for dynamically building complex LDAP filters without concern for
26
26
  closing parentheses
27
27
  email:
@@ -34,6 +34,7 @@ files:
34
34
  - .rspec
35
35
  - CHANGELOG
36
36
  - Gemfile
37
+ - LICENSE
37
38
  - README.md
38
39
  - Rakefile
39
40
  - ldap-filter.gemspec