vidibus-secure 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Vidibus::Secure [![](http://travis-ci.org/vidibus/vidibus-secure.png)](http://travis-ci.org/vidibus/vidibus-secure) [![](http://stillmaintained.com/vidibus/vidibus-secure.png)](http://stillmaintained.com/vidibus/vidibus-secure)
2
+
3
+ Allows encryption and signing of requests and storing encrypted data within Mongoid documents.
4
+
5
+ This gem is part of [Vidibus](http://vidibus.org), an open source toolset for building distributed (video) applications.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add `gem "vidibus-secure"` to your Gemfile. Then call `bundle install` on your console.
11
+
12
+ If you want to use Vidibus::Secure::Mongoid on your models, you should generate an initializer to set an unique encryption key by calling `rails generate vidibus_secure_key`, also on your console.
13
+
14
+
15
+ ## Usage
16
+
17
+ TODO
18
+
19
+
20
+ ## TODO
21
+
22
+ * Documentation
23
+
24
+
25
+ ## Copyright
26
+
27
+ © 2010-2011 Andre Pankratz. See LICENSE for details.
@@ -145,7 +145,7 @@ module Vidibus
145
145
  def params_identifier(params, level = 1)
146
146
  array = []
147
147
  for key, value in params
148
- if [Array, Hash].include?(value.class)
148
+ if value.is_a?(Array) or value.is_a?(Hash)
149
149
  value = params_identifier(value, level + 1)
150
150
  end
151
151
  array << "#{level}:#{key}:#{value}"
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Secure
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-secure
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-09 00:00:00 +02:00
18
+ date: 2011-07-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -199,26 +199,16 @@ extensions: []
199
199
  extra_rdoc_files: []
200
200
 
201
201
  files:
202
- - .bundle/config
203
- - .gitignore
204
- - .rspec
205
- - .travis.yml
206
- - Gemfile
207
- - LICENSE
208
- - README.rdoc
209
- - Rakefile
210
202
  - lib/generators/vidibus_secure_key/vidibus_secure_key_generator.rb
211
- - lib/vidibus-secure.rb
212
- - lib/vidibus/secure.rb
213
- - lib/vidibus/secure/extensions.rb
214
203
  - lib/vidibus/secure/extensions/controller.rb
204
+ - lib/vidibus/secure/extensions.rb
215
205
  - lib/vidibus/secure/mongoid.rb
216
206
  - lib/vidibus/secure/version.rb
217
- - spec/spec_helper.rb
218
- - spec/vidibus/secure/extensions/controller_spec.rb
219
- - spec/vidibus/secure/mongoid_spec.rb
220
- - spec/vidibus/secure_spec.rb
221
- - vidibus-secure.gemspec
207
+ - lib/vidibus/secure.rb
208
+ - lib/vidibus-secure.rb
209
+ - LICENSE
210
+ - README.md
211
+ - Rakefile
222
212
  has_rdoc: true
223
213
  homepage: https://github.com/vidibus/vidibus-secure
224
214
  licenses: []
data/.bundle/config DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_DISABLE_SHARED_GEMS: "1"
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- pkg/*
2
- Gemfile.lock
3
- *.gem
4
- .bundle
5
- rdoc
6
- coverage
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --colour
2
- --format nested
data/.travis.yml DELETED
@@ -1 +0,0 @@
1
- script: "bundle exec rspec spec --format progress"
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source :gemcutter
2
-
3
- # Specify your gem's dependencies in vidibus-resource.gemspec
4
- gemspec
data/README.rdoc DELETED
@@ -1,45 +0,0 @@
1
- = Vidibus::Secure
2
-
3
- Allows encryption and signing of requests and storing encrypted data within Mongoid documents.
4
-
5
- This gem is part of {Vidibus}[http://vidibus.org], an open source toolset for building distributed (video) applications.
6
-
7
-
8
- == Compatibility
9
-
10
- Vidibus::Secure is tested against Ruby 1.8.7.
11
-
12
- http://travis-ci.org/vidibus/vidibus-secure.png {Build History}[http://travis-ci.org/vidibus/vidibus-secure]
13
-
14
-
15
- == Installation
16
-
17
- Add the dependency to the Gemfile of your application:
18
-
19
- gem "vidibus-secure"
20
-
21
- Then call `bundle install` on your console.
22
-
23
- If you want to use Vidibus::Secure::Mongoid on your models, you should generate an initializer to set an unique encryption key:
24
-
25
- rails generate vidibus_secure_key
26
-
27
-
28
- == Usage
29
-
30
- TODO: Describe
31
-
32
-
33
- === Usage in Mongoid model
34
-
35
- TODO: Describe
36
-
37
-
38
- == TODO
39
-
40
- * Documentation
41
-
42
-
43
- == Copyright
44
-
45
- Copyright (c) 2010-2011 Andre Pankratz. See LICENSE for details.
data/spec/spec_helper.rb DELETED
@@ -1,21 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- require "rubygems"
5
- require "mongoid"
6
- require "rspec"
7
- require "rr"
8
- require "vidibus-secure"
9
-
10
- Mongoid.configure do |config|
11
- name = "vidibus-secure_test"
12
- host = "localhost"
13
- config.master = Mongo::Connection.new.db(name)
14
- end
15
-
16
- RSpec.configure do |config|
17
- config.mock_with :rr
18
- config.after :suite do
19
- Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
20
- end
21
- end
@@ -1,65 +0,0 @@
1
- require "ostruct"
2
- require "spec_helper"
3
- require "action_controller"
4
-
5
- class Controller < ActionController::Base; end
6
-
7
- describe "Vidibus::Secure::Extensions::Controller" do
8
- let(:controller) { Controller.new }
9
- let(:secret) { "mysecret" }
10
-
11
- before do
12
- stub(controller).request do
13
- @request ||= begin
14
- Struct.new("Request", :protocol, :host_with_port, :fullpath, :method, :request_parameters) unless defined?(Struct::Request)
15
- Struct::Request.new("http://", "vidibus.org", "/", "get", {})
16
- end
17
- end
18
- end
19
-
20
- describe "#valid_request?" do
21
- it "should be available to controllers that stem from ActionController::Base" do
22
- controller.should respond_to(:valid_request?)
23
- end
24
-
25
- it "should build URI from request object if no :uri is provided" do
26
- mock(controller.request).protocol {"http://"}
27
- mock(controller.request).host_with_port {"vidibus.org"}
28
- mock(controller.request).fullpath {"/"}
29
- controller.valid_request?(secret, :method => "get", :params => {})
30
- end
31
-
32
- it "should use request.method if no :method is provided" do
33
- mock(controller.request).method {"get"}
34
- controller.valid_request?(secret, :uri => "something", :params => {})
35
- end
36
-
37
- it "should use request_parameters unless params are provided" do
38
- mock(controller.request).request_parameters
39
- controller.valid_request?(secret, :uri => "something/?with=params", :method => "get")
40
- end
41
-
42
- it "should use given params" do
43
- dont_allow(controller).request
44
- controller.valid_request?(secret, :method => "get", :uri => "something", :params => {})
45
- end
46
-
47
- it "should return true for valid requests" do
48
- params = {}
49
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/", params, secret)
50
- controller.request.fullpath = "?sign=#{params[:sign]}"
51
- controller.valid_request?(secret).should be_true
52
- end
53
-
54
- it "should use given custom params" do
55
- params = { :action => "index", :controller => "application", :id => "12" }
56
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/", params, secret)
57
- controller.valid_request?(secret, :params => params).should be_true
58
- end
59
-
60
- it "should call Vidibus::Secure.verify_request" do
61
- mock(Vidibus::Secure).verify_request("get", "http://vidibus.org/", {}, secret)
62
- controller.valid_request?(secret)
63
- end
64
- end
65
- end
@@ -1,89 +0,0 @@
1
- require "spec_helper"
2
-
3
- ENV["VIDIBUS_SECURE_KEY"] = "c4l60HC/lyerr2VEnrP7s2YAldyZGfIBePUzCl+tBsTs1EWJOc8dEJ7F2Vty7KPEeRuBWGxZHVAbku8pLo+UvXRpLcRiF7lxKiKl"
4
-
5
- class Model
6
- include Mongoid::Document
7
- include Vidibus::Secure::Mongoid
8
- attr_encrypted :my_secret, :another_secret
9
- end
10
-
11
- describe "Vidibus::Secure::Mongoid" do
12
- let(:model) { Model.new }
13
- let(:secret) { "My name is Bond." }
14
- let(:encrypted_secret) { "+PlBG1ChiqUAYMrHlJzDL4NwXHtGBIUm/KQ2ZWfwxjM=\n" }
15
-
16
- it "should add a field :my_secret_encrypted" do
17
- model.should respond_to(:my_secret_encrypted)
18
- end
19
-
20
- it "should add a setter for :my_secret" do
21
- model.should respond_to(:my_secret=)
22
- end
23
-
24
- it "should add a getter for :my_secret" do
25
- model.should respond_to(:my_secret)
26
- end
27
-
28
- it "should add a field :another_secret_encrypted" do
29
- model.should respond_to(:another_secret_encrypted)
30
- end
31
-
32
- it "should add a setter for :another_secret" do
33
- model.should respond_to(:another_secret=)
34
- end
35
-
36
- it "should add a getter for :another_secret" do
37
- model.should respond_to(:another_secret)
38
- end
39
-
40
- describe "#my_secret=" do
41
- it "should set :my_secret_encrypted" do
42
- model.my_secret_encrypted.should be_nil
43
- model.my_secret = "my_secret"
44
- model.my_secret_encrypted.should_not be_nil
45
- end
46
-
47
- it "should encrypt a given value" do
48
- model.my_secret = secret
49
- model.my_secret_encrypted.should eql(encrypted_secret)
50
- end
51
-
52
- it "should be persistent" do
53
- model.my_secret = secret
54
- model.save!
55
- model.reload
56
- model.my_secret_encrypted.should eql(encrypted_secret)
57
- end
58
-
59
- it "should not encrypt nil" do
60
- model.my_secret = nil
61
- model.my_secret_encrypted.should eql(nil)
62
- end
63
- end
64
-
65
- describe "#my_secret" do
66
- it "should get :my_secret_encrypted" do
67
- model.my_secret.should be_nil
68
- model.my_secret_encrypted = encrypted_secret
69
- model.my_secret.should_not be_nil
70
- end
71
-
72
- it "should decrypt value of :my_secret_encrypted" do
73
- model.my_secret_encrypted = encrypted_secret
74
- model.my_secret.should eql(secret)
75
- end
76
-
77
- it "should be persistent" do
78
- model.my_secret_encrypted = encrypted_secret
79
- model.save!
80
- model.reload
81
- model.my_secret.should eql(secret)
82
- end
83
-
84
- it "should not decrypt nil" do
85
- model.my_secret_encrypted = nil
86
- model.my_secret.should eql(nil)
87
- end
88
- end
89
- end
@@ -1,368 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Secure" do
4
- let(:key) { "8KTbTanrBTQ5c8CjANpJQjPWcIstFxq/uFIUQBF3gRnztM565xIfe8MStVcLilbEhjYwfZiD4lFWINF22Aw8gVEbkSf2rLN0fnuO9YtNqFLQU6m/OldO5JbsBJPCwuzsPYmZ1w==" }
5
- let(:data) { "My name is Bond. You know the rest." }
6
- let(:data_hash) {{"name" => "James Bond"}}
7
- let(:data_array) {["Bond", "James"]}
8
- let(:encrypted_base64) { "hXUWa3gHRpYr/Fi2qm9xdTyZg7NSpYq8X2p1EL+/wffUg9IeIjVbSvyUYAvy\nTLbc\n" }
9
- let(:encrypted_base64_array) { "pG9SNq9r2fQVxCiN8jYNciukklnZ+5YagtCE0LAj2bg=\n" }
10
- let(:encrypted_base64_hash) { "kjV3/v52KcsGKoNs7zgcmHih90uvc+hP5X90s6X27GE=\n" }
11
- let(:encrypted_hex) { "8575166b780746962bfc58b6aa6f71753c9983b352a58abc5f6a7510bfbfc1f7d483d21e22355b4afc94600bf24cb6dc" }
12
- let(:encrypted_hex_array) { "8575166b780746962bfc58b6aa6f71753c9983b352a58abc5f6a7510bfbfc1f7d483d21e22355b4afc94600bf24cb6dc" }
13
- let(:encrypted_hex_hash) { "8575166b780746962bfc58b6aa6f71753c9983b352a58abc5f6a7510bfbfc1f7d483d21e22355b4afc94600bf24cb6dc" }
14
- let(:signature_base64) { "AhTlmymUI9q2bdrtJ0vLdyV8Y8eUf2U5xrzoK5PdWKQ=\n" }
15
- let(:signature_hex) { "0214e59b299423dab66ddaed274bcb77257c63c7947f6539c6bce82b93dd58a4" }
16
- let(:base64_format) { /([A-Z]|\+|\/)/ }
17
- let(:hex_format) { /^[0-9a-f]+$/ }
18
-
19
- describe ".settings" do
20
- context "for :random" do
21
- it "should default to a length of 50" do
22
- Vidibus::Secure.settings[:random][:length].should eql(50)
23
- end
24
-
25
- it "should default to base64 encoding" do
26
- Vidibus::Secure.settings[:random][:encoding].should eql(:base64)
27
- end
28
- end
29
-
30
- context "for :sign" do
31
- it "should default to SHA256 algorithm" do
32
- Vidibus::Secure.settings[:sign][:algorithm].should eql("SHA256")
33
- end
34
-
35
- it "should default to hex encoding" do
36
- Vidibus::Secure.settings[:sign][:encoding].should eql(:hex)
37
- end
38
- end
39
-
40
- context "for :crypt" do
41
- it "should default to AES-256-CBC algorithm" do
42
- Vidibus::Secure.settings[:crypt][:algorithm].should eql("AES-256-CBC")
43
- end
44
-
45
- it "should default to base64 encoding" do
46
- Vidibus::Secure.settings[:crypt][:encoding].should eql(:base64)
47
- end
48
- end
49
- end
50
-
51
- describe ".random" do
52
- it "should create a base64 random string with a length of 50 chars" do
53
- random = Vidibus::Secure.random
54
- random.length.should eql(50)
55
- random.should match(base64_format)
56
- end
57
-
58
- it "should create a hexadecimal random string with a length of 50 chars if :encoding is provided" do
59
- random = Vidibus::Secure.random(:encoding => :hex)
60
- random.length.should eql(50)
61
- random.should match(hex_format)
62
- end
63
-
64
- it "should create a random string with a length of 60 chars if :length is provided" do
65
- Vidibus::Secure.random(:length => 60).length.should eql(60)
66
- end
67
-
68
- it "should create a hexadecimal random string if settings for :random are changed" do
69
- Vidibus::Secure.settings[:random][:encoding] = :hex
70
- Vidibus::Secure.random.should match(hex_format)
71
- Vidibus::Secure.settings[:random][:encoding] = :base64
72
- end
73
- end
74
-
75
- describe ".sign" do
76
- it "should create a hexadecimal signature of given data by default" do
77
- Vidibus::Secure.sign(data, key).should eql(signature_hex)
78
- end
79
-
80
- it "should create a base64 signature of given data if :encoding is provided" do
81
- Vidibus::Secure.sign(data, key, :encoding => :base64).should eql(signature_base64)
82
- end
83
-
84
- it "should create a base64 signature of given data if settings for :sign are changed" do
85
- Vidibus::Secure.settings[:sign][:encoding] = :base64
86
- Vidibus::Secure.sign(data, key).should eql(signature_base64)
87
- Vidibus::Secure.settings[:sign][:encoding] = :hex
88
- end
89
-
90
- it "should raise a KeyError if given secret key is nil" do
91
- expect {Vidibus::Secure.sign(data, nil)}.to raise_error(Vidibus::Secure::KeyError)
92
- end
93
- end
94
-
95
- describe ".encrypt" do
96
- it "should encrypt data as base64 string" do
97
- Vidibus::Secure.encrypt(data, key).should eql(encrypted_base64)
98
- end
99
-
100
- it "should encrypt data as hexadecimal string if :encoding is provided" do
101
- Vidibus::Secure.encrypt(data, key, :encoding => :hex).should eql(encrypted_hex)
102
- end
103
-
104
- it "should encrypt data as hexadecimal string if encoding settings for :crypt are set to hex" do
105
- Vidibus::Secure.settings[:crypt][:encoding] = :hex
106
- Vidibus::Secure.encrypt(data, key).should eql(encrypted_hex)
107
- Vidibus::Secure.settings[:crypt][:encoding] = :base64
108
- end
109
-
110
- it "should raise an error if given secret key is nil" do
111
- expect {Vidibus::Secure.sign(data, nil)}.to raise_error(Vidibus::Secure::KeyError)
112
- end
113
-
114
- it "should encrypt array data" do
115
- Vidibus::Secure.encrypt(data_array, key).should eql(encrypted_base64_array)
116
- end
117
-
118
- it "should encrypt hash data" do
119
- Vidibus::Secure.encrypt(data_hash, key).should eql(encrypted_base64_hash)
120
- end
121
- end
122
-
123
- describe ".decrypt" do
124
- it "should decrypt a base64 string" do
125
- Vidibus::Secure.decrypt(encrypted_base64, key).should eql(data)
126
- end
127
-
128
- it "should decrypt array data from base64 string" do
129
- Vidibus::Secure.decrypt(encrypted_base64_array, key).should eql(data_array)
130
- end
131
-
132
- it "should decrypt hash data from base64 string" do
133
- Vidibus::Secure.decrypt(encrypted_base64_hash, key).should eql(data_hash)
134
- end
135
-
136
- it "should decrypt a hexadecimal string if :encoding is provided" do
137
- Vidibus::Secure.decrypt(encrypted_hex, key, :encoding => :hex).should eql(data)
138
- end
139
-
140
- it "should decrypt a hexadecimal string if encoding settings for :crypt are set to hex" do
141
- Vidibus::Secure.settings[:crypt][:encoding] = :hex
142
- Vidibus::Secure.decrypt(encrypted_hex, key).should eql(data)
143
- Vidibus::Secure.settings[:crypt][:encoding] = :base64
144
- end
145
-
146
- it "should raise a KeyError if given secret key is nil" do
147
- expect {Vidibus::Secure.sign(data, nil)}.to raise_error(Vidibus::Secure::KeyError)
148
- end
149
- end
150
-
151
- describe ".sign_request" do
152
- it "should not modifiy path for POST and PUT requests" do
153
- for verb in %w[post put]
154
- path, params = Vidibus::Secure.sign_request(verb, "/whazzup", {}, key)
155
- path.should eql("/whazzup")
156
- end
157
- end
158
-
159
- it "should raise an InputError if given params is not a Hash" do
160
- params = %w[1 2 3]
161
- expect {Vidibus::Secure.sign_request(:post, "/", params, key)}.to raise_error(Vidibus::Secure::InputError, "Given params is not a Hash.")
162
- end
163
-
164
- context "for requests without body" do
165
- it "should add signature to params, if no params are given in URI and params argument is a hash" do
166
- path = "http://vidibus.org/status"
167
- params = {}
168
- Vidibus::Secure.sign_request(:get, path, params, key)
169
- path.should eql("http://vidibus.org/status")
170
- params.should eql(:sign => "09247a2534f14e57081193ef6834b08843352c796af264f77e76445472dae9ed")
171
- end
172
-
173
- it "should add signature to URI, if no params are given in URI and params argument nil" do
174
- path = "http://vidibus.org/status"
175
- params = nil
176
- Vidibus::Secure.sign_request(:get, path, params, key)
177
- path.should eql("http://vidibus.org/status?sign=09247a2534f14e57081193ef6834b08843352c796af264f77e76445472dae9ed")
178
- params.should be_nil
179
- end
180
-
181
- it "should add signature to URI, if params argument is a hash, but params are also given in URI" do
182
- path = "http://vidibus.org/status?feel=good"
183
- params = {}
184
- Vidibus::Secure.sign_request(:get, path, params, key)
185
- path.should eql("http://vidibus.org/status?feel=good&sign=2be2169f27f11ccc519456887838dcbfef54eb461492d60b847d2f01adca9326")
186
- params.should eql({})
187
- end
188
-
189
- it "should accept a custom name as signature param" do
190
- path = "http://vidibus.org/status"
191
- Vidibus::Secure.sign_request(:get, path, nil, key, "privado")
192
- path.should eql("http://vidibus.org/status?privado=09247a2534f14e57081193ef6834b08843352c796af264f77e76445472dae9ed")
193
- end
194
-
195
- it "should create a signature of a given URL" do
196
- path = "http://vidibus.org/"
197
- Vidibus::Secure.sign_request(:get, path, nil, key)
198
- path.should eql("http://vidibus.org/?sign=0ff9ec7056fd6a2b8ea1d2a1f462458719e3cf0b65485c55035ac906fd3d3368")
199
- end
200
-
201
- it "should create identical signatures for URLs with and without trailing slash" do
202
- signature = "0ff9ec7056fd6a2b8ea1d2a1f462458719e3cf0b65485c55035ac906fd3d3368"
203
- Vidibus::Secure.sign_request(:get, "http://vidibus.org", nil, key).first.should match(signature)
204
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/", nil, key).first.should match(signature)
205
- end
206
-
207
- it "should create a signature of a given URI" do
208
- path = "http://vidibus.org/status"
209
- Vidibus::Secure.sign_request(:get, path, nil, key)
210
- path.should eql("http://vidibus.org/status?sign=09247a2534f14e57081193ef6834b08843352c796af264f77e76445472dae9ed")
211
- end
212
-
213
- it "should create identical signatures for URIs with and without trailing slash" do
214
- signature = "09247a2534f14e57081193ef6834b08843352c796af264f77e76445472dae9ed"
215
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/status", nil, key).first.should match(signature)
216
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/status/", nil, key).first.should match(signature)
217
- end
218
-
219
- it "should create a signature of URI with params" do
220
- path = "http://vidibus.org/status?type=server"
221
- Vidibus::Secure.sign_request(:get, path, {}, key)
222
- path.should eql("http://vidibus.org/status?type=server&sign=ff98a086cca8af703537afe873009f16ea5554826fa5d2665c212a13e44f7da0")
223
- end
224
-
225
- it "should create identical signatures for URIs with params with and without trailing slash" do
226
- signature = "ff98a086cca8af703537afe873009f16ea5554826fa5d2665c212a13e44f7da0"
227
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/status?type=server", {}, key).first.should match(signature)
228
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/status/?type=server", {}, key).first.should match(signature)
229
- end
230
-
231
- it "should replace signature in URI with params" do
232
- path = "http://vidibus.org/status?interval=2&sign=something&type=server"
233
- Vidibus::Secure.sign_request(:get, path, {}, key)
234
- path.should eql("http://vidibus.org/status?interval=2&sign=bd66fe642c39d01005090bb9d0a7f62f5c6d563878e6397261ed12bd79bdb92d&type=server")
235
- end
236
-
237
- it "should replace signature in URI without other params" do
238
- path = "http://vidibus.org/status?sign=something"
239
- Vidibus::Secure.sign_request(:get, path, {}, key)
240
- path.should eql("http://vidibus.org/status?sign=09247a2534f14e57081193ef6834b08843352c796af264f77e76445472dae9ed")
241
- end
242
-
243
- it "should create identical signatures for URIs with different params order" do
244
- signature = "116b6628f5b79a42ea9f8eb0e7901404ff641c34baa289dc32b6e2aa57c9281d"
245
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/status?a=1&b=2", {}, key).first.should match(signature)
246
- Vidibus::Secure.sign_request(:get, "http://vidibus.org/status/?b=2&a=1", {}, key).first.should match(signature)
247
- end
248
- end
249
-
250
- context "for request with body" do
251
- it "should create a signature of path and params" do
252
- params = {:some => "thing"}
253
- Vidibus::Secure.sign_request(:post, "/", params, key)
254
- params[:sign].should eql("a41b51acf01f7207d250a0a486e60ed385050f848237251efcdb58448e57d20d")
255
- end
256
-
257
- it "should create a signature of path and nested params" do
258
- params = {:some => {:nested => "params", :are => {:really => ["serious", "stuff"]}}}
259
- Vidibus::Secure.sign_request(:post, "/", params, key)
260
- params[:sign].should eql("3a899c65b9a68fa473e3bc3388b7656538c85498cc63cdcac59eebfe9f68ce07")
261
- end
262
-
263
- it "should create a different signature of path and nested params with switched keys" do
264
- params = {:some => {:are => "params", :nested => {:really => ["serious", "stuff"]}}}
265
- Vidibus::Secure.sign_request(:post, "/", params, key)
266
- params[:sign].should eql("d28b073381dad3c30bc8f5ff5984d7ff29e04dd95bc9ca04cd1ac95e878e4663")
267
- end
268
-
269
- it "should replace existing signature" do
270
- params = {:some => "thing", :sign => "something"}
271
- Vidibus::Secure.sign_request(:post, "/", params, key)
272
- params[:sign].should eql("a41b51acf01f7207d250a0a486e60ed385050f848237251efcdb58448e57d20d")
273
- end
274
-
275
- it "should add signature param as string if params are given as strings" do
276
- params = {"some" => "thing"}
277
- Vidibus::Secure.sign_request(:post, "/", params, key)
278
- params["some"].should eql("thing")
279
- params["sign"].should_not be_nil
280
- params[:sign].should be_nil
281
- end
282
-
283
- it "should add signature param as symbol if params are given as symbols" do
284
- params = {:some => "thing"}
285
- Vidibus::Secure.sign_request(:post, "/", params, key)
286
- params[:some].should eql("thing")
287
- params[:sign].should_not be_nil
288
- params["sign"].should be_nil
289
- end
290
-
291
- it "should add signature param as symbol if no params are given" do
292
- params = {}
293
- Vidibus::Secure.sign_request(:post, "/", params, key)
294
- params[:sign].should_not be_nil
295
- end
296
- end
297
- end
298
-
299
- describe ".verify_request" do
300
- it "should return true for a valid GET request" do
301
- path = "http://vidibus.org/status?type=server&sign=ff98a086cca8af703537afe873009f16ea5554826fa5d2665c212a13e44f7da0"
302
- Vidibus::Secure.verify_request(:get, path, {}, key).should be_true
303
- end
304
-
305
- it "should return true for a valid GET request even if verb is upcase" do
306
- path = "http://vidibus.org/status?type=server&sign=ff98a086cca8af703537afe873009f16ea5554826fa5d2665c212a13e44f7da0"
307
- Vidibus::Secure.verify_request("GET", path, {}, key).should be_true
308
- end
309
-
310
- it "should return true for a valid GET request if params are given as hash" do
311
- path = "http://vidibus.org/status"
312
- params = {:type => "server", :sign => "ff98a086cca8af703537afe873009f16ea5554826fa5d2665c212a13e44f7da0"}
313
- Vidibus::Secure.verify_request("GET", path, params, key).should be_true
314
- end
315
-
316
- it "should return false if additional params are given" do
317
- path = "http://vidibus.org/status?type=server&sign=ff98a086cca8af703537afe873009f16ea5554826fa5d2665c212a13e44f7da0"
318
- Vidibus::Secure.verify_request("GET", path, { :some => "thing" }, key).should be_false
319
- end
320
-
321
- it "should return true for a valid POST request with params given as symbols" do
322
- params = {:some => "thing", :sign => "a41b51acf01f7207d250a0a486e60ed385050f848237251efcdb58448e57d20d"}
323
- Vidibus::Secure.verify_request(:post, "/", params, key).should be_true
324
- end
325
-
326
- it "should return true for a valid POST request with params given as string" do
327
- params = {"some"=>"thing", "sign"=>"a41b51acf01f7207d250a0a486e60ed385050f848237251efcdb58448e57d20d"}
328
- Vidibus::Secure.verify_request(:post, "/", params, key).should be_true
329
- end
330
-
331
- it "should return true for a valid POST request with nested params" do
332
- params = {
333
- :sign => "3a899c65b9a68fa473e3bc3388b7656538c85498cc63cdcac59eebfe9f68ce07",
334
- :some => {:nested => "params", :are => {:really => ["serious", "stuff"]}}
335
- }
336
- Vidibus::Secure.verify_request(:post, "/", params, key).should be_true
337
- end
338
-
339
- it "should return false if signature is invalid" do
340
- path = "http://vidibus.org/status?type=server&sign=invalid"
341
- Vidibus::Secure.verify_request(:get, path, {}, key).should be_false
342
- end
343
-
344
- it "should return false if path does not match signature" do
345
- path = "http://vidibus.org/invalid?type=server&sign=068dbf2695798e3cda2710ae34d74043653eae41d82cbbdf39edebd7e2ae9a50"
346
- Vidibus::Secure.verify_request(:get, path, {}, key).should be_false
347
- end
348
-
349
- it "should return false if request verb does not match signature" do
350
- path = "http://vidibus.org/status?type=server&sign=ff98a086cca8af703537afe873009f16ea5554826fa5d2665c212a13e44f7da0"
351
- Vidibus::Secure.verify_request(:delete, path, {}, key).should be_false
352
- end
353
-
354
- it "should return false if params do not match signature" do
355
- params = {"sign" => "ff98a086cca8af703537afe873009f16ea5554826fa5d2665c212a13e44f7da0", "some" => "invalid"}
356
- Vidibus::Secure.verify_request(:post, "/", params, key).should be_false
357
- end
358
-
359
- it "should return false if signature does not match params" do
360
- params = {"sign" => "invalid", "some" => "thing"}
361
- Vidibus::Secure.verify_request(:post, "/", params, key).should be_false
362
- end
363
-
364
- it "should accept nil params" do
365
- expect { Vidibus::Secure.verify_request(:get, "", nil, key) }.to_not raise_error
366
- end
367
- end
368
- end
@@ -1,37 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path("../lib/", __FILE__)
3
- $:.unshift lib unless $:.include?(lib)
4
-
5
- require "vidibus/secure/version"
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "vidibus-secure"
9
- s.version = Vidibus::Secure::VERSION
10
- s.platform = Gem::Platform::RUBY
11
- s.authors = "Andre Pankratz"
12
- s.email = "andre@vidibus.com"
13
- s.homepage = "https://github.com/vidibus/vidibus-secure"
14
- s.summary = "Security tools for Vidibus applications"
15
- s.description = "Allows encryption and signing of requests and storing encrypted data within Mongoid documents."
16
-
17
- s.required_rubygems_version = ">= 1.3.6"
18
- s.rubyforge_project = "vidibus-resource"
19
-
20
- s.add_dependency "rack", "~> 1.2.1"
21
- s.add_dependency "mongoid", "~> 2"
22
- s.add_dependency "activesupport", "~> 3"
23
- s.add_dependency "json"
24
- s.add_dependency "vidibus-core_extensions"
25
-
26
- s.add_development_dependency "bundler", ">= 1.0.0"
27
- s.add_development_dependency "rake"
28
- s.add_development_dependency "rdoc"
29
- s.add_development_dependency "rspec", "~> 2"
30
- s.add_development_dependency "rr"
31
- s.add_development_dependency "rcov"
32
- s.add_development_dependency "actionpack", "~> 3"
33
-
34
- s.files = `git ls-files`.split("\n")
35
- s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
36
- s.require_path = 'lib'
37
- end