rails_validations_hmac 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/Gemfile +2 -0
  2. data/README.md +77 -0
  3. data/Rakefile +41 -0
  4. data/lib/rails_validations_hmac/support/active_model/validations/hmac_validator.rb +39 -0
  5. data/lib/rails_validations_hmac/support.rb +1 -0
  6. data/lib/rails_validations_hmac/version.rb +3 -0
  7. data/lib/rails_validations_hmac.rb +5 -0
  8. data/spec/dummy/README.rdoc +261 -0
  9. data/spec/dummy/Rakefile +7 -0
  10. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  11. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  12. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  13. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  14. data/spec/dummy/app/models/api_user.rb +4 -0
  15. data/spec/dummy/app/models/post.rb +8 -0
  16. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  17. data/spec/dummy/config/application.rb +59 -0
  18. data/spec/dummy/config/boot.rb +10 -0
  19. data/spec/dummy/config/database.yml +25 -0
  20. data/spec/dummy/config/environment.rb +5 -0
  21. data/spec/dummy/config/environments/development.rb +37 -0
  22. data/spec/dummy/config/environments/production.rb +67 -0
  23. data/spec/dummy/config/environments/test.rb +37 -0
  24. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  25. data/spec/dummy/config/initializers/inflections.rb +15 -0
  26. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  27. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  28. data/spec/dummy/config/initializers/session_store.rb +8 -0
  29. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  30. data/spec/dummy/config/locales/en.yml +5 -0
  31. data/spec/dummy/config/routes.rb +58 -0
  32. data/spec/dummy/config.ru +4 -0
  33. data/spec/dummy/db/development.sqlite3 +0 -0
  34. data/spec/dummy/db/migrate/20120727131814_create_table_api_users.rb +7 -0
  35. data/spec/dummy/db/migrate/20120727131826_create_table_posts.rb +10 -0
  36. data/spec/dummy/db/production.sqlite3 +0 -0
  37. data/spec/dummy/db/schema.rb +27 -0
  38. data/spec/dummy/db/test.sqlite3 +0 -0
  39. data/spec/dummy/log/development.log +36 -0
  40. data/spec/dummy/log/test.log +1119 -0
  41. data/spec/dummy/public/404.html +26 -0
  42. data/spec/dummy/public/422.html +26 -0
  43. data/spec/dummy/public/500.html +25 -0
  44. data/spec/dummy/public/favicon.ico +0 -0
  45. data/spec/dummy/script/rails +6 -0
  46. data/spec/lib/active_model/validations/hmac_validator_spec.rb +90 -0
  47. data/spec/spec_helper.rb +22 -0
  48. metadata +246 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveModel::Validations::HmacValidator do
