rails_validations_hmac 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -7,15 +7,24 @@ module ActiveModel
|
|
7
7
|
DEFAULT_ALGORITHM = :sha1
|
8
8
|
|
9
9
|
def validate_each(record, attribute, hmac)
|
10
|
-
|
11
|
-
|
12
|
-
algorithm = value_in_context(record, options[:algorithm]) || DEFAULT_ALGORITHM
|
13
|
-
message = options[:message] or 'HMAC is invalid'
|
10
|
+
raise ArgumentError, "Definition :key is missing" unless options.has_key?(:key)
|
11
|
+
raise ArgumentError, "Definition :data is missing" unless options.has_key?(:data)
|
14
12
|
|
15
|
-
|
13
|
+
key = value_in_context(record, options[:key])
|
14
|
+
data = value_in_context(record, options[:data])
|
15
|
+
algorithm = value_in_context(record, options[:algorithm]) || DEFAULT_ALGORITHM
|
16
|
+
message = options[:message] or 'HMAC is not matching'
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
if key and data and algorithm
|
19
|
+
real_hmac = OpenSSL::HMAC.hexdigest("#{algorithm}", key, data)
|
20
|
+
valid = real_hmac == hmac
|
21
|
+
record.errors.add(attribute, message) unless valid
|
22
|
+
else
|
23
|
+
record.errors.add(:hmac, 'Comparing key not found') unless key
|
24
|
+
record.errors.add(:hmac, 'Comparing data not found') unless data
|
25
|
+
record.errors.add(:hmac, 'Comparing algorithm not found') unless algorithm
|
26
|
+
valid = false
|
27
|
+
end
|
19
28
|
end
|
20
29
|
|
21
30
|
private
|
@@ -23,9 +32,9 @@ module ActiveModel
|
|
23
32
|
def value_in_context(record, evaluation)
|
24
33
|
case evaluation
|
25
34
|
when Symbol
|
26
|
-
"#{evaluation}".split('.').inject(record) {|object, method| object.send(method) }
|
35
|
+
"#{evaluation}".split('.').inject(record) {|object, method| object.send(method) } rescue nil
|
27
36
|
when Proc
|
28
|
-
record.instance_exec(&evaluation)
|
37
|
+
record.instance_exec(&evaluation) rescue nil
|
29
38
|
when Array
|
30
39
|
evaluation.collect {|e| value_in_context(record, e) }.join
|
31
40
|
else
|
data/spec/dummy/log/test.log
CHANGED
@@ -1134,3 +1134,54 @@ Connecting to database specified by database.yml
|
|
1134
1134
|
[1m[35m (0.1ms)[0m rollback transaction
|
1135
1135
|
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1136
1136
|
[1m[35m (0.1ms)[0m rollback transaction
|
1137
|
+
Connecting to database specified by database.yml
|
1138
|
+
[1m[36m (8.3ms)[0m [1mbegin transaction[0m
|
1139
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1140
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1141
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1142
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1143
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1144
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1145
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1146
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1147
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1148
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1149
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1150
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1151
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1152
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1153
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1154
|
+
Connecting to database specified by database.yml
|
1155
|
+
[1m[36m (0.8ms)[0m [1mbegin transaction[0m
|
1156
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1157
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1158
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1159
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1160
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1161
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1162
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1163
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1164
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1165
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1166
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1167
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1168
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1169
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1170
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1171
|
+
Connecting to database specified by database.yml
|
1172
|
+
[1m[36m (0.8ms)[0m [1mbegin transaction[0m
|
1173
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1174
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1175
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1176
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1177
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1178
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1179
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1180
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1181
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1182
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1183
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1184
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1185
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1186
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
1187
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_validations_hmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
212
|
version: '0'
|
213
213
|
segments:
|
214
214
|
- 0
|
215
|
-
hash:
|
215
|
+
hash: -877944555676697387
|
216
216
|
requirements: []
|
217
217
|
rubyforge_project:
|
218
218
|
rubygems_version: 1.8.24
|