mongoid-encrypted-fields 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmZkZTFkMzNjYzIwYTBkYWMxYzVmNzBlNjg2MjdiMWU4OGE2Njc0OA==
5
+ data.tar.gz: !binary |-
6
+ YmVjZTZmNGU4NDFiNzIwOTA4ZDdjZWE2M2I2Yjg0MThhMjYwOGU4Nw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ N2ViYzJlNGYzOTI1ZWY5NjQ5YjY3MWZjMTNmZjZhY2I3ZDIyMjMyYjJkMGJi
10
+ MTgxNmEwNmNjOTE2MmZiOTU1NjU2NDkzNjE1MjFhMGE3YWYyN2I0NjZkZGVk
11
+ ZjFkYmExNGY4NjM5MzVmNzJhMmU2YmIyZjc4MWI1OTNlZmM1MzQ=
12
+ data.tar.gz: !binary |-
13
+ MjIyNDViMDdhYmY3OGE5NjNlMWIyZWQ1NjJiZWVkZmUxNWNkYmY0NzMwNmUw
14
+ MzNkM2Y3ZTZlM2E2MmNjZmE2MzA2ODA4ZjZjMTk5M2RjMTUwYzIxMjgwYmE5
15
+ Y2JmMDgzNDM2Njk2OTYxYWFmZDNjZTdlMTc1YmY5YTg1Njk5YzU=
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
 
21
21
  #Ignore IDEA directory
22
22
  /.idea
23
+ .tags*
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - 1.9.3
5
+ notifications:
6
+ recipients:
7
+ - jerry.clinesmith@koanhealth.com
8
+ services:
9
+ - mongodb
data/CHANGLOG.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # Revision history
2
2
 
