carrot-facebook 0.0.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,7 @@ module Carrot
21
21
  begin
22
22
  path_override = Yajl::Parser.parse(env[:facebook_data][:app_data], symbolize_keys: true)
23
23
  env['PATH_INFO'] = path_override[:path] if path_override[:path]
24
+ env['QUERY_STRING'] = path_override[:params].map { |params| params.join('=') }.join('&') if path_override[:params]
24
25
  env[:facebook_data][:app_data] = path_override
25
26
  rescue => e
26
27
  env[:facebook_data][:app_data] = env[:facebook_data][:app_data]
@@ -1,5 +1,5 @@
1
1
  module Carrot
2
2
  module Facebook
3
- VERSION = "0.0.2"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
@@ -100,7 +100,7 @@ describe Carrot::Facebook::Middleware do
100
100
 
101
101
  context "when is a canvas app and sends a valid signed_request" do
102
102
  before(:all) do
103
- @signed_request = 'signed_request=kUbujwbyaKAS3EMLSolZki1mJtuzY5-XUrchNN3MVyI.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTMzMTY2NTg5NCwicGFnZSI6eyJpZCI6IjEzNzczOTk4Mjk0MjI3NCIsImxpa2VkIjpmYWxzZSwiYWRtaW4iOnRydWV9LCJ1c2VyIjp7ImNvdW50cnkiOiJ1cyIsImxvY2FsZSI6ImVuX1VTIiwiYWdlIjp7Im1pbiI6MjF9fX0'
103
+ @signed_request = "signed_request=#{encode_signed_request(@valid_facebook_data)}"
104
104
  @request = Rack::MockRequest.env_for('/', lint: true, fatal: true, method: 'POST', input: @signed_request)
105
105
  @response = Carrot::Facebook::Middleware.new(@app).call(@request)
106
106
  end
@@ -128,7 +128,8 @@ describe Carrot::Facebook::Middleware do
128
128
 
129
129
  context "when is a canvas app and sends a valid signed_request with app_data" do
130
130
  before(:all) do
131
- @signed_request = 'signed_request=PGQuysjAoFJBxu2Me_HizoVv8BdiPdm5wBhkcdHZaR0.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImFwcF9kYXRhIjoie1wicGF0aFwiOlwiXC9wYWdlXC90ZXJtc1wifSIsImlzc3VlZF9hdCI6MTMzMTY2OTE4NSwicGFnZSI6eyJpZCI6IjEzNzczOTk4Mjk0MjI3NCIsImxpa2VkIjpmYWxzZSwiYWRtaW4iOnRydWV9LCJ1c2VyIjp7ImNvdW50cnkiOiJ1cyIsImxvY2FsZSI6ImVuX1VTIiwiYWdlIjp7Im1pbiI6MjF9fX0'
131
+ @data = @valid_facebook_data.merge({ issued_at: 1331669185, app_data: { path: '/page/terms' } })
132
+ @signed_request = "signed_request=#{encode_signed_request(@data)}"
132
133
  @request = Rack::MockRequest.env_for('/', lint: true, fatal: true, method: 'POST', input: @signed_request)
133
134
  @response = Carrot::Facebook::Middleware.new(@app).call(@request)
134
135
  end
@@ -150,7 +151,41 @@ describe Carrot::Facebook::Middleware do
150
151
  end
151
152
 
152
153
  it 'should correctly set :facebook_data' do
153
- expect(@request[:facebook_data]).to eq @valid_facebook_data.merge({ issued_at: 1331669185, app_data: { path: '/page/terms' } })
154
+ expect(@request[:facebook_data]).to eq @data
155
+ end
156
+ end
157
+
158
+ context "when sending a parameter in the request with app_data" do
159
+ before(:all) do
160
+ @data = @valid_facebook_data.merge({ issued_at: 1331669185, app_data: { path: '/page/terms', params: { foo: 'bar' } } })
161
+ @signed_request = "signed_request=#{encode_signed_request(@data)}"
162
+ @request = Rack::MockRequest.env_for('/', lint: true, fatal: true, method: 'POST', input: @signed_request)
163
+ @response = Carrot::Facebook::Middleware.new(@app).call(@request)
164
+ end
165
+
166
+ it 'should properly set parameters passed to app_data on the signed request' do
167
+ expect(@request[:facebook_data]).to eq @data
168
+ end
169
+
170
+ it 'should recognize the params object within app_data' do
171
+ @request[:facebook_data][:app_data][:params].should == {foo: 'bar'}
172
+ end
173
+ end
174
+
175
+ context "when sending multiple parameters in the request with app_data" do
176
+ before(:all) do
177
+ @data = @valid_facebook_data.merge({ issued_at: 1331669185, app_data: { path: '/page/terms', params: { foo: 'bar', bar: 'baz', bee: 'bop' } } })
178
+ @signed_request = "signed_request=#{encode_signed_request(@data)}"
179
+ @request = Rack::MockRequest.env_for('/', lint: true, fatal: true, method: 'POST', input: @signed_request)
180
+ @response = Carrot::Facebook::Middleware.new(@app).call(@request)
181
+ end
182
+
183
+ it 'should properly set parameters passed to app_data on the signed request' do
184
+ expect(@request[:facebook_data]).to eq @data
185
+ end
186
+
187
+ it 'should recognize the params object within app_data' do
188
+ @request[:facebook_data][:app_data][:params].should == {foo: 'bar', bar: 'baz', bee: 'bop'}
154
189
  end
155
190
  end
156
191
  end
@@ -1,7 +1,23 @@
1
1
  require "rails/all"
2
+ require "json"
3
+ require "base64"
4
+ require "openssl"
2
5
  require "carrot-facebook"
3
6
 
7
+ module Helpers
8
+ def encode_signed_request(options)
9
+ encoded_data = Base64.urlsafe_encode64( options.to_json ).tr('=', '')
10
+ digestor = OpenSSL::Digest::Digest.new('sha256')
11
+ signature = OpenSSL::HMAC.digest( digestor, '', encoded_data )
12
+ encoded_signature = Base64.strict_encode64( signature ).tr("+/", "-_")
13
+ encoded_signature = encoded_signature.tr('=', '')
14
+
15
+ "#{encoded_signature}.#{encoded_data}"
16
+ end
17
+ end
18
+
4
19
  RSpec.configure do |config|
5
20
  config.color_enabled = true
6
21
  config.formatter = :documentation
7
- end
22
+ config.include Helpers
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrot-facebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-21 00:00:00.000000000 Z
13
+ date: 2013-02-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: yajl-ruby
17
- requirement: &70332661964060 !ruby/object:Gem::Requirement
17
+ requirement: &70105908695560 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70332661964060
25
+ version_requirements: *70105908695560
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: p3p
28
- requirement: &70332661957000 !ruby/object:Gem::Requirement
28
+ requirement: &70105908694960 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70332661957000
36
+ version_requirements: *70105908694960
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rails
39
- requirement: &70332661956300 !ruby/object:Gem::Requirement
39
+ requirement: &70105908694280 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70332661956300
47
+ version_requirements: *70105908694280
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &70332661955860 !ruby/object:Gem::Requirement
50
+ requirement: &70105908693640 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70332661955860
58
+ version_requirements: *70105908693640
59
59
  description: Facebook view helpers and signed request handling.
60
60
  email:
61
61
  - tmilewski@gmail.com