wsoc 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
@@ -1,4 +1,2 @@
1
- �~v��&����@�F`�6w�#p1Qf�&�3�X�.�E�CԧTh�
2
- &F�^���MF��,���!�ēe:c<�yo*~��*5�
3
- �6S����.�qbO�%��&<5���0>lp�����6�A���8�h�n���'�W��m<!X��i������B-����Y��ד.�Rf�^p���WQ��6"J,��5U͋��v��gK��6��q��� k�*X�ٞx�����Q=&�\�u����l���b�c*׈
4
-
1
+ ���
2
+ ����B�����6�gt5�
data/History.rdoc CHANGED
@@ -1,3 +1,15 @@
1
+ === 0.1.1 / 2010-01-06
2
+
3
+ * Added WSOC::Specs.metadata.
4
+ * Added WSOC::Specs.config.
5
+ * Added {WSOC::Helpers::Authentication}.
6
+ * Added a failing link to <tt>/course/remote/start.html</tt> with a bad TLD.
7
+ * Added a failing link to <tt>/course/remote/start.html</tt> with the bad
8
+ IP address +191.255.0.0+.
9
+ * Added <tt>/course/auth</tt> for testing spidering of HTTP Basic
10
+ Auth protected pages.
11
+ * Added auth store information to the metadata within the specs.
12
+
1
13
  === 0.1.0 / 2010-01-02
2
14
 
3
15
  * Initial release:
data/Manifest.txt CHANGED
@@ -11,6 +11,7 @@ lib/wsoc/specs.rb
11
11
  lib/wsoc/course_specs.rb
12
12
  lib/wsoc/helpers.rb
13
13
  lib/wsoc/helpers/rendering.rb
14
+ lib/wsoc/helpers/authentication.rb
14
15
  lib/wsoc/helpers/course.rb
15
16
  lib/wsoc/course.rb
16
17
  lib/wsoc/app.rb
@@ -39,4 +40,5 @@ views/course_remote_next.erb
39
40
  views/course_cookies_start.erb
40
41
  views/course_cookies_get.erb
41
42
  views/course_redirects_start.erb
43
+ views/course_auth_start.erb
42
44
  views/welcome.erb
data/README.rdoc CHANGED
@@ -22,7 +22,9 @@ the thoroughness and resilience of Web Spiders.
22
22
  * Remote links.
23
23
  * <tt>javascript:</tt> links.
24
24
  * Links within +frameset+ and +iframe+ tags.
25
+ * Cookie protected pages.
25
26
  * HTTP 300, 301, 302, 303 and 307 Redirects.
27
+ * HTTP Baisc Auth protected pages.
26
28
 
27
29
  == SYNOPSIS:
28
30
 
data/lib/wsoc/app.rb CHANGED
@@ -37,7 +37,7 @@ module WSOC
37
37
  end
38
38
 
39
39
  get '/specs' do
40
- @specs = specs
40
+ @specs = specs[:specs]
41
41
 
42
42
  show :specs
43
43
  end
@@ -125,23 +125,22 @@ module WSOC
125
125
  course_page :course_cookies_get
126
126
  end
127
127
 
128
- get '/course/cookies/post.html' do
129
- response.set_cookie 'auth_level', '2'
128
+ course_pass '/course/cookies/protected.html'
130
129
 
131
- course_page :course_cookies_post
130
+ get '/course/auth/start.html' do
131
+ protected! do
132
+ course_page :course_auth_start
133
+ end
132
134
  end
133
135
 
134
- post '/course/cookies/post.html' do
135
- @authed = (request.cookies['auth_level'] == '2')
136
-
137
- course_page :course_cookies_post
136
+ get '/course/auth/protected.html' do
137
+ protected! do
138
+ course_page :course_pass
139
+ end
138
140
  end
139
141
 
140
- course_pass '/course/cookies/protected/1.html'
141
-
142
142
  get '/*' do
143
143
  redirect remote_url('/course/fail')
144
144
  end
145
-
146
145
  end
147
146
  end
data/lib/wsoc/config.rb CHANGED
@@ -42,5 +42,9 @@ module WSOC
42
42
 
43
43
  # Path to the course failure page
44
44
  COURSE_FAIL_PATH = "#{COURSE_DIR}/fail"
45
+
46
+ # HTTP Basic Auth credential data
47
+ COURSE_AUTH_USER = 'admin'
48
+ COURSE_AUTH_PASSWORD = 'password'
45
49
  end
46
50
  end
@@ -19,6 +19,7 @@
19
19
  #
20
20
 
21
21
  require 'wsoc/specs'
22
+ require 'wsoc/config'
22
23
 
23
24
  module WSOC
24
25
  module CourseSpecs
@@ -86,7 +87,11 @@ module WSOC
86
87
  'should visit normal remote links'
87
88
  should_fail 'http://spidr.rubyforge.org:1337/course/remote/fail.html',
88
89
  'should safely fail on closed ports'
89
- should_fail 'http://not.found/course/remote/fail.html',
90
+ should_fail 'http://191.255.0.0/course/remote/fail.html',
91
+ 'should safely fail on unreachable IP Addresses'
92
+ should_fail 'http://bad.tld/course/remote/fail.html',
93
+ 'should safely fail on host-names with invalid TLDs'
94
+ should_fail 'http://bad.url.lol.com/course/remote/fail.html',
90
95
  'should safely fail on bad host-names'
91
96
 
92
97
  # Cookies
@@ -94,7 +99,7 @@ module WSOC
94
99
  'should visit the cookies start page'
95
100
  should_visit '/course/cookies/get.html',
96
101
  'should visit the cookies GET request test page'
97
- should_visit '/course/cookies/protected/1.html',
102
+ should_visit '/course/cookies/protected.html',
98
103
  'should visit the first cookie protected page'
99
104
 
100
105
  # HTTP Redirects
@@ -120,5 +125,18 @@ module WSOC
120
125
  'should visit the 307 HTTP redirect test page'
121
126
  should_visit '/course/redirects/307/pass.html',
122
127
  'should follow HTTP 307 redirects'
128
+
129
+ config :auth_store, {
130
+ '/course/auth/' => {
131
+ :user, Config::COURSE_AUTH_USER,
132
+ :password, Config::COURSE_AUTH_PASSWORD
133
+ }
134
+ }
135
+
136
+ # HTTP Auth
137
+ should_visit '/course/auth/start.html',
138
+ 'should visit the HTTP Auth start page'
139
+ should_visit '/course/auth/protected.html',
140
+ 'should visit the HTTP Auth protected page'
123
141
  end
124
142
  end
data/lib/wsoc/helpers.rb CHANGED
@@ -18,8 +18,9 @@
18
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  #
20
20
 
21
- require 'wsoc/helpers/course'
21
+ require 'wsoc/helpers/authentication'
22
22
  require 'wsoc/helpers/rendering'
23
+ require 'wsoc/helpers/course'
23
24
 
24
25
  require 'rack'
25
26
 
@@ -28,6 +29,7 @@ module WSOC
28
29
  include Rack::Utils
29
30
  alias :h :escape_html
30
31
 
32
+ include Authentication
31
33
  include Rendering
32
34
  include Course
33
35
  end
@@ -0,0 +1,64 @@
1
+ #
2
+ # WSOC - The Web Spider Obstacle Course
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ module WSOC
22
+ module Helpers
23
+ module Authentication
24
+
25
+ #
26
+ # Protects an action by requiring HTTP Basic Access Authentication.
27
+ #
28
+ # @yield []
29
+ # If a block is given, it will be called if the client is
30
+ # authenticated.
31
+ #
32
+ # @since 0.1.1
33
+ #
34
+ def protected!(&block)
35
+ if authorized?
36
+ block.call() if block
37
+ else
38
+ response['WWW-Authenticate'] = %(Basic realm="HTTP Auth Test")
39
+ throw :halt, [401, "Not authorized\n"]
40
+ end
41
+ end
42
+
43
+ #
44
+ # Checks to see if the requesting user is authorized.
45
+ #
46
+ # @return [Boolean]
47
+ # Specifies whether or not the client is authenticated.
48
+ #
49
+ # @since 0.1.1
50
+ #
51
+ def authorized?
52
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
53
+
54
+ @auth.provided? && \
55
+ @auth.basic? && \
56
+ @auth.credentials && \
57
+ @auth.credentials == [
58
+ WSOC::Config::COURSE_AUTH_USER,
59
+ WSOC::Config::COURSE_AUTH_PASSWORD
60
+ ]
61
+ end
62
+ end
63
+ end
64
+ end
@@ -141,7 +141,7 @@ module WSOC
141
141
  # @since 0.1.0
142
142
  #
143
143
  def specs
144
- CourseSpecs.specs_for(request.host,request.port)
144
+ CourseSpecs.map(request.host,request.port)
145
145
  end
146
146
  end
147
147
  end
data/lib/wsoc/specs.rb CHANGED
@@ -22,29 +22,44 @@ module WSOC
22
22
  module Specs
23
23
  def self.included(base)
24
24
  base.module_eval do
25
+ def self.hash
26
+ @@specs_hash ||= {}
27
+ end
28
+
25
29
  def self.specs
26
- @@specs ||= []
30
+ self.hash[:specs] ||= []
31
+ end
32
+
33
+ def self.metadata
34
+ self.hash[:metadata] ||= {}
27
35
  end
28
36
 
29
37
  def self.should(behavior,options)
30
38
  self.specs << {:behavior => behavior}.merge(options)
31
39
  end
32
40
 
33
- def self.specs_for(host,port=nil)
41
+ def self.map(host,port=nil)
34
42
  prefix = "http://#{host}"
35
43
  prefix << ":#{port}" if (port && port != 80)
36
44
 
37
- self.specs.map do |spec|
38
- unless spec[:url] =~ /^[a-zA-Z0-9]+:/
39
- spec.merge(:url => prefix + spec[:url])
40
- else
41
- spec
42
- end
43
- end
45
+ return {
46
+ :metadata => self.metadata,
47
+ :specs => self.specs.map { |spec|
48
+ unless spec[:url] =~ /^[a-zA-Z0-9]+:/
49
+ spec.merge(:url => prefix + spec[:url])
50
+ else
51
+ spec
52
+ end
53
+ }
54
+ }
44
55
  end
45
56
 
46
57
  protected
47
58
 
59
+ def self.config(name,value)
60
+ self.metadata[name.to_sym] = value
61
+ end
62
+
48
63
  def self.should_visit(url,message=nil)
49
64
  self.should(:visit,:url => url, :message => message)
50
65
  end
data/lib/wsoc/version.rb CHANGED
@@ -20,5 +20,5 @@
20
20
 
21
21
  module WSOC
22
22
  # wsoc version
23
- VERSION = '0.1.0'
23
+ VERSION = '0.1.1'
24
24
  end
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <title><%= title_for 'HTTP Auth' %></title>
4
+ </head>
5
+
6
+ <body>
7
+ <p>HTTP Basic Auth</p>
8
+
9
+ <ul>
10
+ <li><a href="protected.html">should traverse pages that require authentication</a></li>
11
+ </ul>
12
+ </body>
13
+ </html>
@@ -6,7 +6,7 @@
6
6
  <body>
7
7
  <% if @authed %>
8
8
  <p>
9
- <a href="protected/1.html">protected content</a>
9
+ <a href="protected.html">protected content</a>
10
10
  </p>
11
11
  <% end %>
12
12
  </body>
@@ -24,7 +24,15 @@
24
24
  </li>
25
25
 
26
26
  <li>
27
- <a href="http://not.found/course/remote/fail.html">should ignore links that fail</a>
27
+ <a href="http://191.255.0.0/course/remote/fail.html">should ignore links with unreachable IP Addresses</a>
28
+ </li>
29
+
30
+ <li>
31
+ <a href="http://bad.tld/course/remote/fail.html">should ignore links with invalid TLDs</a>
32
+ </li>
33
+
34
+ <li>
35
+ <a href="http://bad.url.lol.com/course/remote/fail.html">should ignore links that fail</a>
28
36
  </li>
29
37
  </ul>
30
38
  </body>
@@ -15,8 +15,10 @@
15
15
  <li><a href="empty/start.html">Empty links</a></li>
16
16
  <li><a href="javascript/start.html">Bogus JavaScript Links</a></li>
17
17
  <li><a href="frames/start.html">Frames</a></li>
18
+ <li><a href="auth/start.html">HTTP Auth</a></li>
18
19
  <li><a href="cookies/start.html">Cookies</a></li>
19
20
  <li><a href="redirects/start.html">HTTP Redirects</a></li>
21
+ <li><a href="auth/start.html">HTTP Auth</a></li>
20
22
  </ul>
21
23
  </body>
22
24
  </html>
data/views/layout.erb CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  <div id="footer">
18
18
  <p><a href="http://github.com/postmodern/wsoc">Web Spider Obstacle Course</a> | Version <%= WSOC::VERSION %></p>
19
- <p>Copyright &#169; 2009 Hal Brodigan</p>
19
+ <p>Copyright &#169; 2009-2010 Hal Brodigan</p>
20
20
  <p>Powered by <a href="http://www.ruby-lang.org/">Ruby</a> <%= RUBY_VERSION %> and <a href="http://www.sinatrarb.com/">Sinatra</a></p>
21
21
  <p>Made with <a href="http://www.vim.org/">Vim</a> | <a href="http://validator.w3.org/check?uri=referer">XHTML 1.1 Strict</a></p>
22
22
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wsoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
@@ -30,7 +30,7 @@ cert_chain:
30
30
  pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2010-01-02 00:00:00 -08:00
33
+ date: 2010-01-06 00:00:00 -08:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -99,6 +99,7 @@ files:
99
99
  - lib/wsoc/course_specs.rb
100
100
  - lib/wsoc/helpers.rb
101
101
  - lib/wsoc/helpers/rendering.rb
102
+ - lib/wsoc/helpers/authentication.rb
102
103
  - lib/wsoc/helpers/course.rb
103
104
  - lib/wsoc/course.rb
104
105
  - lib/wsoc/app.rb
@@ -127,6 +128,7 @@ files:
127
128
  - views/course_cookies_start.erb
128
129
  - views/course_cookies_get.erb
129
130
  - views/course_redirects_start.erb
131
+ - views/course_auth_start.erb
130
132
  - views/welcome.erb
131
133
  has_rdoc: yard
132
134
  homepage: http://github.com/postmodern/wsoc
metadata.gz.sig CHANGED
Binary file