impostor 0.2.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +17 -0
  6. data/Gemfile.lock +47 -0
  7. data/History.txt +8 -0
  8. data/Manifest.txt +87 -55
  9. data/README.txt +11 -11
  10. data/Rakefile +16 -20
  11. data/lib/impostor/auth.rb +103 -0
  12. data/lib/impostor/config.rb +171 -0
  13. data/lib/impostor/errors.rb +67 -0
  14. data/lib/impostor/phpbb2.rb +202 -0
  15. data/lib/impostor/phpbb3.rb +199 -0
  16. data/lib/impostor/post.rb +111 -0
  17. data/lib/impostor/topic.rb +115 -0
  18. data/lib/impostor/wwf79.rb +186 -0
  19. data/lib/impostor/wwf80.rb +190 -0
  20. data/lib/impostor.rb +108 -5
  21. data/spec/auth_spec.rb +148 -0
  22. data/spec/base_spec_helper.rb +12 -0
  23. data/{test/test_helper.rb → spec/caged_net_http.rb} +8 -17
  24. data/spec/config_spec.rb +136 -0
  25. data/spec/fixtures/junk.html +1 -0
  26. data/{test → spec}/fixtures/phpbb2-get-new_topic-form-good-response.html +0 -0
  27. data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-good-response.html +11 -11
  28. data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-malformed-response.html +0 -0
  29. data/{test → spec}/fixtures/phpbb2-index.html +0 -0
  30. data/{test → spec}/fixtures/phpbb2-logged-in.html +0 -0
  31. data/{test → spec}/fixtures/phpbb2-login.html +0 -0
  32. data/{test → spec}/fixtures/phpbb2-not-logged-in.html +0 -0
  33. data/{test → spec}/fixtures/phpbb2-post-new_topic-good-response.html +0 -0
  34. data/{test → spec}/fixtures/phpbb2-post-reply-good-response.html +0 -0
  35. data/{test → spec}/fixtures/phpbb2-post-reply-throttled-response.html +0 -0
  36. data/{test → spec}/fixtures/phpbb2-too-many-posts.html +0 -0
  37. data/{test → spec}/fixtures/phpbb3-get-new-topic-form-good-response.html +0 -0
  38. data/{test → spec}/fixtures/phpbb3-get-reply-form-good-response.html +0 -0
  39. data/{test → spec}/fixtures/phpbb3-logged-in.html +0 -0
  40. data/{test → spec}/fixtures/phpbb3-login.html +0 -0
  41. data/{test → spec}/fixtures/phpbb3-not-logged-in.html +0 -0
  42. data/{test → spec}/fixtures/phpbb3-post-new_topic-good-response.html +0 -0
  43. data/{test → spec}/fixtures/phpbb3-post-reply-good-response.html +0 -0
  44. data/spec/fixtures/vcr_cassettes/phpbb2-should-be-overlimit-creating-topic.yml +1308 -0
  45. data/spec/fixtures/vcr_cassettes/phpbb2-should-create-topic.yml +923 -0
  46. data/spec/fixtures/vcr_cassettes/phpbb2-should-login.yml +360 -0
  47. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-create-new-topic.yml +497 -0
  48. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-login.yml +287 -0
  49. data/spec/fixtures/vcr_cassettes/phpbb2-should-not-post.yml +497 -0
  50. data/spec/fixtures/vcr_cassettes/phpbb2-should-overlimit-error-post.yml +1140 -0
  51. data/spec/fixtures/vcr_cassettes/phpbb2-should-post.yml +751 -0
  52. data/spec/fixtures/vcr_cassettes/phpbb3-should-be-overlimit-creating-topic.yml +995 -0
  53. data/spec/fixtures/vcr_cassettes/phpbb3-should-create-topic.yml +675 -0
  54. data/spec/fixtures/vcr_cassettes/phpbb3-should-login.yml +245 -0
  55. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-create-new-topic.yml +350 -0
  56. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-login.yml +253 -0
  57. data/spec/fixtures/vcr_cassettes/phpbb3-should-not-post.yml +350 -0
  58. data/spec/fixtures/vcr_cassettes/phpbb3-should-overlimit-error-post.yml +1046 -0
  59. data/spec/fixtures/vcr_cassettes/phpbb3-should-post.yml +605 -0
  60. data/{test → spec}/fixtures/wwf79-forum_posts.html +0 -0
  61. data/{test → spec}/fixtures/wwf79-general-new-topic-error.html +0 -0
  62. data/{test → spec}/fixtures/wwf79-general-posting-error.html +0 -0
  63. data/{test → spec}/fixtures/wwf79-good-post-forum_posts.html +1 -1
  64. data/{test → spec}/fixtures/wwf79-index.html +0 -0
  65. data/{test → spec}/fixtures/wwf79-logged-in.html +0 -0
  66. data/{test → spec}/fixtures/wwf79-login.html +0 -0
  67. data/{test → spec}/fixtures/wwf79-new-topic-forum_posts-response.html +0 -0
  68. data/{test → spec}/fixtures/wwf79-new-topic-post_message_form.html +0 -0
  69. data/{test → spec}/fixtures/wwf79-not-logged-in.html +0 -0
  70. data/{test → spec}/fixtures/wwf79-too-many-posts.html +0 -0
  71. data/{test → spec}/fixtures/wwf79-too-many-topics.html +0 -0
  72. data/{test → spec}/fixtures/wwf80-general-posting-error.html +0 -0
  73. data/{test → spec}/fixtures/wwf80-get-new_topic-form-good-response.html +0 -0
  74. data/{test → spec}/fixtures/wwf80-get-viewtopic-for-new-topic-good-response.html +0 -0
  75. data/{test → spec}/fixtures/wwf80-index.html +0 -0
  76. data/{test → spec}/fixtures/wwf80-logged-in.html +0 -0
  77. data/{test → spec}/fixtures/wwf80-login.html +0 -0
  78. data/{test → spec}/fixtures/wwf80-new_reply_form.html +0 -0
  79. data/{test → spec}/fixtures/wwf80-not-logged-in.html +0 -0
  80. data/{test → spec}/fixtures/wwf80-post-new_topic-good-response.html +1 -1
  81. data/{test → spec}/fixtures/wwf80-post-reply-good-response.html +0 -0
  82. data/{test → spec}/fixtures/wwf80-too-many-posts.html +0 -0
  83. data/spec/impostor_spec_helper.rb +162 -0
  84. data/spec/integration/phpbb2_spec.rb +111 -0
  85. data/spec/integration/phpbb3_spec.rb +109 -0
  86. data/spec/integration_spec_helper.rb +7 -0
  87. data/spec/phpbb2_spec.rb +346 -0
  88. data/spec/phpbb3_spec.rb +332 -0
  89. data/spec/post_spec.rb +134 -0
  90. data/spec/spec_helper.rb +2 -0
  91. data/spec/test_impostor.rb +12 -0
  92. data/spec/topic_spec.rb +143 -0
  93. data/spec/wwf79_spec.rb +342 -0
  94. data/spec/wwf80_spec.rb +339 -0
  95. metadata +156 -87
  96. data/lib/www/impostor/phpbb2.rb +0 -258
  97. data/lib/www/impostor/phpbb3.rb +0 -236
  98. data/lib/www/impostor/wwf79.rb +0 -254
  99. data/lib/www/impostor/wwf80.rb +0 -264
  100. data/lib/www/impostor.rb +0 -269
  101. data/test/test_github.rb +0 -12
  102. data/test/test_www_impostor.rb +0 -165
  103. data/test/test_www_impostor_phpbb2.rb +0 -536
  104. data/test/test_www_impostor_phpbb3.rb +0 -483
  105. data/test/test_www_impostor_wwf79.rb +0 -535
  106. data/test/test_www_impostor_wwf80.rb +0 -535
  107. data/vendor/plugins/impostor/lib/autotest/discover.rb +0 -3
  108. data/vendor/plugins/impostor/lib/autotest/impostor.rb +0 -49