3
- ## 1.2.1 - Uniqueness validator fails if developer attempts to use case-insensitive option for an encrypted field
3
+ ## 1.2.2
4
+ * Accepted [pull request](https://github.com/KoanHealth/mongoid-encrypted-fields/pull/10) to support aliased fields with the uniqueness validator (@johnnyshields)
4
5
 
5
- ## 1.2 - Add EncryptedHash
6
+ ## 1.2.1
7
+ * Uniqueness validator fails if developer attempts to use case-insensitive option for an encrypted field
6
8
 
7
- * Accepted [pull request](https://github.com/KoanHealth/mongoid-encrypted-fields/pull/4) from ashirazi to add support for encrypted hashes
9
+ ## 1.2 - Add EncryptedHash
10
+ * Accepted [pull request](https://github.com/KoanHealth/mongoid-encrypted-fields/pull/4) to add support for encrypted hashes (@ashirazi)
8
11
 
9
12
  ## 1.1 - Breaking changes - PLEASE READ
10
13
 
data/Gemfile CHANGED
@@ -1,4 +1,13 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in mongoid-encrypted-fields.gemspec
4
2
  gemspec
3
+
4
+ gem 'rake'
5
+ gem 'mongoid', '~> 3'
6
+
7
+ gem 'coveralls', require: false
8
+
9
+ group :test do
10
+ gem 'rspec', '~> 2.13'
11
+ gem 'gibberish', '~> 1.2.2'
12
+ gem 'encrypted_strings', '~> 0.3'
13
+ end
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  mongoid-encrypted-fields
2
2
  ========================
3
+ [![Build Status](https://secure.travis-ci.org/KoanHealth/mongoid-encrypted-fields.png?branch=master&.png)](http://travis-ci.org/KoanHealth/mongoid-encrypted-fields)
4
+ [![Code Climate](https://codeclimate.com/github/KoanHealth/mongoid-encrypted-fields.png)](https://codeclimate.com/github/KoanHealth/mongoid-encrypted-fields)
5
+ [![Coverage Status](https://coveralls.io/repos/KoanHealth/mongoid-encrypted-fields/badge.png?branch=master)](https://coveralls.io/r/KoanHealth/mongoid-encrypted-fields)
6
+ [![Dependency Status](https://gemnasium.com/KoanHealth/mongoid-encrypted-fields.png)](https://gemnasium.com/KoanHealth/mongoid-encrypted-fields)
3
7
 
4
8
  A library for storing encrypted data in Mongo using Mongoid. We looked at a few alternatives, but wanted something that stored the values securely and unobtrusively.
5
9
 
data/Rakefile CHANGED
@@ -1,8 +1,17 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+ Bundler.setup
3
4
 
4
- RSpec::Core::RakeTask.new do |task|
5
- task.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
6
- task.pattern = 'spec/**/*_spec.rb'
5
+ require 'rake'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new('spec') do |spec|
9
+ spec.pattern = 'spec/**/*_spec.rb'
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new('spec:progress') do |spec|
13
+ spec.rspec_opts = %w(--format progress)
14
+ spec.pattern = 'spec/**/*_spec.rb'
7
15
  end
8
16
 
17
+ task :default => :spec
@@ -3,21 +3,18 @@
3
3
  module Mongoid
4
4
  module Validations # renamed to module Validatable in Mongoid 4.0
5
5
 
6
- # Monkey-patch for Mongoid's uniqueness validator to encrypt
7
- # uniqueness test values before querying the database
6
+ # Monkey-patch for Mongoid's uniqueness validator to enforce that the :case_sensitive option does not work
7
+ # for encrypted fields; they must always be case-sensitive.
8
8
  #
9
9
  # Patch is confirmed to work on Mongoid >= 3.0.0
10
10
  # Should work in Mongoid >= 4.0.0 by renaming module Validations to Validatable
11
- #
12
- # A known limitation is that the :case_sensitive option does not work
13
- # for encrypted fields; they must always be case-sensitive.
14
11
  class UniquenessValidator
15
12
 
16
13
  def setup_with_validation(klass)
17
14
  setup_without_validation(klass)
18
15
  return if case_sensitive?
19
16
  attributes.each do |attribute|
20
- field_type = @klass.fields[attribute.to_s].options[:type]
17
+ field_type = @klass.fields[@klass.database_field_name(attribute)].options[:type]
21
18
  raise ArgumentError, "Encrypted field :#{attribute} cannot support case insensitive uniqueness" if field_type.method_defined?(:encrypted)
22
19
  end
23
20
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module EncryptedFields
3
- VERSION = '1.2.1'
3
+ VERSION = '1.2.2'
4
4
  end
5
5
  end
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'mongoid-encrypted-fields/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "mongoid-encrypted-fields"
7
+ gem.name = 'mongoid-encrypted-fields'
8
8
  gem.version = Mongoid::EncryptedFields::VERSION
9
- gem.authors = ["Koan Health"]
10
- gem.email = ["development@koanhealth.com"]
11
- gem.description = "A library for storing encrypted data in Mongo"
12
- gem.summary = "Custom types for storing encrypted data"
13
- gem.homepage = "https://github.com/KoanHealth/mongoid-encrypted-fields"
9
+ gem.authors = ['Koan Health']
10
+ gem.email = ['development@koanhealth.com']
11
+ gem.description = 'A library for storing encrypted data in Mongo'
12
+ gem.summary = 'Custom types for storing encrypted data'
13
+ gem.homepage = 'https://github.com/KoanHealth/mongoid-encrypted-fields'
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
18
+ gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency "mongoid", "~> 3"
20
+ gem.add_dependency 'mongoid', '~> 3'
21
21
 
22
- gem.add_development_dependency "rake"
23
- gem.add_development_dependency "rspec"
24
- gem.add_development_dependency "gibberish", "~> 1.2.2"
25
- gem.add_development_dependency "encrypted_strings", "~> 0.3"
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'gibberish', '~> 1.2.2'
25
+ gem.add_development_dependency 'encrypted_strings', '~> 0.3'
26
+ gem.add_development_dependency 'coveralls'
26
27
  end
@@ -14,7 +14,7 @@ describe Mongoid::Validations::UniquenessValidator do
14
14
  describe "#valid?" do
15
15
 
16
16
  let(:person) do
17
- Person.new(name: "bill", ssn: "abc456789")
17
+ Person.new(name: "bill", ssn: "abc456789", credit_card: "12345678", phone_number: "12345678")
18
18
  end
19
19
 
20
20
  after do
@@ -54,8 +54,13 @@ describe Mongoid::Validations::UniquenessValidator do
54
54
 
55
55
  context "when the validation is case-sensitive" do
56
56
 
57
+ before do
58
+ Person.validates_uniqueness_of :ssn
59
+ Person.create!(ssn: "abc456789")
60
+ end
61
+
57
62
  it "behaves as case-sensitive" do
58
- expect(person).to be_valid
63
+ expect(person).not_to be_valid
59
64
  end
60
65
  end
61
66
 
@@ -95,5 +100,52 @@ describe Mongoid::Validations::UniquenessValidator do
95
100
  end
96
101
  end
97
102
  end
103
+
104
+ context "when the field name is aliased" do
105
+
106
+ context "when the aliased name is used" do
107
+
108
+ context "when the field is encrypted" do
109
+
110
+ it "throws an exception" do
111
+ expect { Person.validates_uniqueness_of :credit_card, case_sensitive: false }.to raise_error 'Encrypted field :credit_card cannot support case insensitive uniqueness'
112
+ end
113
+ end
114
+
115
+ context "when the field is not encrypted" do
116
+
117
+ before do
118
+ Person.validates_uniqueness_of :phone_number, case_sensitive: false
119
+ Person.create!(phone_number: "12345678")
120
+ end
121
+
122
+ it "correctly detects a uniqueness conflict" do
123
+ expect(person).to_not be_valid
124
+ end
125
+ end
126
+ end
127
+
128
+ context "when the underlying name is used" do
129
+
130
+ context "when the field is encrypted" do
131
+
132
+ it "throws an exception" do
133
+ expect { Person.validates_uniqueness_of :cc, case_sensitive: false }.to raise_error 'Encrypted field :cc cannot support case insensitive uniqueness'
134
+ end
135
+ end
136
+
137
+ context "when the field is not encrypted" do
138
+
139
+ before do
140
+ Person.validates :ph, uniqueness: { case_sensitive: false }
141
+ Person.create!(phone_number: "12345678")
142
+ end
143
+
144
+ it "correctly detects a uniqueness conflict" do
145
+ expect(person).to_not be_valid
146
+ end
147
+ end
148
+ end
149
+ end
98
150
  end
99
151
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,9 @@ require 'bundler/setup'
3
3
  require 'mongoid'
4
4
  require 'rspec'
5
5
 
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+
6
9
  require 'mongoid-encrypted-fields'
7
10
 
8
11
  Dir["#{File.dirname(__FILE__)}/../examples/**/*.rb"].each {|f| require f}
@@ -11,9 +14,12 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
14
  ENV['MONGOID_ENV'] ||= 'test'
12
15
  Mongoid.load!("#{File.dirname(__FILE__)}/config/mongoid.yml")
13
16
 
14
- Mongoid::EncryptedFields.logger.level = Logger::DEBUG
17
+ Mongoid::EncryptedFields.logger.level = Logger::FATAL
15
18
 
16
19
  RSpec.configure do |config|
20
+ Mongoid.logger = Mongoid::EncryptedFields.logger
21
+ Moped.logger = Mongoid::EncryptedFields.logger
22
+
17
23
  config.treat_symbols_as_metadata_keys_with_true_values = true
18
24
  config.run_all_when_everything_filtered = true
19
25
  config.filter_run :focus
@@ -5,5 +5,7 @@ class Person
5
5
  field :ssn, type: Mongoid::EncryptedString
6
6
  field :birth_date, type: Mongoid::EncryptedDate
7
7
  field :address, type: Mongoid::EncryptedHash
8
+ field :ph, as: :phone_number, type: String
9
+ field :cc, as: :credit_card, type: Mongoid::EncryptedString
8
10
 
9
11
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-encrypted-fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
5
- prerelease:
4
+ version: 1.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Koan Health
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-22 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mongoid
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: gibberish
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: encrypted_strings
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,11 +76,24 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
94
97
  description: A library for storing encrypted data in Mongo
95
98
  email:
96
99
  - development@koanhealth.com
@@ -98,11 +101,11 @@ executables: []
98
101
  extensions: []
99
102
  extra_rdoc_files: []
100
103
  files:
104
+ - .coveralls.yml
101
105
  - .gitignore
102
- - .rspec
103
106
  - .ruby-gemset
104
107
  - .ruby-version
105
- - .rvmrc
108
+ - .travis.yml
106
109
  - CHANGLOG.md
107
110
  - Gemfile
108
111
  - LICENSE.txt
@@ -135,33 +138,26 @@ files:
135
138
  - spec/support/models/person.rb
136
139
  homepage: https://github.com/KoanHealth/mongoid-encrypted-fields
137
140
  licenses: []
141
+ metadata: {}
138
142
  post_install_message:
139
143
  rdoc_options: []
140
144
  require_paths:
141
145
  - lib
142
146
  required_ruby_version: !ruby/object:Gem::Requirement
143
- none: false
144
147
  requirements:
145
148
  - - ! '>='
146
149
  - !ruby/object:Gem::Version
147
150
  version: '0'
148
- segments:
149
- - 0
150
- hash: 3728144320335115622
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
- none: false
153
152
  requirements:
154
153
  - - ! '>='
155
154
  - !ruby/object:Gem::Version
156
155
  version: '0'
157
- segments:
158
- - 0
159
- hash: 3728144320335115622
160
156
  requirements: []
161
157
  rubyforge_project:
162
- rubygems_version: 1.8.25
158
+ rubygems_version: 2.0.6
163
159
  signing_key:
164
- specification_version: 3
160
+ specification_version: 4
165
161
  summary: Custom types for storing encrypted data
166
162
  test_files:
167
163
  - spec/config/mongoid.yml
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@mongoid-encrypted-fields --create