impostor 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/Manifest.txt +9 -0
- data/README.txt +10 -3
- data/Rakefile +1 -1
- data/lib/www/impostor/phpbb2.rb +5 -7
- data/lib/www/impostor/phpbb3.rb +236 -0
- data/lib/www/impostor.rb +1 -1
- data/test/fixtures/phpbb2-not-logged-in.html +530 -145
- data/test/fixtures/phpbb3-get-new-topic-form-good-response.html +975 -0
- data/test/fixtures/phpbb3-get-reply-form-good-response.html +1015 -0
- data/test/fixtures/phpbb3-logged-in.html +512 -0
- data/test/fixtures/phpbb3-login.html +423 -0
- data/test/fixtures/phpbb3-not-logged-in.html +426 -0
- data/test/fixtures/phpbb3-post-new_topic-good-response.html +894 -0
- data/test/fixtures/phpbb3-post-reply-good-response.html +2077 -0
- data/test/test_www_impostor_phpbb3.rb +483 -0
- metadata +19 -27
- data.tar.gz.sig +0 -3
- metadata.gz.sig +0 -3
@@ -0,0 +1,483 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "www", "impostor")
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "www", "impostor", "phpbb3")
|
3
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'rubygems'
|
7
|
+
require 'mocha'
|
8
|
+
require 'mechanize'
|
9
|
+
|
10
|
+
class TestWwwImpostorPhpbb3 < Test::Unit::TestCase
|
11
|
+
include TestHelper
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@cookie_jar = File.join(Dir.tmpdir, 'www_impostor_phpbb_test.yml')
|
15
|
+
@app_root = 'http://localhost/phpbb3/'
|
16
|
+
@im = WWW::Impostor.new(config())
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
File.delete(@cookie_jar) if File.exist?(@cookie_jar)
|
21
|
+
end
|
22
|
+
|
23
|
+
def config(config={})
|
24
|
+
c = {:type => :phpbb3,
|
25
|
+
:app_root => @app_root,
|
26
|
+
:login_page => 'ucp.php?mode=login',
|
27
|
+
:posting_page => 'posting.php',
|
28
|
+
:user_agent => 'Windows IE 7',
|
29
|
+
:username => 'tester',
|
30
|
+
:password => 'test',
|
31
|
+
:cookie_jar => @cookie_jar
|
32
|
+
}.merge(config)
|
33
|
+
c
|
34
|
+
end
|
35
|
+
|
36
|
+
def phpbb3_good_submit_new_topic_form
|
37
|
+
load_page('phpbb3-get-new-topic-form-good-response.html').join
|
38
|
+
end
|
39
|
+
|
40
|
+
def phpbb3_good_submit_post_form
|
41
|
+
body = load_page('phpbb3-get-reply-form-good-response.html').join
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_initialize_with_cookie_jar
|
45
|
+
FileUtils.touch(@cookie_jar)
|
46
|
+
|
47
|
+
WWW::Mechanize::CookieJar.any_instance.expects(:load).once.with(@cookie_jar)
|
48
|
+
im = WWW::Impostor.new(config())
|
49
|
+
assert im
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_initialize_without_cookie_jar
|
53
|
+
WWW::Mechanize::CookieJar.any_instance.expects(:load).never
|
54
|
+
im = WWW::Impostor.new(config())
|
55
|
+
assert im
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_version
|
59
|
+
assert_equal @im.version, "WWW::Impostor::Phpbb3"
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_fetch_login_page
|
63
|
+
page = load_page('phpbb3-login.html').join
|
64
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(
|
65
|
+
URI.join(@app_root, config[:login_page])
|
66
|
+
).returns(page)
|
67
|
+
|
68
|
+
assert_equal page, @im.send(:fetch_login_page)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_login_form_and_button_should_return_a_form_and_button
|
72
|
+
response = {'content-type' => 'text/html'}
|
73
|
+
body = load_page('phpbb3-login.html').join
|
74
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
75
|
+
form, button = @im.send(:login_form_and_button, page)
|
76
|
+
assert_equal "POST", form.method
|
77
|
+
assert_equal "./ucp.php?mode=login&sid=a9b66b7fedae3d5696d297194f940aa4", form.action
|
78
|
+
assert_equal true, form.is_a?(WWW::Mechanize::Form)
|
79
|
+
assert_equal true, button.is_a?(WWW::Mechanize::Form::Button)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_login_form_and_button_should_raise_login_error_when_form_is_missing
|
83
|
+
err = assert_raise(WWW::Impostor::LoginError) do
|
84
|
+
form, button = @im.send(:login_form_and_button, nil)
|
85
|
+
end
|
86
|
+
assert_equal "unknown login page format", err.original_exception.message
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_post_login_should_return_page
|
90
|
+
response = {'content-type' => 'text/html'}
|
91
|
+
body = load_page('phpbb3-logged-in.html').join
|
92
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
93
|
+
form = mock()
|
94
|
+
button = mock()
|
95
|
+
WWW::Mechanize.any_instance.expects(:submit).once.with(form, button).returns(page)
|
96
|
+
|
97
|
+
assert_equal page, @im.send(:post_login, form, button)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_post_login_should_raise_login_error
|
101
|
+
errmsg = "from test #{Time.now.to_s}"
|
102
|
+
WWW::Mechanize.any_instance.expects(:submit).raises(StandardError, errmsg)
|
103
|
+
err = assert_raise(WWW::Impostor::LoginError) do
|
104
|
+
page = @im.send(:post_login, nil, nil)
|
105
|
+
end
|
106
|
+
assert_equal errmsg, err.original_exception.message
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_bad_login_page_should_raise_exception
|
110
|
+
errmsg = "from test #{Time.now.to_s}"
|
111
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(
|
112
|
+
URI.join(@app_root, config[:login_page])
|
113
|
+
).raises(StandardError, errmsg)
|
114
|
+
|
115
|
+
err = assert_raise(WWW::Impostor::LoginError) do
|
116
|
+
@im.send(:fetch_login_page)
|
117
|
+
end
|
118
|
+
assert_equal errmsg, err.original_exception.message
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_already_logged_in_should_not_post_login_information_again_instance_varialbe
|
122
|
+
@im.instance_variable_set(:@loggedin, true)
|
123
|
+
@im.expects(:fetch_login_page).never
|
124
|
+
assert_equal true, @im.login
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_already_logged_in_should_not_post_login_information_again
|
128
|
+
@im.instance_variable_set(:@loggedin, false)
|
129
|
+
page = mock()
|
130
|
+
@im.stubs(:fetch_login_page).returns(page)
|
131
|
+
@im.expects(:logged_in?).once.with(page).returns(true)
|
132
|
+
@im.expects(:login_form_and_button).with(page).never
|
133
|
+
@im.login
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_login_should_login
|
137
|
+
@im.instance_variable_set(:@loggedin, false)
|
138
|
+
login_page = mock()
|
139
|
+
@im.stubs(:fetch_login_page).returns(login_page)
|
140
|
+
@im.expects(:logged_in?).once.with(login_page).returns(false)
|
141
|
+
form = mock()
|
142
|
+
button = mock()
|
143
|
+
@im.expects(:login_form_and_button).with(login_page).returns([form, button])
|
144
|
+
logged_in_page = mock()
|
145
|
+
@im.expects(:post_login).with(form, button).returns(logged_in_page)
|
146
|
+
@im.expects(:logged_in?).once.with(logged_in_page).returns(true)
|
147
|
+
@im.expects(:load_topics).once.returns(true)
|
148
|
+
|
149
|
+
assert_equal true, @im.login
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_should_be_logged_in?
|
153
|
+
response = {'content-type' => 'text/html'}
|
154
|
+
body = load_page('phpbb3-logged-in.html').join
|
155
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
156
|
+
assert_equal true, @im.send(:logged_in?, page)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_should_not_be_logged_in?
|
160
|
+
response = {'content-type' => 'text/html'}
|
161
|
+
body = load_page('phpbb3-not-logged-in.html').join
|
162
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
163
|
+
assert_equal false, @im.send(:logged_in?, page)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_logout_does_nothing_if_logged_out
|
167
|
+
@im.instance_variable_set(:@loggedin, false)
|
168
|
+
@im.expects(:cookie_jar).never
|
169
|
+
@im.expects(:save_topics).never
|
170
|
+
assert_equal false, @im.logout
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_logout
|
174
|
+
@im.instance_variable_set(:@loggedin, true)
|
175
|
+
cookie_jar = mock()
|
176
|
+
@im.expects(:cookie_jar).times(2).returns(cookie_jar)
|
177
|
+
WWW::Mechanize::CookieJar.any_instance.expects(:save_as).once.with(cookie_jar).returns(nil)
|
178
|
+
@im.expects(:save_topics).once
|
179
|
+
assert_equal true, @im.logout
|
180
|
+
assert_equal nil, @im.instance_variable_get(:@forum)
|
181
|
+
assert_equal nil, @im.instance_variable_get(:@topic)
|
182
|
+
assert_equal nil, @im.instance_variable_get(:@subject)
|
183
|
+
assert_equal nil, @im.instance_variable_get(:@message)
|
184
|
+
assert_equal false, @im.instance_variable_get(:@loggedin)
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
def test_new_topic_without_forum_set_should_raise_exception
|
189
|
+
@im.instance_variable_set(:@forum, nil)
|
190
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
191
|
+
@im.new_topic
|
192
|
+
end
|
193
|
+
assert_equal "forum not set", err.original_exception.message
|
194
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
195
|
+
@im.new_topic(f=nil,s="hello world",m="hello world")
|
196
|
+
end
|
197
|
+
assert_equal "forum not set", err.original_exception.message
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_new_topic_without_subject_set_should_raise_exception
|
201
|
+
@im.instance_variable_set(:@forum, 1)
|
202
|
+
@im.instance_variable_set(:@subject, nil)
|
203
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
204
|
+
assert @im.new_topic
|
205
|
+
end
|
206
|
+
assert_equal "topic name not given", err.original_exception.message
|
207
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
208
|
+
@im.new_topic(f=1,s=nil,m="hello world")
|
209
|
+
end
|
210
|
+
assert_equal "topic name not given", err.original_exception.message
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_new_topic_without_message_set_should_raise_exception
|
214
|
+
@im.instance_variable_set(:@forum, 1)
|
215
|
+
@im.instance_variable_set(:@subject, 'test')
|
216
|
+
@im.instance_variable_set(:@message, nil)
|
217
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
218
|
+
@im.new_topic
|
219
|
+
end
|
220
|
+
assert_equal "message not set", err.original_exception.message
|
221
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
222
|
+
@im.new_topic(f=1,s="hello world",m=nil)
|
223
|
+
end
|
224
|
+
assert_equal "message not set", err.original_exception.message
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_new_topic_not_logged_in_should_raise_exception
|
228
|
+
@im.expects(:login).once.returns(false)
|
229
|
+
@im.instance_variable_set(:@loggedin, false)
|
230
|
+
|
231
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
232
|
+
@im.new_topic(f=2,s="hello world",m="hello ruby")
|
233
|
+
end
|
234
|
+
assert_equal "not logged in", err.original_exception.message
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_getting_bad_post_page_for_new_topic_should_raise_exception
|
238
|
+
@im.instance_variable_set(:@loggedin, true)
|
239
|
+
forum = 2
|
240
|
+
posting_page = @im.posting_page
|
241
|
+
posting_page.query = "mode=post&f=#{forum}"
|
242
|
+
errmsg = "from test #{Time.now.to_s}"
|
243
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(
|
244
|
+
posting_page
|
245
|
+
).raises(StandardError, errmsg)
|
246
|
+
|
247
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
248
|
+
@im.new_topic(f=forum,s="hello world",m="hello ruby")
|
249
|
+
end
|
250
|
+
assert_equal errmsg, err.original_exception.message
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_getting_bad_post_form_for_new_topic_should_raise_exception
|
254
|
+
@im.instance_variable_set(:@loggedin, true)
|
255
|
+
response = {'content-type' => 'text/html'}
|
256
|
+
body = '<form action="./posting.php?mode=post&f=37&sid=a56da5e50e92e3f2d8dc14bb8c4936bf" method="post" name="BADPOSTFORM" enctype="multipart/form-data"></form>'
|
257
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
258
|
+
forum = 2
|
259
|
+
posting_page = @im.posting_page
|
260
|
+
posting_page.query = "mode=post&f=#{forum}"
|
261
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
|
262
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
263
|
+
@im.new_topic(f=forum,s="hello world",m="hello ruby")
|
264
|
+
end
|
265
|
+
assert_equal 'post form not found', err.original_exception.message
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_submitting_bad_post_for_new_topic_form_should_raise_exception
|
269
|
+
@im.instance_variable_set(:@loggedin, true)
|
270
|
+
response = {'content-type' => 'text/html'}
|
271
|
+
body = "<html><body>#{phpbb3_good_submit_new_topic_form}</body></html"
|
272
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
273
|
+
forum = 2
|
274
|
+
posting_page = @im.posting_page
|
275
|
+
posting_page.query = "mode=post&f=#{forum}"
|
276
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
|
277
|
+
errmsg = "from test #{Time.now.to_s}"
|
278
|
+
WWW::Mechanize.any_instance.expects(:submit).once.raises(StandardError, errmsg)
|
279
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
280
|
+
@im.new_topic(f=forum,s="hello world",m="hello ruby")
|
281
|
+
end
|
282
|
+
assert_equal errmsg, err.original_exception.message
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_unexpected_viewtopic_for_new_topic_should_raise_exception
|
286
|
+
@im.instance_variable_set(:@loggedin, true)
|
287
|
+
response = {'content-type' => 'text/html'}
|
288
|
+
body = phpbb3_good_submit_new_topic_form
|
289
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
290
|
+
forum = 2
|
291
|
+
posting_page = @im.posting_page
|
292
|
+
posting_page.query = "mode=post&f=#{forum}"
|
293
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
|
294
|
+
WWW::Mechanize.any_instance.expects(:submit).once.returns('JUNK')
|
295
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
296
|
+
@im.new_topic(f=forum,s="hello world",m="hello ruby")
|
297
|
+
end
|
298
|
+
assert_equal "unexpected new topic ID", err.original_exception.message
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_malformed_viewtopic_response_for_new_topic_should_raise_exception
|
302
|
+
@im.instance_variable_set(:@loggedin, true)
|
303
|
+
response = {'content-type' => 'text/html'}
|
304
|
+
body = phpbb3_good_submit_new_topic_form
|
305
|
+
post_page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
306
|
+
forum = 2
|
307
|
+
posting_page = @im.posting_page
|
308
|
+
posting_page.query = "mode=post&f=#{forum}"
|
309
|
+
WWW::Mechanize.any_instance.expects(:get).with(posting_page).returns(post_page)
|
310
|
+
body = "JUNK"
|
311
|
+
#uri = URI.parse("http://localhost/forum/viewtopic.php?f=37&t=205")
|
312
|
+
uri = URI.parse("http://localhost/forum/viewtopic.php?f=2")
|
313
|
+
page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
|
314
|
+
form = post_page.forms.first
|
315
|
+
button = form.buttons.detect{|b| b.name == 'post'}
|
316
|
+
WWW::Mechanize.any_instance.expects(:submit).with(form, button).once.returns(page)
|
317
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
318
|
+
@im.new_topic(f=forum,s="hello world",m="hello ruby")
|
319
|
+
end
|
320
|
+
assert_equal "unexpected new topic ID", err.original_exception.message
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_new_topic_should_work
|
324
|
+
@im.instance_variable_set(:@loggedin, true)
|
325
|
+
response = {'content-type' => 'text/html'}
|
326
|
+
body = phpbb3_good_submit_new_topic_form
|
327
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
328
|
+
forum = 2
|
329
|
+
subject = "hello world"
|
330
|
+
message = "hello ruby"
|
331
|
+
posting_page = @im.posting_page
|
332
|
+
posting_page.query = "mode=post&f=#{forum}"
|
333
|
+
WWW::Mechanize.any_instance.expects(:get).with(posting_page).returns(page)
|
334
|
+
|
335
|
+
body = load_page('phpbb3-post-new_topic-good-response.html').join
|
336
|
+
uri = URI.parse("http://localhost/forum/viewtopic.php?f=2&t=29")
|
337
|
+
page = WWW::Mechanize::Page.new(uri, response, body, code=nil, mech=nil)
|
338
|
+
WWW::Mechanize.any_instance.expects(:submit).once.returns(page)
|
339
|
+
|
340
|
+
@im.expects(:add_subject).once.with(forum,29,subject)
|
341
|
+
assert_equal true, @im.new_topic(f=forum,s=subject,m=message)
|
342
|
+
assert_equal forum, @im.instance_variable_get(:@forum)
|
343
|
+
assert_equal 29, @im.instance_variable_get(:@topic)
|
344
|
+
assert_equal subject, @im.instance_variable_get(:@subject)
|
345
|
+
assert_equal message, @im.instance_variable_get(:@message)
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_posting_page
|
349
|
+
c = config
|
350
|
+
assert_equal URI.join(@app_root, c[:posting_page]), @im.posting_page
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_post_without_forum_set_should_raise_exception
|
354
|
+
@im.instance_variable_set(:@forum, nil)
|
355
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
356
|
+
@im.post
|
357
|
+
end
|
358
|
+
assert_equal "forum not set", err.original_exception.message
|
359
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
360
|
+
@im.post(f=nil,t=nil,m=nil)
|
361
|
+
end
|
362
|
+
assert_equal "forum not set", err.original_exception.message
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_post_without_topic_set_should_raise_exception
|
366
|
+
@im.instance_variable_set(:@forum, 1)
|
367
|
+
@im.instance_variable_set(:@topic, nil)
|
368
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
369
|
+
@im.post
|
370
|
+
end
|
371
|
+
assert_equal "topic not set", err.original_exception.message
|
372
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
373
|
+
@im.post(f=2,t=nil,m=nil)
|
374
|
+
end
|
375
|
+
assert_equal "topic not set", err.original_exception.message
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_post_without_message_set_should_raise_exception
|
379
|
+
@im.instance_variable_set(:@forum, 1)
|
380
|
+
@im.instance_variable_set(:@topic, 1)
|
381
|
+
@im.instance_variable_set(:@message, nil)
|
382
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
383
|
+
@im.post
|
384
|
+
end
|
385
|
+
assert_equal "message not set", err.original_exception.message
|
386
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
387
|
+
@im.post(f=2,t=2,m=nil)
|
388
|
+
end
|
389
|
+
assert_equal "message not set", err.original_exception.message
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_post_not_logged_in_should_raise_exception
|
393
|
+
@im.expects(:login).once.returns(false)
|
394
|
+
@im.instance_variable_set(:@loggedin, false)
|
395
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
396
|
+
@im.post(2,2,'hello')
|
397
|
+
end
|
398
|
+
assert_equal "not logged in", err.original_exception.message
|
399
|
+
end
|
400
|
+
|
401
|
+
def test_bad_post_page_for_post_should_raise_exception
|
402
|
+
@im.instance_variable_set(:@loggedin, true)
|
403
|
+
topic = 1
|
404
|
+
forum = 2
|
405
|
+
posting_page = @im.posting_page
|
406
|
+
posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
|
407
|
+
errmsg = "from test #{Time.now.to_s}"
|
408
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(
|
409
|
+
posting_page
|
410
|
+
).raises(StandardError, errmsg)
|
411
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
412
|
+
@im.post(forum,topic,'hello')
|
413
|
+
end
|
414
|
+
assert_equal errmsg, err.original_exception.message
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_bad_post_form_for_post_should_raise_exception
|
418
|
+
@im.instance_variable_set(:@loggedin, true)
|
419
|
+
response = {'content-type' => 'text/html'}
|
420
|
+
body = '<form action="posting.php" method="post" name="post"></form>'
|
421
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
422
|
+
topic = 2
|
423
|
+
forum = 5
|
424
|
+
posting_page = @im.posting_page
|
425
|
+
posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
|
426
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
|
427
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
428
|
+
@im.post(forum,topic,'hello')
|
429
|
+
end
|
430
|
+
assert_equal "post form not found", err.original_exception.message
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_submitting_bad_post_form_for_post_should_raise_exception
|
434
|
+
@im.instance_variable_set(:@loggedin, true)
|
435
|
+
response = {'content-type' => 'text/html'}
|
436
|
+
body = phpbb3_good_submit_post_form
|
437
|
+
page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
438
|
+
topic = 2
|
439
|
+
forum = 9
|
440
|
+
posting_page = @im.posting_page
|
441
|
+
posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
|
442
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(page)
|
443
|
+
errmsg = "from test #{Time.now.to_s}"
|
444
|
+
WWW::Mechanize.any_instance.expects(:submit).once.raises(StandardError, errmsg)
|
445
|
+
err = assert_raise(WWW::Impostor::PostError) do
|
446
|
+
@im.post(forum,topic,'hello')
|
447
|
+
end
|
448
|
+
assert_equal errmsg, err.original_exception.message
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_should_post
|
452
|
+
@im.instance_variable_set(:@loggedin, true)
|
453
|
+
response = {'content-type' => 'text/html'}
|
454
|
+
body = phpbb3_good_submit_post_form
|
455
|
+
form_page = WWW::Mechanize::Page.new(uri=nil, response, body, code=nil, mech=nil)
|
456
|
+
topic = 2
|
457
|
+
forum = 1
|
458
|
+
posting_page = @im.posting_page
|
459
|
+
posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
|
460
|
+
WWW::Mechanize.any_instance.expects(:get).once.with(posting_page).returns(form_page)
|
461
|
+
form = form_page.forms.first
|
462
|
+
button = form.buttons.detect{|b| b.name == 'post'}
|
463
|
+
body = load_page('phpbb3-post-reply-good-response.html').join
|
464
|
+
posting_page.query = "mode=reply&f=#{forum}&t=#{topic}"
|
465
|
+
page_url = @im.posting_page
|
466
|
+
page_url.path = "/forum/viewtopic.php"
|
467
|
+
page_url.query = "f=#{forum}&t=#{topic}&p=3725"
|
468
|
+
page_url.fragment = "p3725"
|
469
|
+
page = WWW::Mechanize::Page.new(uri=page_url, response, body, code=nil, mech=nil)
|
470
|
+
WWW::Mechanize.any_instance.expects(:submit).with(form, button).once.returns(page)
|
471
|
+
|
472
|
+
subject = "test #{Time.now.to_s}"
|
473
|
+
@im.expects(:get_subject).once.returns(subject)
|
474
|
+
|
475
|
+
assert_equal true, @im.post(1,topic,'hello')
|
476
|
+
assert_equal 1, @im.instance_variable_get(:@forum)
|
477
|
+
assert_equal topic, @im.instance_variable_get(:@topic)
|
478
|
+
assert_equal subject, @im.instance_variable_get(:@subject)
|
479
|
+
assert_equal 'hello', @im.instance_variable_get(:@message)
|
480
|
+
end
|
481
|
+
|
482
|
+
end
|
483
|
+
|
metadata
CHANGED
@@ -1,40 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: impostor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Mondragon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
- |
|
12
|
-
-----BEGIN CERTIFICATE-----
|
13
|
-
MIIDPDCCAiSgAwIBAgIBADANBgkqhkiG9w0BAQUFADBEMRYwFAYDVQQDDA1taWtl
|
14
|
-
bW9uZHJhZ29uMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
|
15
|
-
FgNjb20wHhcNMDcwODI3MTk1NjQ1WhcNMDgwODI2MTk1NjQ1WjBEMRYwFAYDVQQD
|
16
|
-
DA1taWtlbW9uZHJhZ29uMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
|
17
|
-
k/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQD9J/K2
|
18
|
-
wp3uqpMzXOfOlY+zb2qRuP0Q6SaqPf8+Y/OD4n+KR91999nRcd9MED4b9okQb5XF
|
19
|
-
KjbIRtEyXRtX+nmajf3CqrtOe+Gej9Uru1jBiqwdegCipN2HRrqqOX0Tv15o2W6n
|
20
|
-
Lxayxj4JD/DWLrBaKWagv87MCwb0FeKB45Z6bZFA62QM7beBSB9TY+Lv7qpW+uPk
|
21
|
-
vlLC9nj765cU0jZNcddgLZcKVl4AihhA5YNOI6XztxA+DSYze8EryrkES8YjY+O7
|
22
|
-
oPSSvyi/13QnIPpB884/k9alxWqzx3+qQI6UxXeVY1idS9M+1q3QC6vteo5KqE41
|
23
|
-
enZ5Unpw288x+gc5AgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0G
|
24
|
-
A1UdDgQWBBQfSk8NE+/Ad8ZKbEAgwIoKvI5H+TANBgkqhkiG9w0BAQUFAAOCAQEA
|
25
|
-
ZyBadUGUGP/x2pZEIPYVcP9vG0l64wLDksJNVJ90rEgToaQqypCElvipbCXYF9Pe
|
26
|
-
y+5G/bJItH/OKiIHcdJUs8UdXMH5icCpyqNgNopHVkVsE8gghMYm0ptHyKWswRAK
|
27
|
-
6nBO3mw0C2n+KiWdTSXf6HtF9sBg5SV+I/kZEGHbiFEglxfiVoUnlvsCbRt2QlCC
|
28
|
-
uMBzJ1sNVgCL3bqeEZwZj0o2HLxOHg0sSOc16rCfX5yvDo7bFM0XAMvwNgYg8ifQ
|
29
|
-
zeHINowDygx2eefh0hynPGd/QwgANxHpr4+V93KLsyLosIgAIsqoXRkNx3a5gecL
|
30
|
-
q8SfeAt4oNk4pWm9Ocmiww==
|
31
|
-
-----END CERTIFICATE-----
|
10
|
+
cert_chain: []
|
32
11
|
|
33
|
-
date: 2008-
|
12
|
+
date: 2008-07-30 00:00:00 -07:00
|
34
13
|
default_executable:
|
35
14
|
dependencies:
|
36
15
|
- !ruby/object:Gem::Dependency
|
37
16
|
name: hpricot
|
17
|
+
type: :runtime
|
38
18
|
version_requirement:
|
39
19
|
version_requirements: !ruby/object:Gem::Requirement
|
40
20
|
requirements:
|
@@ -44,6 +24,7 @@ dependencies:
|
|
44
24
|
version:
|
45
25
|
- !ruby/object:Gem::Dependency
|
46
26
|
name: mechanize
|
27
|
+
type: :runtime
|
47
28
|
version_requirement:
|
48
29
|
version_requirements: !ruby/object:Gem::Requirement
|
49
30
|
requirements:
|
@@ -53,14 +34,15 @@ dependencies:
|
|
53
34
|
version:
|
54
35
|
- !ruby/object:Gem::Dependency
|
55
36
|
name: hoe
|
37
|
+
type: :development
|
56
38
|
version_requirement:
|
57
39
|
version_requirements: !ruby/object:Gem::Requirement
|
58
40
|
requirements:
|
59
41
|
- - ">="
|
60
42
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
43
|
+
version: 1.7.0
|
62
44
|
version:
|
63
|
-
description: "Makes
|
45
|
+
description: "== FEATURES/PROBLEMS: Makes automated posts to the following forum applications: * Web Wiz Forums (WWF) 7.9 * Web Wiz Forums (WWF) 8.0 * PHP Bullitin Board (phpBB) 2.0 (2.0.22) * PHP Bullitin Board (phpBB) 3.0 == SYNOPSIS:"
|
64
46
|
email: mikemondragon@gmail.com
|
65
47
|
executables: []
|
66
48
|
|
@@ -78,6 +60,7 @@ files:
|
|
78
60
|
- lib/impostor.rb
|
79
61
|
- lib/www/impostor.rb
|
80
62
|
- lib/www/impostor/phpbb2.rb
|
63
|
+
- lib/www/impostor/phpbb3.rb
|
81
64
|
- lib/www/impostor/wwf79.rb
|
82
65
|
- lib/www/impostor/wwf80.rb
|
83
66
|
- test/fixtures/phpbb2-get-new_topic-form-good-response.html
|
@@ -91,6 +74,13 @@ files:
|
|
91
74
|
- test/fixtures/phpbb2-post-reply-good-response.html
|
92
75
|
- test/fixtures/phpbb2-post-reply-throttled-response.html
|
93
76
|
- test/fixtures/phpbb2-too-many-posts.html
|
77
|
+
- test/fixtures/phpbb3-get-new-topic-form-good-response.html
|
78
|
+
- test/fixtures/phpbb3-get-reply-form-good-response.html
|
79
|
+
- test/fixtures/phpbb3-logged-in.html
|
80
|
+
- test/fixtures/phpbb3-login.html
|
81
|
+
- test/fixtures/phpbb3-not-logged-in.html
|
82
|
+
- test/fixtures/phpbb3-post-new_topic-good-response.html
|
83
|
+
- test/fixtures/phpbb3-post-reply-good-response.html
|
94
84
|
- test/fixtures/wwf79-forum_posts.html
|
95
85
|
- test/fixtures/wwf79-general-new-topic-error.html
|
96
86
|
- test/fixtures/wwf79-general-posting-error.html
|
@@ -117,6 +107,7 @@ files:
|
|
117
107
|
- test/test_helper.rb
|
118
108
|
- test/test_www_impostor.rb
|
119
109
|
- test/test_www_impostor_phpbb2.rb
|
110
|
+
- test/test_www_impostor_phpbb3.rb
|
120
111
|
- test/test_www_impostor_wwf79.rb
|
121
112
|
- test/test_www_impostor_wwf80.rb
|
122
113
|
- vendor/plugins/impostor/lib/autotest/discover.rb
|
@@ -144,12 +135,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
135
|
requirements: []
|
145
136
|
|
146
137
|
rubyforge_project: impostor
|
147
|
-
rubygems_version: 1.0
|
138
|
+
rubygems_version: 1.2.0
|
148
139
|
signing_key:
|
149
140
|
specification_version: 2
|
150
141
|
summary: imPOSTor posts messages to non-RESTful forums and blogs
|
151
142
|
test_files:
|
152
143
|
- test/test_www_impostor_phpbb2.rb
|
144
|
+
- test/test_www_impostor_phpbb3.rb
|
153
145
|
- test/test_www_impostor_wwf79.rb
|
154
146
|
- test/test_www_impostor_wwf80.rb
|
155
147
|
- test/test_helper.rb
|
data.tar.gz.sig
DELETED
metadata.gz.sig
DELETED