rplatform-rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +0 -0
- data/History.txt +2 -0
- data/Manifest.txt +22 -0
- data/README.txt +33 -0
- data/Rakefile +15 -0
- data/init.rb +22 -0
- data/lib/rplatform-rails.rb +45 -0
- data/lib/rplatform_rails/controller_extensions.rb +572 -0
- data/lib/rplatform_rails/model_extensions.rb +218 -0
- data/lib/rplatform_rails/session_extensions.rb +198 -0
- data/lib/rplatform_rails/status_manager.rb +312 -0
- data/lib/rplatform_rails/view_extensions.rb +93 -0
- data/tasks/all.rake +176 -0
- data/templates/debug_panel.rhtml +220 -0
- data/templates/exception_backtrace.rhtml +105 -0
- data/test/api_test.rb +203 -0
- data/test/controller_test.rb +257 -0
- data/test/initialization_test.rb +29 -0
- data/test/model_test.rb +142 -0
- data/test/session_test.rb +64 -0
- data/test/test_helper.rb +105 -0
- data/test/view_test.rb +30 -0
- metadata +92 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
<style type="text/css">
|
2
|
+
|
3
|
+
.RFacebook .backtrace
|
4
|
+
{
|
5
|
+
border-collapse: collapse;
|
6
|
+
background-color: #3B5998;
|
7
|
+
color: white;
|
8
|
+
}
|
9
|
+
|
10
|
+
.RFacebook .backtrace
|
11
|
+
{
|
12
|
+
padding: 30px;
|
13
|
+
background: #3B5998;
|
14
|
+
}
|
15
|
+
|
16
|
+
.RFacebook .backtrace h1
|
17
|
+
{
|
18
|
+
margin: 0px 0px 5px 0px;
|
19
|
+
padding: 0px;
|
20
|
+
|
21
|
+
color: #6D84B4;
|
22
|
+
font-size: 1.6em;
|
23
|
+
}
|
24
|
+
|
25
|
+
/*
|
26
|
+
.RFacebook table.backtrace td
|
27
|
+
{
|
28
|
+
padding: 10px 2px 10px 2px;
|
29
|
+
border-width: 1px 0px 1px 0px;
|
30
|
+
|
31
|
+
border-style: solid;
|
32
|
+
border-color: #ccc;
|
33
|
+
}
|
34
|
+
*/
|
35
|
+
|
36
|
+
.RFacebook .backtrace div.summary
|
37
|
+
{
|
38
|
+
font-size: 1.2em;
|
39
|
+
padding: 2px;
|
40
|
+
color: #6D84B4;
|
41
|
+
}
|
42
|
+
|
43
|
+
.RFacebook .backtrace div.summary strong
|
44
|
+
{
|
45
|
+
color: white;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
.RFacebook .backtrace div.summary em
|
50
|
+
{
|
51
|
+
color: white;
|
52
|
+
}
|
53
|
+
|
54
|
+
.RFacebook .backtrace div.rawsummary
|
55
|
+
{
|
56
|
+
font-size: 0.7em;
|
57
|
+
color: #6D84B4;
|
58
|
+
padding-left: 5px;
|
59
|
+
}
|
60
|
+
|
61
|
+
.RFacebook .backtrace div.message
|
62
|
+
{
|
63
|
+
font-size: 1.6em;
|
64
|
+
color: #6D84B4;
|
65
|
+
}
|
66
|
+
|
67
|
+
.RFacebook ul
|
68
|
+
{
|
69
|
+
margin: 0px;
|
70
|
+
padding: 0px;
|
71
|
+
list-style-type: none;
|
72
|
+
}
|
73
|
+
|
74
|
+
.RFacebook ul li
|
75
|
+
{
|
76
|
+
list-style-type: none;
|
77
|
+
padding: 5px;
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
</style>
|
83
|
+
|
84
|
+
<div class="RFacebook">
|
85
|
+
<div class="backtrace">
|
86
|
+
|
87
|
+
<div class="message">
|
88
|
+
<strong><%= exception.message %></strong>
|
89
|
+
</div>
|
90
|
+
<ul>
|
91
|
+
<% rfacebookBacktraceLines.each do |line| %>
|
92
|
+
<li>
|
93
|
+
<div class="summary">
|
94
|
+
<strong><%= line[:filename] %></strong>:<em><%= line[:line] %></em>
|
95
|
+
in <strong><%= line[:method] %></strong>
|
96
|
+
</div>
|
97
|
+
<div class="rawsummary">
|
98
|
+
<%= line[:rawsummary] %>
|
99
|
+
</div>
|
100
|
+
</li>
|
101
|
+
<% end %>
|
102
|
+
</ul>
|
103
|
+
|
104
|
+
</div>
|
105
|
+
</div>
|
data/test/api_test.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
require "test/unit"
|
3
|
+
require "rubygems"
|
4
|
+
require "mocha"
|
5
|
+
|
6
|
+
class APITest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_fbsession_methods_are_present
|
9
|
+
assert @controller.fbsession.respond_to?(:session_user_id)
|
10
|
+
assert @controller.fbsession.respond_to?(:session_key)
|
11
|
+
assert @controller.fbsession.respond_to?(:session_expires)
|
12
|
+
assert @controller.fbsession.respond_to?(:last_error_message), "This assertion is OK to fail with RFacebook Gem <= 0.9.1"
|
13
|
+
assert @controller.fbsession.respond_to?(:logger)
|
14
|
+
assert @controller.fbsession.respond_to?(:logger=)
|
15
|
+
assert @controller.fbsession.respond_to?(:ready?), "This assertion is OK to fail with RFacebook Gem <= 0.9.1"
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
|
20
|
+
# we want to test with the same fbsession that a real controller will get
|
21
|
+
@controller = DummyController.new
|
22
|
+
@request = ActionController::TestRequest.new
|
23
|
+
@response = ActionController::TestResponse.new
|
24
|
+
|
25
|
+
# simulate fbsession setup inside canvas
|
26
|
+
# (most common usage, but it really doesn't matter for this test case anyway)
|
27
|
+
@controller.simulate_inside_canvas
|
28
|
+
post :index
|
29
|
+
|
30
|
+
assert @controller.fbparams.size > 0, "API Test should have simulated fbparams properly"
|
31
|
+
assert @controller.fbsession.ready?, "API Test should have an fbsession that is ready to go"
|
32
|
+
|
33
|
+
# set up some dummy responses from the API
|
34
|
+
@dummy_error_response = <<-EOF
|
35
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
36
|
+
<error_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
|
37
|
+
<error_code>5</error_code>
|
38
|
+
<error_msg>Unauthorized source IP address (ip was: 10.1.2.3)</error_msg>
|
39
|
+
<request_args list="true">
|
40
|
+
<arg>
|
41
|
+
<key>method</key>
|
42
|
+
<value>facebook.friends.get</value>
|
43
|
+
</arg>
|
44
|
+
<arg>
|
45
|
+
<key>session_key</key>
|
46
|
+
<value>373443c857fcda2e410e349c-i7nF4PqX4IW4.</value>
|
47
|
+
</arg>
|
48
|
+
<arg>
|
49
|
+
<key>api_key</key>
|
50
|
+
<value>0289b21f46b2ee642d5c42145df5489f</value>
|
51
|
+
</arg>
|
52
|
+
<arg>
|
53
|
+
<key>call_id</key>
|
54
|
+
<value>1170813376.3544</value>
|
55
|
+
</arg>
|
56
|
+
<arg>
|
57
|
+
<key>v</key>
|
58
|
+
<value>1.0</value>
|
59
|
+
</arg>
|
60
|
+
<arg>
|
61
|
+
<key>sig</key>
|
62
|
+
<value>570dcc2b764578af350ea1e1622349a0</value>
|
63
|
+
</arg>
|
64
|
+
</request_args>
|
65
|
+
</error_response>
|
66
|
+
EOF
|
67
|
+
|
68
|
+
@dummy_auth_getSession_response = <<-EOF
|
69
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
70
|
+
<auth_getSession_response
|
71
|
+
xmlns="http://api.facebook.com/1.0/"
|
72
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
73
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
|
74
|
+
<session_key>5f34e11bfb97c762e439e6a5-8055</session_key>
|
75
|
+
<uid>8055</uid>
|
76
|
+
<expires>1173309298</expires>
|
77
|
+
</auth_getSession_response>
|
78
|
+
EOF
|
79
|
+
|
80
|
+
@dummy_group_getMembers_response = <<-EOF
|
81
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
82
|
+
<groups_getMembers_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
|
83
|
+
<members list="true">
|
84
|
+
<uid>4567</uid>
|
85
|
+
<uid>5678</uid>
|
86
|
+
<uid>6789</uid>
|
87
|
+
<uid>7890</uid>
|
88
|
+
</members>
|
89
|
+
<admins list="true">
|
90
|
+
<uid>1234567</uid>
|
91
|
+
</admins>
|
92
|
+
<officers list="true"/>
|
93
|
+
<not_replied list="true"/>
|
94
|
+
</groups_getMembers_response>
|
95
|
+
EOF
|
96
|
+
|
97
|
+
@dummy_users_getLoggedInUser_response = <<-EOF
|
98
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
99
|
+
<users_getLoggedInUser_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1234567</users_getLoggedInUser_response>
|
100
|
+
EOF
|
101
|
+
|
102
|
+
@dummy_users_getInfo_response = <<-EOF
|
103
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
104
|
+
<users_getInfo_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
|
105
|
+
<user>
|
106
|
+
<uid>8055</uid>
|
107
|
+
<about_me>This field perpetuates the glorification of the ego. Also, it has a character limit.</about_me>
|
108
|
+
<activities>Here: facebook, etc. There: Glee Club, a capella, teaching.</activities>
|
109
|
+
<affiliations list="true">
|
110
|
+
<affiliation>
|
111
|
+
<nid>50453093</nid>
|
112
|
+
<name>Facebook Developers</name>
|
113
|
+
<type>work</type>
|
114
|
+
<status/>
|
115
|
+
<year/>
|
116
|
+
</affiliation>
|
117
|
+
</affiliations>
|
118
|
+
<birthday>November 3</birthday>
|
119
|
+
<books>The Brothers K, GEB, Ken Wilber, Zen and the Art, Fitzgerald, The Emporer's New Mind, The Wonderful Story of Henry Sugar</books>
|
120
|
+
<current_location>
|
121
|
+
<city>Palo Alto</city>
|
122
|
+
<state>CA</state>
|
123
|
+
<country>United States</country>
|
124
|
+
<zip>94303</zip>
|
125
|
+
</current_location>
|
126
|
+
<education_history list="true">
|
127
|
+
<education_info>
|
128
|
+
<name>Harvard</name>
|
129
|
+
<year>2003</year>
|
130
|
+
<concentrations list="true">
|
131
|
+
<concentration>Applied Mathematics</concentration>
|
132
|
+
<concentration>Computer Science</concentration>
|
133
|
+
</concentrations>
|
134
|
+
</education_info>
|
135
|
+
</education_history>
|
136
|
+
<first_name>Dave</first_name>
|
137
|
+
<hometown_location>
|
138
|
+
<city>York</city>
|
139
|
+
<state>PA</state>
|
140
|
+
<country>United States</country>
|
141
|
+
<zip>0</zip>
|
142
|
+
</hometown_location>
|
143
|
+
<hs_info>
|
144
|
+
<hs1_name>Central York High School</hs1_name>
|
145
|
+
<hs2_name/>
|
146
|
+
<grad_year>1999</grad_year>
|
147
|
+
<hs1_id>21846</hs1_id>
|
148
|
+
<hs2_id>0</hs2_id>
|
149
|
+
</hs_info>
|
150
|
+
<is_app_user>1</is_app_user>
|
151
|
+
<has_added_app>1</has_added_app>
|
152
|
+
<interests>coffee, computers, the funny, architecture, code breaking,snowboarding, philosophy, soccer, talking to strangers</interests>
|
153
|
+
<last_name>Fetterman</last_name>
|
154
|
+
<meeting_for list="true">
|
155
|
+
<seeking>Friendship</seeking>
|
156
|
+
</meeting_for>
|
157
|
+
<meeting_sex list="true">
|
158
|
+
<sex>female</sex>
|
159
|
+
</meeting_sex>
|
160
|
+
<movies>Tommy Boy, Billy Madison, Fight Club, Dirty Work, Meet the Parents, My Blue Heaven, Office Space </movies>
|
161
|
+
<music>New Found Glory, Daft Punk, Weezer, The Crystal Method, Rage, the KLF, Green Day, Live, Coldplay, Panic at the Disco, Family Force 5</music>
|
162
|
+
<name>Dave Fetterman</name>
|
163
|
+
<notes_count>0</notes_count>
|
164
|
+
<pic>http://photos-055.facebook.com/ip007/profile3/1271/65/s8055_39735.jpg</pic>
|
165
|
+
<pic_big>http://photos-055.facebook.com/ip007/profile3/1271/65/n8055_39735.jpg</pic>
|
166
|
+
<pic_small>http://photos-055.facebook.com/ip007/profile3/1271/65/t8055_39735.jpg</pic>
|
167
|
+
<pic_square>http://photos-055.facebook.com/ip007/profile3/1271/65/q8055_39735.jpg</pic>
|
168
|
+
<political>Moderate</political>
|
169
|
+
<profile_update_time>1170414620</profile_update_time>
|
170
|
+
<quotes/>
|
171
|
+
<relationship_status>In a Relationship</relationship_status>
|
172
|
+
<religion/>
|
173
|
+
<sex>male</sex>
|
174
|
+
<significant_other_id xsi:nil="true"/>
|
175
|
+
<status>
|
176
|
+
<message/>
|
177
|
+
<time>0</time>
|
178
|
+
</status>
|
179
|
+
<timezone>-8</timezone>
|
180
|
+
<tv>cf. Bob Trahan</tv>
|
181
|
+
<wall_count>121</wall_count>
|
182
|
+
<work_history list="true">
|
183
|
+
<work_info>
|
184
|
+
<location>
|
185
|
+
<city>Palo Alto</city>
|
186
|
+
<state>CA</state>
|
187
|
+
<country>United States</country>
|
188
|
+
</location>
|
189
|
+
<company_name>Facebook</company_name>
|
190
|
+
<position>Software Engineer</position>
|
191
|
+
<description>Tech Lead, Facebook Platform</description>
|
192
|
+
<start_date>2006-01</start_date>
|
193
|
+
<end_date/>
|
194
|
+
</work_info>
|
195
|
+
</work_history>
|
196
|
+
</user>
|
197
|
+
</users_getInfo_response>
|
198
|
+
EOF
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
require "test/unit"
|
3
|
+
require "rubygems"
|
4
|
+
require "mocha"
|
5
|
+
|
6
|
+
class ControllerTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_before_filters_are_present
|
9
|
+
assert(@controller.respond_to?(:require_facebook_login))
|
10
|
+
assert(@controller.respond_to?(:require_facebook_install))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_facebook_helpers_are_present
|
14
|
+
assert(@controller.respond_to?(:in_facebook_canvas?))
|
15
|
+
assert(@controller.respond_to?(:in_facebook_frame?))
|
16
|
+
assert(@controller.respond_to?(:in_mock_ajax?))
|
17
|
+
assert(@controller.respond_to?(:in_ajax?))
|
18
|
+
assert(@controller.respond_to?(:in_external_app?))
|
19
|
+
assert(@controller.respond_to?(:added_facebook_application?))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_overrides_are_present
|
23
|
+
assert_rfacebook_overrides_method(@controller, :url_for)
|
24
|
+
assert_rfacebook_overrides_method(@controller, :redirect_to)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_unactivated_fbsession_raises_errors
|
28
|
+
post :index
|
29
|
+
assert_raise(RFacebook::FacebookSession::NotActivatedStandardError){@controller.fbsession.friends_get}
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_detect_user_has_added_app
|
33
|
+
|
34
|
+
# test adding app
|
35
|
+
post :index, {:fb_sig_added => 1}
|
36
|
+
assert(@controller.added_facebook_application?, "Should be installed")
|
37
|
+
|
38
|
+
# test not adding app
|
39
|
+
@controller.stub_fbparams
|
40
|
+
post :index
|
41
|
+
assert(!@controller.added_facebook_application?, "Should not be installed")
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_detect_user_in_canvas
|
46
|
+
|
47
|
+
# test adding app
|
48
|
+
post :index, {:fb_sig_in_canvas => 1}
|
49
|
+
assert(@controller.in_facebook_canvas?, "Should be in canvas")
|
50
|
+
|
51
|
+
# test not adding app
|
52
|
+
post :index
|
53
|
+
assert(!@controller.in_facebook_canvas?, "Should not be in canvas")
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_detect_user_in_iframe
|
58
|
+
|
59
|
+
# test adding app
|
60
|
+
post :index, {:fb_sig_in_iframe => 1}
|
61
|
+
assert(@controller.in_facebook_frame?, "Should be in iframe")
|
62
|
+
|
63
|
+
# test not adding app
|
64
|
+
post :index
|
65
|
+
assert(!@controller.in_facebook_frame?, "Should not be in iframe")
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_canvas_authentication_succeeds
|
70
|
+
@controller.simulate_inside_canvas
|
71
|
+
post :index
|
72
|
+
assert @controller.fbsession.ready?
|
73
|
+
assert_equal("viewing index", @response.body)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_fbsession_exists_and_is_correct
|
77
|
+
@controller.stub_fbparams
|
78
|
+
post :index
|
79
|
+
assert_kind_of(RFacebook::FacebookWebSession, @controller.fbsession)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_redirect_for_unauthenticated_user_in_external_site
|
83
|
+
post :index
|
84
|
+
#assert_redirected_to "http://www.facebook.com/login.php?v=1.0&api_key=#{@controller.facebook_api_key}"
|
85
|
+
assert_equal("<script type=\"text/javascript\">\ntop.location.href='http://www.facebook.com/login.php?v=1.0&api_key=#{@controller.facebook_api_key}';\n</script>", @response.body)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_should_redirect_for_unauthenticated_user_in_canvas
|
89
|
+
post :index, {:fb_sig_in_canvas => 1}
|
90
|
+
assert(!@controller.fbsession.ready?, "Session should be invalid since the user hasn't logged in.")
|
91
|
+
assert_equal("<fb:redirect url=\"http://www.facebook.com/login.php?v=1.0&api_key=#{@controller.facebook_api_key}&canvas=true\" />", @response.body)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_redirect_when_not_in_canvas
|
95
|
+
post :doredirect, {:redirect_url => "http://www.dummy.com"}
|
96
|
+
assert_redirected_to("http://www.dummy.com")
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_redirect_when_in_canvas
|
100
|
+
@controller.simulate_inside_canvas
|
101
|
+
assert(@controller.in_facebook_canvas?, "controller should detect that it is in the canvas")
|
102
|
+
post :doredirect, {:redirect_url => "http://www.dummy.com"}
|
103
|
+
assert_equal("<fb:redirect url=\"http://www.dummy.com\" />", @response.body)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_should_have_valid_session_when_auth_token_is_set_for_external_app
|
107
|
+
RFacebook::FacebookWebSession.any_instance.expects(:post_request).returns @dummy_auth_getSession_response1
|
108
|
+
post :index, {"auth_token" => "abc123"}
|
109
|
+
assert(@controller.fbsession.ready?, "session should be ready")
|
110
|
+
assert_equal("finished facebook login", @response.body)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_should_grab_new_session_when_different_but_valid_auth_token_is_given_for_external_app
|
114
|
+
# first request
|
115
|
+
RFacebook::FacebookWebSession.any_instance.expects(:post_request).returns @dummy_auth_getSession_response1
|
116
|
+
post :index, {"auth_token" => "abc123"}
|
117
|
+
assert(@controller.fbsession.ready?, "session should be ready after first request")
|
118
|
+
assert_equal("finished facebook login", @response.body)
|
119
|
+
|
120
|
+
firstSessionKey = @controller.fbsession.session_key
|
121
|
+
assert_equal("5f34e11bfb97c762e439e6a5-8055", firstSessionKey)
|
122
|
+
|
123
|
+
# second (valid) request, with a new auth token, except that the session is already activated
|
124
|
+
RFacebook::FacebookWebSession.any_instance.expects(:post_request).returns @dummy_auth_getSession_response2
|
125
|
+
post :index, {:auth_token => "xyz987"}
|
126
|
+
assert(@controller.fbsession.ready?, "session should be ready after second test")
|
127
|
+
assert_equal("finished facebook login", @response.body)
|
128
|
+
|
129
|
+
secondSessionKey = @controller.fbsession.session_key
|
130
|
+
assert_equal("21498732891470982137", secondSessionKey)
|
131
|
+
assert_not_equal(secondSessionKey, firstSessionKey, "Should have a new session key")
|
132
|
+
|
133
|
+
# third (invalid) request
|
134
|
+
RFacebook::FacebookWebSession.any_instance.expects(:remote_call).raises(RFacebook::FacebookSession::RemoteStandardError)
|
135
|
+
post :index, {:auth_token => "ijklmnop"}
|
136
|
+
assert(@controller.fbsession.ready?, "session should be ready after third test")
|
137
|
+
assert_equal("viewing index", @response.body)
|
138
|
+
|
139
|
+
thirdSessionKey = @controller.fbsession.session_key
|
140
|
+
assert_equal(thirdSessionKey, secondSessionKey, "Session key should be unchanged")
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_should_have_empty_fbparams_when_signature_is_invalid
|
145
|
+
post :nofilter, {:fb_sig_session_key => "12345", :fb_sig => "invalidsignature123"}
|
146
|
+
assert(@controller.fbparams.size == 0)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_should_rewrite_urls_when_in_canvas
|
150
|
+
@controller.simulate_inside_canvas
|
151
|
+
post :render_foobar_action_on_callback
|
152
|
+
assert @controller.in_facebook_canvas?, "Should be in canvas for rewriting to happen"
|
153
|
+
assert_equal("http://apps.facebook.com#{@controller.facebook_canvas_path}foobar", @response.body)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_should_not_rewrite_urls_when_outside_canvas
|
157
|
+
post :render_foobar_action_on_callback
|
158
|
+
assert !@controller.in_facebook_canvas?, "Should not be in canvas"
|
159
|
+
assert_equal("#{@controller.facebook_callback_path}foobar", @response.body)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_should_detect_in_mock_ajax
|
163
|
+
@controller.stub_fbparams
|
164
|
+
@controller.simulate_inside_canvas({"fb_sig_is_mockajax" => "1"})
|
165
|
+
post :index
|
166
|
+
assert(@controller.in_mock_ajax?, "should be in mockajax")
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_should_be_able_to_marshal_fbsession
|
170
|
+
@controller.stub_fbparams
|
171
|
+
@controller.simulate_inside_canvas
|
172
|
+
post :index
|
173
|
+
|
174
|
+
originalSession = @controller.fbsession.dup
|
175
|
+
|
176
|
+
serializedSession = Marshal.dump(originalSession)
|
177
|
+
assert serializedSession
|
178
|
+
|
179
|
+
deserializedSession = Marshal.load(serializedSession)
|
180
|
+
assert deserializedSession
|
181
|
+
|
182
|
+
assert_equal(originalSession.session_user_id , deserializedSession.session_user_id)
|
183
|
+
assert_equal(originalSession.session_key , deserializedSession.session_key)
|
184
|
+
assert_equal(originalSession.session_expires , deserializedSession.session_expires)
|
185
|
+
assert_equal(originalSession.quiet? , deserializedSession.quiet?)
|
186
|
+
assert_equal(originalSession.ready? , deserializedSession.ready?)
|
187
|
+
assert_equal(originalSession.expired? , deserializedSession.expired?)
|
188
|
+
|
189
|
+
assert_equal(originalSession.class, deserializedSession.class)
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_view_should_not_prepend_image_paths_that_are_already_absolute
|
193
|
+
# TODO: implement this
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_should_not_change_only_path_when_specified
|
197
|
+
# TODO: implement this
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_should_detect_new_user_has_logged_in_when_in_iframe
|
201
|
+
|
202
|
+
# log in the first user to the iframe
|
203
|
+
post :index
|
204
|
+
@controller.stub_fbparams("user" => "ABCDEFG", "in_iframe"=>true)
|
205
|
+
assert @controller.fbsession.ready?
|
206
|
+
assert_equal "ABCDEFG", @controller.fbsession.session_user_id
|
207
|
+
|
208
|
+
# simulate a new user coming to the iframe (logout/login cycle happened in Facebook)
|
209
|
+
post :index
|
210
|
+
|
211
|
+
# clear out the old login
|
212
|
+
@controller.log_out_of_facebook
|
213
|
+
|
214
|
+
@controller.stub_fbparams("user" => "ZYXWVUT", "in_iframe"=>true)
|
215
|
+
assert @controller.fbsession.ready?
|
216
|
+
assert_equal "ZYXWVUT", @controller.fbsession.session_user_id
|
217
|
+
|
218
|
+
# simulate someone coming back to the iframe without POSTed fb_sig params
|
219
|
+
# (should use previous session from Rails session)
|
220
|
+
post :index
|
221
|
+
assert @controller.fbsession.ready?
|
222
|
+
assert_equal("ZYXWVUT", @controller.fbsession.session_user_id, "should have grabbed fbsession from Rails session")
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
def setup
|
227
|
+
@controller = DummyController.new
|
228
|
+
@request = ActionController::TestRequest.new
|
229
|
+
@response = ActionController::TestResponse.new
|
230
|
+
|
231
|
+
@dummy_auth_getSession_response1 = <<-EOF
|
232
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
233
|
+
<auth_getSession_response
|
234
|
+
xmlns="http://api.facebook.com/1.0/"
|
235
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
236
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
|
237
|
+
<session_key>5f34e11bfb97c762e439e6a5-8055</session_key>
|
238
|
+
<uid>8055</uid>
|
239
|
+
<expires>1173309298</expires>
|
240
|
+
</auth_getSession_response>
|
241
|
+
EOF
|
242
|
+
|
243
|
+
@dummy_auth_getSession_response2 = <<-EOF
|
244
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
245
|
+
<auth_getSession_response
|
246
|
+
xmlns="http://api.facebook.com/1.0/"
|
247
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
248
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
|
249
|
+
<session_key>21498732891470982137</session_key>
|
250
|
+
<uid>8055</uid>
|
251
|
+
<expires>1173309298</expires>
|
252
|
+
</auth_getSession_response>
|
253
|
+
EOF
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|