@@ -1,254 +0,0 @@
1
- require 'rubygems'
2
- require 'hpricot'
3
- gem 'mechanize', '>= 0.7.0'
4
- require 'mechanize'
5
- require 'cgi'
6
-
7
- ##
8
- # Web Wiz Forums version 7.9 of the Impostor
9
- #
10
-
11
- class WWW::Impostor
12
-
13
- class Wwf79 < WWW::Impostor
14
-
15
- ##
16
- # After initializing the parent a mechanize agent is created
17
- #
18
- # Additional configuration parameters:
19
- #
20
- # :forum_posts_page
21
- # :post_message_page
22
- #
23
- # Typical configuration parameters
24
- # { :type => :wwf79,
25
- # :app_root => 'http://example.com/forum/',
26
- # :login_page => 'login_user.asp',
27
- # :forum_posts_page => 'forum_posts.asp',
28
- # :post_message_page => 'post_message_form.asp'
29
- # :user_agent => 'Windows IE 7',
30
- # :username => 'myuser',
31
- # :password => 'mypasswd' }
32
-
33
- def initialize(config={})
34
- super(config)
35
- @agent = WWW::Mechanize.new
36
- @agent.user_agent_alias = user_agent
37
- @agent.cookie_jar.load(cookie_jar) if cookie_jar && File.exist?(cookie_jar)
38
- @message = nil
39
- @loggedin = false
40
- end
41
-
42
- ##
43
- # clean up the state of the library and log out
44
-
45
- def logout
46
- return false unless @loggedin
47
-
48
- @agent.cookie_jar.save_as(cookie_jar) if cookie_jar
49
- save_topics
50
-
51
- @forum = nil
52
- @topic = nil
53
- @message = nil
54
-
55
- @loggedin = false
56
- true
57
- end
58
-
59
- ##
60
- # create a new topic
61
-
62
- def new_topic(forum=@forum, subject=@subject, message=@message)
63
- raise PostError.new("forum not set") unless forum
64
- raise PostError.new("topic name not given") unless subject
65
- raise PostError.new("message not set") unless message
66
-
67
- login
68
- raise PostError.new("not logged in") unless @loggedin
69
-
70
- uri = post_message_page
71
- uri.query = "FID=#{forum}"
72
-
73
- # get the submit form
74
- begin
75
- page = @agent.get(uri)
76
- rescue StandardError => err
77
- raise PostError.new(err)
78
- end
79
- form = page.form('frmAddMessage') rescue nil
80
- button = form.buttons.with.name('Submit').first rescue nil
81
- raise PostError.new("post form not found") unless button && form
82
-
83
- # set up the form and submit it
84
- form.subject = subject
85
- form.message = message
86
- begin
87
- page = @agent.submit(form, button)
88
- rescue StandardError => err
89
- raise PostError.new(err)
90
- end
91
-
92
- error = page.body =~ /Message Not Posted/
93
- if error
94
-
95
- # throttled
96
- throttled = "You have exceeded the number of posts permitted in the time span"
97
- too_many = page.body =~ /#{throttled}/
98
- raise ThrottledError.new(throttled) if too_many
99
-
100
- # general error
101
- raise PostError.new("There was an error creating the topic")
102
- end
103
-
104
- # look up the new topic id
105
- form = page.form('frmAddMessage') rescue nil
106
- topic = form['TID'].to_i rescue 0
107
- raise PostError.new('unexpected new topic ID') if topic < 1
108
-
109
- # save new topic id and topic name
110
- add_subject(forum, topic, subject)
111
- @forum=forum; @topic=topic; @subject=subject; @message=message
112
- return true
113
- end
114
-
115
- ##
116
- # Attempt to post to the forum
117
-
118
- def post(forum = @forum, topic = @topic, message = @message)
119
- raise PostError.new("forum not set") unless forum
120
- raise PostError.new("topic not set") unless topic
121
- raise PostError.new("message not set") unless message
122
-
123
- login
124
- raise PostError.new("not logged in") unless @loggedin
125
-
126
- uri = forum_posts_page
127
- uri.query = "TID=#{topic}&TPN=10000"
128
-
129
- # get the submit form
130
- begin
131
- page = @agent.get(uri)
132
- rescue StandardError => err
133
- raise PostError.new(err)
134
- end
135
- form = page.form('frmAddMessage') rescue nil
136
- button = form.buttons.with.name('Submit').first rescue nil
137
- raise PostError.new("post form not found") unless button && form
138
-
139
- # set up the form and submit it
140
- form.message = message
141
- begin
142
- page = @agent.submit(form, button)
143
- rescue StandardError => err
144
- raise PostError.new(err)
145
- end
146
-
147
- error = page.body =~ /Message Not Posted/
148
- if error
149
-
150
- # throttled
151
- throttled = "You have exceeded the number of posts permitted in the time span"
152
- too_many = page.body =~ /#{throttled}/
153
- raise ThrottledError.new(throttled) if too_many
154
-
155
- # general error
156
- raise PostError.new("There was an error making the post")
157
- end
158
-
159
- @forum=forum; @topic=topic; @subject=get_subject(forum,topic); @message=message
160
- return true
161
- end
162
-
163
- ##
164
- # Get the new posts page for the application (specific to WWF7.9)
165
-
166
- def forum_posts_page
167
- URI.join(app_root, config[:forum_posts_page])
168
- end
169
-
170
- ##
171
- # Get the new topic page for the application (specific to WWF7.9)
172
-
173
- def post_message_page
174
- URI.join(app_root, config[:post_message_page])
175
- end
176
-
177
- ##
178
- # does the work of logging into WWF 7.9
179
-
180
- def login
181
- return true if @loggedin
182
-
183
- # get the login page
184
- page = fetch_login_page
185
-
186
- # return if we are already logged in from a cookie state
187
- return true if logged_in?(page)
188
-
189
- # setup the form and submit
190
- form, button = login_form_and_button(page)
191
- page = post_login(form, button)
192
-
193
- # set up the rest of the state if we are logged in
194
- @loggedin = logged_in?(page)
195
- load_topics if @loggedin
196
-
197
- @loggedin
198
- end
199
-
200
- def version
201
- @version ||= self.class.to_s
202
- end
203
-
204
- protected
205
-
206
- ##
207
- # does the work of posting the login form
208
-
209
- def post_login(form, button)
210
- begin
211
- page = @agent.submit(form, button)
212
- rescue StandardError => err
213
- raise LoginError.new(err)
214
- end
215
- end
216
-
217
- ##
218
- # returns the login form and its button from the login page
219
-
220
- def login_form_and_button(page)
221
- form = page.forms.with.name('frmLogin').first rescue nil
222
- raise LoginError.new("unknown login page format") unless form
223
-
224
- button = WWW::Mechanize::Form::Button.new('Submit', 'Forum Login')
225
- form.add_button_to_query(button)
226
- form['name'] = username
227
- form['password'] = password
228
- return form, button
229
- end
230
-
231
- ##
232
- # fetches the login page
233
-
234
- def fetch_login_page
235
- begin
236
- page = @agent.get(login_page)
237
- rescue StandardError => err
238
- raise LoginError.new(err)
239
- end
240
- end
241
-
242
- ##
243
- # Checks if the agent is already logged by stored cookie
244
-
245
- def logged_in?(page)
246
- mm = page.search("//a[@class='nav']")
247
- return false unless mm
248
- mm.each do |m|
249
- return true if (m.innerText =~ /Logout \[#{username}\]/ rescue false)
250
- end
251
- false
252
- end
253
- end
254
- end
@@ -1,264 +0,0 @@
1
- require 'rubygems'
2
- require 'hpricot'
3
- gem 'mechanize', '>= 0.7.0'
4
- require 'mechanize'
5
- require 'cgi'
6
-
7
- ##
8
- # Web Wiz Forums version 8.0 of the Impostor
9
- #
10
-
11
- class WWW::Impostor
12
-
13
- class Wwf80 < WWW::Impostor
14
-
15
- ##
16
- # After initializing the parent a mechanize agent is created
17
- #
18
- # Additional configuration parameters:
19
- #
20
- # :new_reply_page
21
- # :new_topic_page
22
- #
23
- # Typical configuration parameters
24
- # { :type => :wwf80,
25
- # :app_root => 'http://example.com/forum/',
26
- # :login_page => 'login_user.asp',
27
- # :new_reply_page => 'new_reply_form.asp',
28
- # :new_topic_page => 'new_topic_form.asp',
29
- # :user_agent => 'Windows IE 7',
30
- # :username => 'myuser',
31
- # :password => 'mypasswd' }
32
-
33
- def initialize(config={})
34
- super(config)
35
- @agent = WWW::Mechanize.new
36
- @agent.user_agent_alias = user_agent
37
- # jar is a yaml file
38
- @agent.cookie_jar.load(cookie_jar) if cookie_jar && File.exist?(cookie_jar)
39
- @message = nil
40
- @loggedin = false
41
- end
42
-
43
- ##
44
- # clean up the state of the library and log out
45
-
46
- def logout
47
- return false unless @loggedin
48
-
49
- @agent.cookie_jar.save_as(cookie_jar) if cookie_jar
50
- save_topics
51
-
52
- @forum = nil
53
- @topic = nil
54
- @message = nil
55
-
56
- @loggedin = false
57
- true
58
- end
59
-
60
- def new_topic(forum=@forum, subject=@subject, message=@message)
61
- raise PostError.new("forum not set") unless forum
62
- raise PostError.new("topic name not given") unless subject
63
- raise PostError.new("message not set") unless message
64
-
65
- login
66
- raise PostError.new("not logged in") unless @loggedin
67
-
68
- uri = new_topic_page
69
- uri.query = "FID=#{forum}"
70
-
71
- # get the submit form
72
- begin
73
- page = @agent.get(uri)
74
- rescue StandardError => err
75
- raise PostError.new(err)
76
- end
77
- form = page.form('frmMessageForm') rescue nil
78
- button = form.buttons.with.name('Submit').first rescue nil
79
- raise PostError.new("post form not found") unless button && form
80
-
81
- # set up the form and submit it
82
- form.subject = subject
83
- form.message = message
84
- begin
85
- page = @agent.submit(form, button)
86
- rescue StandardError => err
87
- raise PostError.new(err)
88
- end
89
-
90
- error = page.search("//table[@class='errorTable']")
91
- if error
92
- msgs = error.search("//td")
93
-
94
- # throttled
95
- too_many = (msgs.last.innerText =~
96
- /You have exceeded the number of posts permitted in the time span/ rescue
97
- false)
98
- raise ThrottledError.new(msgs.last.innerText.gsub(/\s+/m,' ').strip) if too_many
99
-
100
- # general error
101
- had_error = (error.last.innerText =~
102
- /Error: Message Not Posted/ rescue
103
- false)
104
- raise PostError.new(error.last.innerText.gsub(/\s+/m,' ').strip) if had_error
105
- end
106
-
107
- # look up the new topic id
108
- form = page.form('frmMessageForm') rescue nil
109
- topic = form['TID'].to_i rescue 0
110
- raise PostError.new('unexpected new topic ID') if topic < 1
111
-
112
- # save new topic id and topic name
113
- add_subject(forum, topic, subject)
114
-
115
- @forum=forum; @topic=topic; @subject=subject; @message=message
116
- return true
117
- end
118
-
119
- ##
120
- # Attempt to post to the forum
121
-
122
- def post(forum = @forum, topic = @topic, message = @message)
123
- raise PostError.new("forum not set") unless forum
124
- raise PostError.new("topic not set") unless topic
125
- raise PostError.new("message not set") unless message
126
-
127
- login
128
- raise PostError.new("not logged in") unless @loggedin
129
-
130
- uri = new_reply_page
131
- uri.query = "TID=#{topic}"
132
-
133
- # get the submit form
134
- begin
135
- page = @agent.get(uri)
136
- rescue StandardError => err
137
- raise PostError.new(err)
138
- end
139
-
140
- form = page.form('frmMessageForm') rescue nil
141
- button = form.buttons.with.name('Submit').first rescue nil
142
- raise PostError.new("post form not found") unless button && form
143
-
144
- # set up the form and submit it
145
- form.message = message
146
- begin
147
- page = @agent.submit(form, button)
148
- rescue StandardError => err
149
- raise PostError.new(err)
150
- end
151
-
152
- error = page.search("//table[@class='errorTable']")
153
- if error
154
- msgs = error.search("//td")
155
-
156
- # throttled
157
- too_many = (msgs.last.innerText =~
158
- /You have exceeded the number of posts permitted in the time span/ rescue
159
- false)
160
- raise ThrottledError.new(msgs.last.innerText.gsub(/\s+/m,' ').strip) if too_many
161
-
162
- # general error
163
- had_error = (error.last.innerText =~
164
- /Error: Message Not Posted/ rescue
165
- false)
166
- raise PostError.new(error.last.innerText.gsub(/\s+/m,' ').strip) if had_error
167
- end
168
-
169
- @forum=forum; @topic=topic; @subject=get_subject(forum,topic); @message=message
170
- return true
171
- end
172
-
173
- ##
174
- # Get the new reply page for the application (specific to WWF8.0)
175
-
176
- def new_reply_page
177
- URI.join(app_root, config[:new_reply_page])
178
- end
179
-
180
- ##
181
- # Get the new topic page for the application (specific to WWF8.0)
182
-
183
- def new_topic_page
184
- URI.join(app_root, config[:new_topic_page])
185
- end
186
-
187
- ##
188
- # does the work of logging into WWF 8.0
189
-
190
- def login
191
- return true if @loggedin
192
-
193
- # get the login page
194
- page = fetch_login_page
195
-
196
- # return if we are already logged in from a cookie state
197
- return true if logged_in?(page)
198
-
199
- # setup the form and submit
200
- form, button = login_form_and_button(page)
201
- page = post_login(form, button)
202
-
203
- # set up the rest of the state if we are logged in
204
- @loggedin = logged_in?(page)
205
- load_topics if @loggedin
206
-
207
- @loggedin
208
- end
209
-
210
- def version
211
- @version ||= self.class.to_s
212
- end
213
-
214
- protected
215
-
216
- ##
217
- # does the work of posting the login form
218
-
219
- def post_login(form, button)
220
- begin
221
- page = @agent.submit(form, button)
222
- rescue StandardError => err
223
- raise LoginError.new(err)
224
- end
225
- end
226
-
227
- ##
228
- # returns the login form and its button from the login page
229
-
230
- def login_form_and_button(page)
231
- form = page.forms.with.name('frmLogin').first rescue nil
232
- raise LoginError.new("unknown login page format") unless form
233
-
234
- button = form.buttons.with.name('Submit').first
235
- form['name'] = username
236
- form['password'] = password
237
-
238
- return form, button
239
- end
240
-
241
- ##
242
- # fetches the login page
243
-
244
- def fetch_login_page
245
- begin
246
- page = @agent.get(login_page)
247
- rescue StandardError => err
248
- raise LoginError.new(err)
249
- end
250
- end
251
-
252
- ##
253
- # Checks if the agent is already logged by stored cookie
254
-
255
- def logged_in?(page)
256
- mm = page.search("//a[@class='nav']")
257
- return false unless mm
258
- mm.each do |m|
259
- return true if (m.innerText =~ /Logout \[#{username}\]/ rescue false)
260
- end
261
- false
262
- end
263
- end
264
- end