witness 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/witness/base.rb +52 -8
- data/spec/support/sample_verification_response.rb +2 -26
- data/spec/witness/sample_verification_response_spec.rb +11 -11
- data/witness.gemspec +2 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.0
|
data/lib/witness/base.rb
CHANGED
@@ -2,19 +2,21 @@ module Witness
|
|
2
2
|
class Base
|
3
3
|
VALID_TYPES = [:string, :integer, :symbol]
|
4
4
|
|
5
|
-
class_inheritable_accessor :actions, :
|
5
|
+
class_inheritable_accessor :actions, :columns, :validates_presence, :validates_signature
|
6
6
|
|
7
|
-
self.actions
|
8
|
-
self.columns
|
9
|
-
self.
|
7
|
+
self.actions ||= []
|
8
|
+
self.columns ||= {}
|
9
|
+
self.validates_presence ||= {}
|
10
|
+
self.validates_signature ||= {}
|
10
11
|
|
11
12
|
def self.action(*action_names)
|
12
13
|
[*action_names].each do |action_name|
|
13
14
|
self.actions << action_name.to_sym
|
14
15
|
|
15
16
|
class_eval <<-end_eval
|
16
|
-
def self.#{action_name.to_sym}(provided_params)
|
17
|
+
def self.#{action_name.to_sym}(provided_params, key = nil)
|
17
18
|
command = "#{action_name}".to_sym
|
19
|
+
provided_params.merge!(:key => key) if key.present?
|
18
20
|
construct(provided_params.update(:command => command))
|
19
21
|
end
|
20
22
|
end_eval
|
@@ -35,14 +37,30 @@ module Witness
|
|
35
37
|
configuration.update(attr_names.extract_options!)
|
36
38
|
|
37
39
|
[*configuration[:on]].each do |on|
|
38
|
-
self.
|
40
|
+
self.validates_presence[on] ||= []
|
39
41
|
|
40
42
|
[*attr_names].each do |attr_name|
|
41
|
-
self.
|
43
|
+
self.validates_presence[on] << attr_name
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
48
|
+
def self.validates_signature_of(*attr_names)
|
49
|
+
configuration = { :on => self.actions }
|
50
|
+
configuration.update(attr_names.extract_options!)
|
51
|
+
|
52
|
+
[*configuration[:on]].each do |on|
|
53
|
+
self.validates_signature[on] ||= []
|
54
|
+
|
55
|
+
[*attr_names].each do |attr_name|
|
56
|
+
self.validates_signature[on] << attr_name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
column :signature
|
61
|
+
column :key
|
62
|
+
end
|
63
|
+
|
46
64
|
protected :initialize
|
47
65
|
|
48
66
|
private
|
@@ -54,7 +72,7 @@ module Witness
|
|
54
72
|
|
55
73
|
self.columns.each do |column, configuration|
|
56
74
|
if provided_params[column] == nil || provided_params[column] == ""
|
57
|
-
if self.
|
75
|
+
if self.validates_presence[command] && self.validates_presence[command].include?(column)
|
58
76
|
raise Witness::Error, "#{configuration[:name]} not set"
|
59
77
|
end
|
60
78
|
else
|
@@ -82,6 +100,32 @@ module Witness
|
|
82
100
|
end
|
83
101
|
end
|
84
102
|
|
103
|
+
if self.validates_signature[command]
|
104
|
+
|
105
|
+
if provided_params[:key].blank?
|
106
|
+
raise Witness::Error, "Key not set"
|
107
|
+
end
|
108
|
+
|
109
|
+
if provided_params[:signature].blank?
|
110
|
+
raise Witness::Error, "Signature not set"
|
111
|
+
end
|
112
|
+
|
113
|
+
secure_params = {}
|
114
|
+
|
115
|
+
self.validates_signature[command].each do |key|
|
116
|
+
secure_params[key] = provided_params[key]
|
117
|
+
end
|
118
|
+
|
119
|
+
sigil = Sigil::Base.new(secure_params, provided_params[:key])
|
120
|
+
|
121
|
+
verified = sigil.verify(provided_params[:signature])
|
122
|
+
|
123
|
+
if !verified
|
124
|
+
raise Witness::Error, "Signature does not match"
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
85
129
|
result
|
86
130
|
end
|
87
131
|
|
@@ -8,12 +8,11 @@ class SampleVerificationResponse < Witness::Base
|
|
8
8
|
column :receive_contact_url, :name => "Receive Contact URL"
|
9
9
|
column :contact_id, :type => :integer, :name => "Contact ID"
|
10
10
|
column :authorized, :type => :boolean, :name => "Authorization"
|
11
|
-
column :key
|
12
11
|
|
13
|
-
validates_presence_of :slice_slug, :request_url, :contact_id
|
12
|
+
validates_presence_of :slice_slug, :request_url, :contact_id
|
14
13
|
validates_presence_of :receive_contact_url, :on => :generate
|
15
14
|
|
16
|
-
|
15
|
+
validates_signature_of :slice_slug, :contact_id, :secure_area_id, :authorized, :request_url, :on => :receive
|
17
16
|
|
18
17
|
def url
|
19
18
|
Witness.update_url(receive_contact_url, params)
|
@@ -36,27 +35,4 @@ class SampleVerificationResponse < Witness::Base
|
|
36
35
|
_params.update(:signature => sigil.signature).reject { |k, v| v.nil? }
|
37
36
|
end
|
38
37
|
|
39
|
-
def self.construct(provided_params)
|
40
|
-
response = super(provided_params)
|
41
|
-
|
42
|
-
command = provided_params[:command]
|
43
|
-
|
44
|
-
if command == :receive
|
45
|
-
if provided_params[:signature].blank?
|
46
|
-
raise Witness::Error, "Signature not set"
|
47
|
-
end
|
48
|
-
|
49
|
-
sigil = Sigil::Base.new(response.secure_params, response.key)
|
50
|
-
|
51
|
-
verified = sigil.verify(provided_params[:signature])
|
52
|
-
|
53
|
-
if !verified
|
54
|
-
raise Witness::Error, "Signature does not match"
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
response
|
60
|
-
end
|
61
|
-
|
62
38
|
end
|
@@ -53,11 +53,6 @@ describe SampleVerificationResponse do
|
|
53
53
|
lambda { SampleVerificationResponse.generate(@valid_generate_params) }.should raise_error(Witness::Error, /Contact ID not set/)
|
54
54
|
end
|
55
55
|
|
56
|
-
it "should raise an error if Key is not set" do
|
57
|
-
@valid_generate_params.delete(:key)
|
58
|
-
lambda { SampleVerificationResponse.generate(@valid_generate_params) }.should raise_error(Witness::Error, /Key not set/)
|
59
|
-
end
|
60
|
-
|
61
56
|
it "should recognise true authorizations" do
|
62
57
|
@valid_generate_params[:authorized] = true
|
63
58
|
response = SampleVerificationResponse.generate(@valid_generate_params)
|
@@ -124,13 +119,14 @@ describe SampleVerificationResponse do
|
|
124
119
|
describe "receive" do
|
125
120
|
|
126
121
|
before do
|
122
|
+
@key = "deadbeef"
|
123
|
+
|
127
124
|
@valid_generate_params = {
|
128
125
|
:slice_slug => "banana",
|
129
126
|
:secure_area_id => 42,
|
130
127
|
:request_url => "http://www.example.com/secure",
|
131
128
|
:contact_id => 1234,
|
132
129
|
:authorized => true,
|
133
|
-
:key => "deadbeef",
|
134
130
|
:signature => "ffb581dbdf4d72f2c3c4d61af2fbaaa6fbcf66af",
|
135
131
|
}
|
136
132
|
end
|
@@ -138,27 +134,31 @@ describe SampleVerificationResponse do
|
|
138
134
|
describe "initialization" do
|
139
135
|
|
140
136
|
it "should generate" do
|
141
|
-
SampleVerificationResponse.receive(@valid_generate_params)
|
137
|
+
SampleVerificationResponse.receive(@valid_generate_params, @key)
|
142
138
|
end
|
143
139
|
|
144
140
|
it "should raise an error if Slice slug is not set" do
|
145
141
|
@valid_generate_params.delete(:slice_slug)
|
146
|
-
lambda { SampleVerificationResponse.receive(@valid_generate_params) }.should raise_error(Witness::Error, /Slice not set/)
|
142
|
+
lambda { SampleVerificationResponse.receive(@valid_generate_params, @key) }.should raise_error(Witness::Error, /Slice not set/)
|
147
143
|
end
|
148
144
|
|
149
145
|
it "should raise an error if Request URL is not set" do
|
150
146
|
@valid_generate_params.delete(:request_url)
|
151
|
-
lambda { SampleVerificationResponse.receive(@valid_generate_params) }.should raise_error(Witness::Error, /Request URL not set/)
|
147
|
+
lambda { SampleVerificationResponse.receive(@valid_generate_params, @key) }.should raise_error(Witness::Error, /Request URL not set/)
|
152
148
|
end
|
153
149
|
|
154
150
|
it "should raise an error if Signature is not set" do
|
155
151
|
@valid_generate_params.delete(:signature)
|
156
|
-
lambda { SampleVerificationResponse.receive(@valid_generate_params) }.should raise_error(Witness::Error, /Signature not set/)
|
152
|
+
lambda { SampleVerificationResponse.receive(@valid_generate_params, @key) }.should raise_error(Witness::Error, /Signature not set/)
|
157
153
|
end
|
158
154
|
|
159
155
|
it "should raise an error if Signature does not match" do
|
160
156
|
@valid_generate_params[:signature] = "incorrect"
|
161
|
-
lambda { SampleVerificationResponse.receive(@valid_generate_params) }.should raise_error(Witness::Error, /Signature does not match/)
|
157
|
+
lambda { SampleVerificationResponse.receive(@valid_generate_params, @key) }.should raise_error(Witness::Error, /Signature does not match/)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should raise an error if Key is not set" do
|
161
|
+
lambda { SampleVerificationResponse.receive(@valid_generate_params, "" ) }.should raise_error(Witness::Error, /Key not set/)
|
162
162
|
end
|
163
163
|
|
164
164
|
end
|
data/witness.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{witness}
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steve Hoeksema"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-13}
|
13
13
|
s.description = %q{Witness}
|
14
14
|
s.email = %q{steve@seven.net.nz}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 2.0.0
|
9
|
+
version: 2.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Steve Hoeksema
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-13 00:00:00 +13:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -174,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
174
|
requirements:
|
175
175
|
- - ">="
|
176
176
|
- !ruby/object:Gem::Version
|
177
|
-
hash:
|
177
|
+
hash: -3102975516984677801
|
178
178
|
segments:
|
179
179
|
- 0
|
180
180
|
version: "0"
|