4
+
5
+ subject { described_class.new(attributes: {}) }
6
+
7
+ before do
8
+ Object.send(:remove_const, :Post) rescue false
9
+ load 'spec/dummy/app/models/post.rb'
10
+ end
11
+
12
+ it "calls validate_each when hmac specified" do
13
+ class Post
14
+ validates :hmac, hmac: {key: :'api_user.secret', data: [:body, :title]}
15
+ end
16
+
17
+ post = Post.new(hmac: 'a', title: 'a', body: 'a')
18
+ described_class.any_instance.should_receive(:validate_each).with(post, :hmac, 'a')
19
+
20
+ post.valid?
21
+ end
22
+
23
+ describe "#value_in_context" do
24
+ context "evaluatable type" do
25
+ before do
26
+ @c = "result"
27
+ @b = mock(:b)
28
+ @a = mock(:a)
29
+ @record = Post.new
30
+ @record.should_receive(:a).and_return(@a)
31
+ @a.should_receive(:b).and_return(@b)
32
+ @b.should_receive(:c).and_return(@c)
33
+ end
34
+ it "supports Symbol value" do
35
+ r = subject.send(:value_in_context, @record, :'a').b.c
36
+ r.should eq @c
37
+ end
38
+ it "supports Symbol values (with tree support using .)" do
39
+ r = subject.send(:value_in_context, @record, :'a.b.c')
40
+ r.should eq @c
41
+ end
42
+ it "supports Proc" do
43
+ r = subject.send(:value_in_context, @record, lambda { a.b.c })
44
+ r.should eq @c
45
+ end
46
+ it "supports Arrays (evaluates its elements and concats)" do
47
+ r = subject.send(:value_in_context, @record, [lambda { a.b.c }])
48
+ r.should eq @c
49
+ end
50
+ end
51
+ context "unevaluatable type" do
52
+ it "returns other types untouched" do
53
+ r = subject.send(:value_in_context, @record, @c)
54
+ r.should eq @c
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "#validate_each" do
60
+ context "valid hmac" do
61
+ it "does not add error" do
62
+ class Post
63
+ validates :hmac, hmac: {key: :'api_user.secret', data: [:body, :title]}
64
+ end
65
+
66
+ @u = mock(:api_user)
67
+ @u.should_receive(:secret).and_return('Secret')
68
+
69
+ @p = Post.new(hmac: '30965a942b83bf362deb8b0834e28ccdf7db132a', title: 'Title', body: 'Body')
70
+ @p.should_receive(:api_user).and_return(@u)
71
+ @p.valid?.should eq true
72
+ end
73
+ end
74
+ context "invalid hmac" do
75
+ it "adds an error" do
76
+ class Post
77
+ validates :hmac, hmac: {key: :'api_user.secret', data: [:body, :title]}
78
+ end
79
+
80
+ @u = mock(:api_user)
81
+ @u.should_receive(:secret).and_return('Secret')
82
+
83
+ @p = Post.new(hmac: '30965a942b83bf362deb8b0834e28ccdf7db132', title: 'Title', body: 'Body')
84
+ @p.should_receive(:api_user).and_return(@u)
85
+ @p.valid?.should eq false
86
+ end
87
+ end
88
+ end
89
+
90
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+ require 'rails_validations_hmac'
4
+
5
+ Spork.prefork do
6
+ ENV["RAILS_ENV"] ||= 'test'
7
+ require File.expand_path("../dummy/config/environment", __FILE__)
8
+ require 'rspec/rails'
9
+ require 'rspec/autorun'
10
+
11
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
15
+ config.use_transactional_fixtures = true
16
+ config.infer_base_class_for_anonymous_controllers = false
17
+ end
18
+ end
19
+
20
+ Spork.each_run do
21
+ # This code will be run each time you run your specs.
22
+ end
metadata ADDED
@@ -0,0 +1,246 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_validations_hmac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Margus Pärt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activemodel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: capybara
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-spork
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: HMAC Validation for Rails.
127
+ email: margus@tione.eu
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - README.md
133
+ - Gemfile
134
+ - Rakefile
135
+ - lib/rails_validations_hmac/support/active_model/validations/hmac_validator.rb
136
+ - lib/rails_validations_hmac/support.rb
137
+ - lib/rails_validations_hmac/version.rb
138
+ - lib/rails_validations_hmac.rb
139
+ - spec/dummy/app/assets/javascripts/application.js
140
+ - spec/dummy/app/assets/stylesheets/application.css
141
+ - spec/dummy/app/controllers/application_controller.rb
142
+ - spec/dummy/app/helpers/application_helper.rb
143
+ - spec/dummy/app/models/api_user.rb
144
+ - spec/dummy/app/models/post.rb
145
+ - spec/dummy/app/views/layouts/application.html.erb
146
+ - spec/dummy/config/application.rb
147
+ - spec/dummy/config/boot.rb
148
+ - spec/dummy/config/database.yml
149
+ - spec/dummy/config/environment.rb
150
+ - spec/dummy/config/environments/development.rb
151
+ - spec/dummy/config/environments/production.rb
152
+ - spec/dummy/config/environments/test.rb
153
+ - spec/dummy/config/initializers/backtrace_silencers.rb
154
+ - spec/dummy/config/initializers/inflections.rb
155
+ - spec/dummy/config/initializers/mime_types.rb
156
+ - spec/dummy/config/initializers/secret_token.rb
157
+ - spec/dummy/config/initializers/session_store.rb
158
+ - spec/dummy/config/initializers/wrap_parameters.rb
159
+ - spec/dummy/config/locales/en.yml
160
+ - spec/dummy/config/routes.rb
161
+ - spec/dummy/config.ru
162
+ - spec/dummy/db/development.sqlite3
163
+ - spec/dummy/db/migrate/20120727131814_create_table_api_users.rb
164
+ - spec/dummy/db/migrate/20120727131826_create_table_posts.rb
165
+ - spec/dummy/db/production.sqlite3
166
+ - spec/dummy/db/schema.rb
167
+ - spec/dummy/db/test.sqlite3
168
+ - spec/dummy/log/development.log
169
+ - spec/dummy/log/test.log
170
+ - spec/dummy/public/404.html
171
+ - spec/dummy/public/422.html
172
+ - spec/dummy/public/500.html
173
+ - spec/dummy/public/favicon.ico
174
+ - spec/dummy/Rakefile
175
+ - spec/dummy/README.rdoc
176
+ - spec/dummy/script/rails
177
+ - spec/lib/active_model/validations/hmac_validator_spec.rb
178
+ - spec/spec_helper.rb
179
+ homepage: https://github.com/tione/rails_validations_hmac
180
+ licenses: []
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: 1.9.2
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ segments:
198
+ - 0
199
+ hash: 1337768765338415342
200
+ requirements: []
201
+ rubyforge_project:
202
+ rubygems_version: 1.8.24
203
+ signing_key:
204
+ specification_version: 3
205
+ summary: HMAC validation based on secret and content
206
+ test_files:
207
+ - spec/dummy/app/assets/javascripts/application.js
208
+ - spec/dummy/app/assets/stylesheets/application.css
209
+ - spec/dummy/app/controllers/application_controller.rb
210
+ - spec/dummy/app/helpers/application_helper.rb
211
+ - spec/dummy/app/models/api_user.rb
212
+ - spec/dummy/app/models/post.rb
213
+ - spec/dummy/app/views/layouts/application.html.erb
214
+ - spec/dummy/config/application.rb
215
+ - spec/dummy/config/boot.rb
216
+ - spec/dummy/config/database.yml
217
+ - spec/dummy/config/environment.rb
218
+ - spec/dummy/config/environments/development.rb
219
+ - spec/dummy/config/environments/production.rb
220
+ - spec/dummy/config/environments/test.rb
221
+ - spec/dummy/config/initializers/backtrace_silencers.rb
222
+ - spec/dummy/config/initializers/inflections.rb
223
+ - spec/dummy/config/initializers/mime_types.rb
224
+ - spec/dummy/config/initializers/secret_token.rb
225
+ - spec/dummy/config/initializers/session_store.rb
226
+ - spec/dummy/config/initializers/wrap_parameters.rb
227
+ - spec/dummy/config/locales/en.yml
228
+ - spec/dummy/config/routes.rb
229
+ - spec/dummy/config.ru
230
+ - spec/dummy/db/development.sqlite3
231
+ - spec/dummy/db/migrate/20120727131814_create_table_api_users.rb
232
+ - spec/dummy/db/migrate/20120727131826_create_table_posts.rb
233
+ - spec/dummy/db/production.sqlite3
234
+ - spec/dummy/db/schema.rb
235
+ - spec/dummy/db/test.sqlite3
236
+ - spec/dummy/log/development.log
237
+ - spec/dummy/log/test.log
238
+ - spec/dummy/public/404.html
239
+ - spec/dummy/public/422.html
240
+ - spec/dummy/public/500.html
241
+ - spec/dummy/public/favicon.ico
242
+ - spec/dummy/Rakefile
243
+ - spec/dummy/README.rdoc
244
+ - spec/dummy/script/rails
245
+ - spec/lib/active_model/validations/hmac_validator_spec.rb
246
+ - spec/spec_helper.rb