facebook_canvas 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/facebook_canvas.rb +9 -1
- data/lib/facebook_canvas/engine.rb +3 -1
- data/lib/facebook_canvas/middleware.rb +38 -4
- data/lib/facebook_canvas/version.rb +1 -1
- data/test/dummy/log/test.log +5225 -0
- data/test/facebook_canvas/middleware_test.rb +160 -0
- data/test/integration/middleware_test.rb +1 -1
- data/test/test_helper.rb +3 -4
- metadata +51 -35
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FacebookCanvas::MiddlewareTest < ActiveSupport::TestCase
|
4
|
+
let(:middleware) { FacebookCanvas::Middleware.new(app, request_host, custom_filter, **kwargs) }
|
5
|
+
let(:request_host) { %r{.*} }
|
6
|
+
let(:custom_filter) { proc { |_env| true } }
|
7
|
+
let(:kwargs) { {} }
|
8
|
+
let(:app) { proc { |env| [200, {}, env] } }
|
9
|
+
let(:env) {
|
10
|
+
{
|
11
|
+
"SERVER_NAME" => "test.host",
|
12
|
+
"REQUEST_METHOD" => original_request_method,
|
13
|
+
}
|
14
|
+
}
|
15
|
+
let(:original_request_method) { "POST" }
|
16
|
+
|
17
|
+
describe "request_host" do
|
18
|
+
describe "matching via regexp" do
|
19
|
+
describe "matching any host" do
|
20
|
+
let(:request_host) { %r{.*} }
|
21
|
+
|
22
|
+
test "modifies request method to GET" do
|
23
|
+
env["SERVER_NAME"] = "anything"
|
24
|
+
assert_request_method "GET"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "matching speficic host" do
|
29
|
+
let(:request_host) { %r{\.fb\.} }
|
30
|
+
|
31
|
+
test "modifies request method to GET if matched" do
|
32
|
+
env["SERVER_NAME"] = "test.fb.host"
|
33
|
+
assert_request_method "GET"
|
34
|
+
end
|
35
|
+
|
36
|
+
test "does not change request method" do
|
37
|
+
env["SERVER_NAME"] = "test.facebook.host"
|
38
|
+
refute_request_method_change
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "matching via proc" do
|
44
|
+
let(:request_host) do
|
45
|
+
proc { |env| env[:pass_server_name] }
|
46
|
+
end
|
47
|
+
|
48
|
+
test "modifies request method to GET" do
|
49
|
+
env[:pass_server_name] = true
|
50
|
+
assert_request_method "GET"
|
51
|
+
end
|
52
|
+
|
53
|
+
test "does not change request method" do
|
54
|
+
env[:pass_server_name] = false
|
55
|
+
refute_request_method_change
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "matching via other objects" do
|
60
|
+
let(:request_host) { :something }
|
61
|
+
|
62
|
+
test "fails initialization with ArgumentError" do
|
63
|
+
e = assert_raises ArgumentError do
|
64
|
+
middleware
|
65
|
+
end
|
66
|
+
assert_equal "Expected Regexp or Proc for `request_host` but got: :something", e.message
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "custom_filter" do
|
72
|
+
let(:custom_filter) do
|
73
|
+
proc { |env| env[:pass_custom_filter] }
|
74
|
+
end
|
75
|
+
|
76
|
+
test "modifies request method to GET if matched" do
|
77
|
+
env[:pass_custom_filter] = true
|
78
|
+
assert_request_method "GET"
|
79
|
+
end
|
80
|
+
|
81
|
+
test "prevents change of request method" do
|
82
|
+
env[:pass_custom_filter] = false
|
83
|
+
refute_request_method_change
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "with Rails' POST request" do
|
88
|
+
before do
|
89
|
+
env["rack.request.form_hash"] = {
|
90
|
+
"utf8" => "✓"
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
test "does not change request method" do
|
95
|
+
refute_request_method_change
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "with Rails' XHR requests" do
|
100
|
+
before do
|
101
|
+
env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
|
102
|
+
end
|
103
|
+
|
104
|
+
test "does not change request method" do
|
105
|
+
refute_request_method_change
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "inside_filter" do
|
110
|
+
describe "is optional" do
|
111
|
+
test "modifies request method to GET if matched" do
|
112
|
+
# no kwargs
|
113
|
+
assert_request_method "GET"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "is set" do
|
118
|
+
before do
|
119
|
+
kwargs[:inside_filter] = proc { |env| env[:pass_inside_filter] }
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "accepted by the filter" do
|
123
|
+
before do
|
124
|
+
env[:pass_inside_filter] = true
|
125
|
+
end
|
126
|
+
|
127
|
+
test ".inside?(env) returns true" do
|
128
|
+
_, _, new_env = middleware.call(env)
|
129
|
+
assert FacebookCanvas::Middleware.inside?(new_env)
|
130
|
+
end
|
131
|
+
|
132
|
+
test "modifies request method to GET if matched" do
|
133
|
+
assert_request_method "GET"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "denied by the filter" do
|
138
|
+
before do
|
139
|
+
env[:pass_inside_filter] = false
|
140
|
+
end
|
141
|
+
test "does not change request method" do
|
142
|
+
refute_request_method_change
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def assert_request_method(expected)
|
151
|
+
status, headers, body = middleware.call(env)
|
152
|
+
|
153
|
+
assert_instance_of Hash, body
|
154
|
+
assert_equal expected, body.fetch("REQUEST_METHOD")
|
155
|
+
end
|
156
|
+
|
157
|
+
def refute_request_method_change
|
158
|
+
assert_request_method original_request_method
|
159
|
+
end
|
160
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
CodeClimate::TestReporter.start
|
4
|
-
end
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start
|
5
3
|
|
6
4
|
# Configure Rails Environment
|
7
5
|
ENV["RAILS_ENV"] = "test"
|
@@ -10,6 +8,7 @@ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
|
10
8
|
require "rails/test_help"
|
11
9
|
|
12
10
|
require "minitest/rails"
|
11
|
+
require "minitest/focus" unless ENV["CI"]
|
13
12
|
|
14
13
|
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
15
14
|
# to be shown.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebook_canvas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André Stuhrmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-focus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- as@neopoly.de
|
@@ -92,6 +106,7 @@ files:
|
|
92
106
|
- test/dummy/public/422.html
|
93
107
|
- test/dummy/public/500.html
|
94
108
|
- test/dummy/public/favicon.ico
|
109
|
+
- test/facebook_canvas/middleware_test.rb
|
95
110
|
- test/facebook_canvas/signed_request_test.rb
|
96
111
|
- test/facebook_canvas_test.rb
|
97
112
|
- test/fixtures/signed_request.txt
|
@@ -118,51 +133,52 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
133
|
version: '0'
|
119
134
|
requirements: []
|
120
135
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.6.11
|
122
137
|
signing_key:
|
123
138
|
specification_version: 4
|
124
139
|
summary: Rails engine for Facebook's canvas integration.
|
125
140
|
test_files:
|
126
|
-
- test/facebook_canvas/signed_request_test.rb
|
127
141
|
- test/integration/middleware_test.rb
|
128
|
-
- test/
|
142
|
+
- test/facebook_canvas_test.rb
|
143
|
+
- test/test_helper.rb
|
144
|
+
- test/facebook_canvas/middleware_test.rb
|
145
|
+
- test/facebook_canvas/signed_request_test.rb
|
146
|
+
- test/dummy/log/test.log
|
147
|
+
- test/dummy/Rakefile
|
148
|
+
- test/dummy/bin/setup
|
149
|
+
- test/dummy/bin/rails
|
150
|
+
- test/dummy/bin/bundle
|
151
|
+
- test/dummy/bin/rake
|
152
|
+
- test/dummy/README.rdoc
|
153
|
+
- test/dummy/config/environment.rb
|
154
|
+
- test/dummy/config/boot.rb
|
155
|
+
- test/dummy/config/secrets.yml
|
129
156
|
- test/dummy/config/routes.rb
|
130
|
-
- test/dummy/config/
|
157
|
+
- test/dummy/config/initializers/inflections.rb
|
158
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
159
|
+
- test/dummy/config/initializers/session_store.rb
|
131
160
|
- test/dummy/config/initializers/cookies_serializer.rb
|
132
161
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
133
162
|
- test/dummy/config/initializers/mime_types.rb
|
134
|
-
- test/dummy/config/initializers/assets.rb
|
135
163
|
- test/dummy/config/initializers/wrap_parameters.rb
|
136
|
-
- test/dummy/config/initializers/
|
137
|
-
- test/dummy/config/
|
138
|
-
- test/dummy/config/
|
164
|
+
- test/dummy/config/initializers/assets.rb
|
165
|
+
- test/dummy/config/database.yml
|
166
|
+
- test/dummy/config/locales/en.yml
|
167
|
+
- test/dummy/config/environments/development.rb
|
139
168
|
- test/dummy/config/environments/production.rb
|
140
169
|
- test/dummy/config/environments/test.rb
|
141
|
-
- test/dummy/config/
|
142
|
-
- test/dummy/config/locales/en.yml
|
143
|
-
- test/dummy/config/environment.rb
|
144
|
-
- test/dummy/config/boot.rb
|
145
|
-
- test/dummy/config/secrets.yml
|
146
|
-
- test/dummy/config.ru
|
147
|
-
- test/dummy/bin/bundle
|
148
|
-
- test/dummy/bin/rake
|
149
|
-
- test/dummy/bin/rails
|
150
|
-
- test/dummy/bin/setup
|
151
|
-
- test/dummy/Rakefile
|
152
|
-
- test/dummy/README.rdoc
|
153
|
-
- test/dummy/app/assets/stylesheets/application.css
|
154
|
-
- test/dummy/app/assets/javascripts/application.js
|
155
|
-
- test/dummy/app/helpers/application_helper.rb
|
156
|
-
- test/dummy/app/controllers/foo_controller.rb
|
157
|
-
- test/dummy/app/controllers/application_controller.rb
|
158
|
-
- test/dummy/app/views/foo/create.haml
|
159
|
-
- test/dummy/app/views/layouts/application.html.erb
|
160
|
-
- test/dummy/log/test.log
|
161
|
-
- test/dummy/public/favicon.ico
|
162
|
-
- test/dummy/public/404.html
|
170
|
+
- test/dummy/config/application.rb
|
163
171
|
- test/dummy/public/500.html
|
164
172
|
- test/dummy/public/422.html
|
165
|
-
- test/
|
166
|
-
- test/
|
167
|
-
- test/
|
173
|
+
- test/dummy/public/404.html
|
174
|
+
- test/dummy/public/favicon.ico
|
175
|
+
- test/dummy/app/views/foo/create.haml
|
176
|
+
- test/dummy/app/views/layouts/application.html.erb
|
177
|
+
- test/dummy/app/assets/javascripts/application.js
|
178
|
+
- test/dummy/app/assets/stylesheets/application.css
|
179
|
+
- test/dummy/app/controllers/application_controller.rb
|
180
|
+
- test/dummy/app/controllers/foo_controller.rb
|
181
|
+
- test/dummy/app/helpers/application_helper.rb
|
182
|
+
- test/dummy/config.ru
|
168
183
|
- test/fixtures/signed_request.txt
|
184
|
+
- test/fixtures/signed_request_with_user_id.txt
|