http_redirect_test 0.1.1 → 0.1.2
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.
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'http_redirect_test'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: http_redirect_test command project_name"
|
8
|
+
|
9
|
+
opts.on("g", "generate DIR", "The directory your projects are located, defaults to ~/code") do |d|
|
10
|
+
@dir = d
|
11
|
+
end
|
12
|
+
|
13
|
+
opts.on_tail("-h", "--help", "Show this help message.") do
|
14
|
+
puts opts;
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
end.parse!
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_redirect_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Matt House
|
@@ -9,12 +15,27 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-10-21 00:00:00 +01:00
|
13
19
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mocha
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 49
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 5
|
34
|
+
version: 0.9.5
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
16
37
|
description:
|
17
|
-
email: matt@
|
38
|
+
email: matt@eightbitraptor.com
|
18
39
|
executables: []
|
19
40
|
|
20
41
|
extensions: []
|
@@ -22,12 +43,11 @@ extensions: []
|
|
22
43
|
extra_rdoc_files: []
|
23
44
|
|
24
45
|
files:
|
25
|
-
-
|
26
|
-
- lib/http_redirect_test/redirect_check.rb
|
27
|
-
- lib/http_redirect_test/resource_path.rb
|
46
|
+
- bin/http_redirect_test.rb
|
28
47
|
- lib/http_redirect_test.rb
|
48
|
+
- test/test_helper.rb
|
29
49
|
has_rdoc: true
|
30
|
-
homepage: http://github.com/
|
50
|
+
homepage: http://github.com/eightbitraptor/http_redirect_test
|
31
51
|
licenses: []
|
32
52
|
|
33
53
|
post_install_message:
|
@@ -36,23 +56,29 @@ rdoc_options: []
|
|
36
56
|
require_paths:
|
37
57
|
- lib
|
38
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
39
60
|
requirements:
|
40
61
|
- - ">="
|
41
62
|
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
42
66
|
version: "0"
|
43
|
-
version:
|
44
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
45
69
|
requirements:
|
46
70
|
- - ">="
|
47
71
|
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
48
75
|
version: "0"
|
49
|
-
version:
|
50
76
|
requirements: []
|
51
77
|
|
52
78
|
rubyforge_project:
|
53
|
-
rubygems_version: 1.3.
|
79
|
+
rubygems_version: 1.3.7
|
54
80
|
signing_key:
|
55
81
|
specification_version: 3
|
56
|
-
summary:
|
82
|
+
summary: Test Apache behavior using Test::Unit, based on a gist by Patrick Reagan of Viget Labs
|
57
83
|
test_files: []
|
58
84
|
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "redirect_check")
|
2
|
-
require File.join(File.dirname(__FILE__), "resource_path")
|
3
|
-
require 'test/unit'
|
4
|
-
|
5
|
-
class HTTPRedirectTest < Test::Unit::TestCase
|
6
|
-
# permanent can be overriden in 2 ways, with a call to self.permanent to set globally. Or via the options array for each redirect call
|
7
|
-
@permanent=nil
|
8
|
-
|
9
|
-
def default_test; end # placeholder to stop Test::Unit from complaining
|
10
|
-
|
11
|
-
class <<self
|
12
|
-
def domain=(domain)
|
13
|
-
@domain = domain
|
14
|
-
end
|
15
|
-
|
16
|
-
def domain
|
17
|
-
@domain
|
18
|
-
end
|
19
|
-
|
20
|
-
def permanent=(permanent)
|
21
|
-
@permanent=permanent
|
22
|
-
end
|
23
|
-
|
24
|
-
def permanent?
|
25
|
-
@permanent.nil? ? false : true
|
26
|
-
end
|
27
|
-
|
28
|
-
def should_not_redirect(path)
|
29
|
-
class_eval <<-CODE
|
30
|
-
def test_#{name_for(path)}_should_not_redirect
|
31
|
-
check = RedirectCheck.new(self.class.domain, '#{path}')
|
32
|
-
assert_equal false, check.redirected?, "#{path} is redirecting"
|
33
|
-
assert_equal true, check.success?, "#{path} is not a success response"
|
34
|
-
end
|
35
|
-
CODE
|
36
|
-
end
|
37
|
-
|
38
|
-
def name_for(path)
|
39
|
-
name = path.gsub(/\W+/, '_')
|
40
|
-
name.gsub!(/^_+/, '')
|
41
|
-
name.gsub!(/_+$/, '')
|
42
|
-
|
43
|
-
name = 'root' if name == ''
|
44
|
-
|
45
|
-
name
|
46
|
-
end
|
47
|
-
|
48
|
-
def should_redirect(source, options)
|
49
|
-
source_path = ResourcePath.new(source, :param => 'subdir').to_s
|
50
|
-
destination_path = ResourcePath.new(options[:to], :param => 'subdir').to_s
|
51
|
-
|
52
|
-
@permanent = options.fetch(:permanent, true) if @permanent.nil?
|
53
|
-
|
54
|
-
class_eval <<-CODE
|
55
|
-
def test_#{name_for(source_path)}_should_redirect_to_#{name_for(destination_path)}
|
56
|
-
redirection = RedirectCheck.new(self.class.domain, '#{source_path}', '#{destination_path}')
|
57
|
-
assert_equal true, redirection.redirected?, "'#{source_path}' is not redirecting"
|
58
|
-
assert_equal '#{destination_path}', redirection.redirected_path,
|
59
|
-
"'#{source_path}' is not redirecting to '#{destination_path}'"
|
60
|
-
|
61
|
-
if #{@permanent}
|
62
|
-
assert_equal true, redirection.permanent_redirect?,
|
63
|
-
"The redirection from '#{source_path}' to '#{destination_path}' doesn't appear to be a permanent redirect"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
CODE
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'net/http'
|
3
|
-
|
4
|
-
class RedirectCheck
|
5
|
-
attr_reader :source_path, :destination_path
|
6
|
-
|
7
|
-
def initialize(domain, source_path, destination_path = nil)
|
8
|
-
@domain = domain
|
9
|
-
@source_path = source_path.to_s
|
10
|
-
@destination_path = destination_path.to_s
|
11
|
-
end
|
12
|
-
|
13
|
-
def uri
|
14
|
-
URI.parse("http://#{@domain}#{source_path}")
|
15
|
-
end
|
16
|
-
|
17
|
-
def response
|
18
|
-
@response ||= Net::HTTP.start(uri.host, uri.port) {|http| return http.head(uri.path) }
|
19
|
-
end
|
20
|
-
|
21
|
-
def success?
|
22
|
-
response.is_a?(Net::HTTPOK)
|
23
|
-
end
|
24
|
-
|
25
|
-
def redirected?
|
26
|
-
response.is_a?(Net::HTTPRedirection)
|
27
|
-
end
|
28
|
-
|
29
|
-
def permanent_redirect?
|
30
|
-
redirected? && response.is_a?(Net::HTTPMovedPermanently)
|
31
|
-
end
|
32
|
-
|
33
|
-
def redirected_path
|
34
|
-
response['location'].sub(/#{Regexp.escape("#{uri.scheme}://#{uri.host}")}/, '') if redirected?
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class ResourcePath
|
2
|
-
|
3
|
-
attr_writer :param
|
4
|
-
|
5
|
-
def initialize(path, options = {})
|
6
|
-
@path = path
|
7
|
-
@param = options[:param]
|
8
|
-
end
|
9
|
-
|
10
|
-
def param
|
11
|
-
@param ||= (0...8).map{65.+(rand(25)).chr}.join
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
@path.gsub('*', param)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|