cloak_id 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +1 -1
- data/Rakefile +0 -0
- data/cloak_id.gemspec +0 -0
- data/lib/cloak_id.rb +21 -0
- data/lib/cloak_id/cloak_id_encoder.rb +3 -1
- data/lib/cloak_id/errors.rb +0 -0
- data/lib/cloak_id/version.rb +1 -1
- data/lib/generators/cloak_id/install/install_generator.rb +0 -0
- data/lib/generators/cloak_id/install/templates/cloak_id.rb.erb +0 -0
- data/spec/cloak_id/cloak_id_encoder_spec.rb +0 -0
- data/spec/cloak_id/cloak_id_spec.rb +25 -0
- data/spec/cloak_id/install_generator_spec.rb +0 -0
- data/spec/schema.rb +0 -0
- data/spec/spec_helper.rb +0 -0
- data/spec/support/test_model.rb +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c32322be1c62ab6c319e8f2680de05a8f5a87193
|
4
|
+
data.tar.gz: 2e597ed6a16a5712487ba3b129e9ef215fbbffde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 166e418c9ee29a51f57b6fa30e368548171ee9c3619cf17b987366ddb851758c524aa2bc3bd0f06ccfacbea2e66a9af670d019f1c29934d9fcfe67f8338295b9
|
7
|
+
data.tar.gz: fad96e4260637382c71e078acebee64a05b9578071a08a811c833202fd203e6ada1a54e47a84c045582f5533c221af4c7904cfdd6f4bf615d9b6c54db800adc3
|
data/.gitignore
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ The logic behind the transformation is to use a prime number to generate a simpl
|
|
59
59
|
That newly obscured hash is then encoded as a string, to further hide its meaning. This will happen when generating forms
|
60
60
|
from ActiveRecords (when using the entire object or the to_param call), as well as when encoding the object in JSON format.
|
61
61
|
|
62
|
-
|
62
|
+
The obfuscation techinque is largely based on the one used by the Python Project "opaque_id" (https://github.com/marekweb/opaque-id) by Marek Z., and released under the MIT License.
|
63
63
|
## Customizing your cloaking
|
64
64
|
|
65
65
|
The cloak_id method call takes an option hash that controls how the cloaking occurs:
|
data/Rakefile
CHANGED
File without changes
|
data/cloak_id.gemspec
CHANGED
File without changes
|
data/lib/cloak_id.rb
CHANGED
@@ -121,6 +121,27 @@ module CloakId
|
|
121
121
|
super arg
|
122
122
|
end
|
123
123
|
end
|
124
|
+
|
125
|
+
## Extends the ability of the class to handle the exists? method when we pass in a cloaked id. This change will
|
126
|
+
## work when passed in as a single argument as well as if it is part of a hash. The method is not (currently)
|
127
|
+
## smart enough to handle array based arguments
|
128
|
+
def exists?(arg)
|
129
|
+
arg_is_cloaked_id = is_cloaked_id? arg
|
130
|
+
if arg_is_cloaked_id
|
131
|
+
decloked_id = decloak_id_for_class(arg)
|
132
|
+
super decloked_id
|
133
|
+
elsif arg.is_a? Hash
|
134
|
+
if (arg[:id].nil? == false and is_cloaked_id? arg[:id])
|
135
|
+
copied_hash = arg.clone
|
136
|
+
copied_hash[:id] = decloak_id_for_class copied_hash[:id]
|
137
|
+
super copied_hash
|
138
|
+
else
|
139
|
+
super arg # is a hash but not a cloaked it
|
140
|
+
end
|
141
|
+
else
|
142
|
+
super arg
|
143
|
+
end
|
144
|
+
end
|
124
145
|
end
|
125
146
|
end
|
126
147
|
|
@@ -7,6 +7,8 @@ module CloakId
|
|
7
7
|
|
8
8
|
cattr_accessor :cloak_id_default_key
|
9
9
|
|
10
|
+
## The twiddle and cloak methods are based on Marek Z.'s "Opaque Id" code (https://github.com/marekweb/opaque-id)
|
11
|
+
|
10
12
|
# Basic hashing function to go back and forth between a hashed value.
|
11
13
|
def self.twiddle(val,key)
|
12
14
|
hashed = (key ^ val) * TWIDDLE_PRIME
|
@@ -56,4 +58,4 @@ module CloakId
|
|
56
58
|
self.cloak(intermediate_id,key)
|
57
59
|
end
|
58
60
|
end
|
59
|
-
end
|
61
|
+
end
|
data/lib/cloak_id/errors.rb
CHANGED
File without changes
|
data/lib/cloak_id/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
@@ -89,4 +89,29 @@ describe CloakId do
|
|
89
89
|
expect(TestModel.find([model.id, model_2.id])).to eql [model,model_2]
|
90
90
|
expect(TestModel.find([model.cloaked_id, model_2.cloaked_id])).to eql [model,model_2]
|
91
91
|
end
|
92
|
+
|
93
|
+
it 'should return true for items that exist and false for those that don\'t when exists? is called' do
|
94
|
+
model = TestModel.create
|
95
|
+
|
96
|
+
expect(TestModel.exists?(model.cloaked_id)).to be_true
|
97
|
+
expect(TestModel.exists?("#{model.cloaked_id}XX")).to be_false
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should be able to handle the "exists" clause in hash queries as well as alone' do
|
101
|
+
model = TestModel.create
|
102
|
+
|
103
|
+
expect(TestModel.exists?(id:model.cloaked_id)).to be_true
|
104
|
+
expect(TestModel.exists?(id:"#{model.cloaked_id}XX")).to be_false
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should still handle cases for both hashes and "normal" exists? calls when we use the non cloaked id' do
|
108
|
+
model = TestModel.create
|
109
|
+
|
110
|
+
expect(TestModel.exists?(model.id)).to be_true
|
111
|
+
expect(TestModel.exists?(model.id+3)).to be_false
|
112
|
+
|
113
|
+
expect(TestModel.exists?(id:model.id)).to be_true
|
114
|
+
expect(TestModel.exists?(id:(model.id+3))).to be_false
|
115
|
+
|
116
|
+
end
|
92
117
|
end
|
File without changes
|
data/spec/schema.rb
CHANGED
File without changes
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
data/spec/support/test_model.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloak_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elle L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|