rewrite-tester 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +37 -0
  4. data/lib/redirects.rb +27 -0
  5. data/lib/rewrite_rule.rb +56 -0
  6. metadata +75 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fda3cc7258f9e5f245a91248892b258b1acc7242
4
+ data.tar.gz: fe65b2b5ed6bdc63fede8d81b05288b4178b97b9
5
+ SHA512:
6
+ metadata.gz: 8d0193b4addf5038abfa7ca0e072a084a1f425f5aa4f32cae43ca5562f53188008e2296a5b2b7177451df1ee5673a5abcc42489ca099cc0f2d55271ade813649
7
+ data.tar.gz: 7b4d7c57b2d49bef80a663ffc1bc24fbe2a2dc3cbe99dfd81e627c08f084f19d0346f1d663c3723e9b0d1e00191841432bc58dba35b8effd47d65ac01d2d7881
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Paul Bonaud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ Rewrite Tester
2
+ ===
3
+
4
+ This tool provides Rspec integration tests to test your server's *url rewriting* capabilities given a set of Apache `RewriteRules`.
5
+
6
+
7
+ _Tool under development_
8
+
9
+ Usage
10
+ ===
11
+
12
+ - From the sources
13
+
14
+ - Clone the repository and use the default rake task to run the tests. You will need to give the absolute path of a file containing a list of `RewriteRules` through a `RULES` env variable.
15
+
16
+ `bash
17
+ $ RULES=/path/to//my/rules rake
18
+ `
19
+
20
+ - From your project
21
+
22
+ - Include the gem in your `Gemfile`
23
+
24
+ `ruby
25
+ gem 'rewrite-tester'
26
+ `
27
+
28
+ - Use the `test:redirects` rake task by giving a absolute file path to the `RULES` env variable.
29
+
30
+ `bash
31
+ $ RULES=/path/to//my/rules rake test:redirects
32
+ `
33
+
34
+ LICENSE
35
+ ===
36
+
37
+ MIT
data/lib/redirects.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'rewrite_rule'
2
+
3
+ class Redirects
4
+
5
+ def initialize io_instance
6
+ @rules = []
7
+
8
+ unless io_instance.nil?
9
+ io_instance.readlines.each do |line|
10
+ @rules << RewriteRule.new(line)
11
+ end
12
+ end
13
+ end
14
+
15
+ # Increments the rul reading
16
+ def has_next?
17
+ !@rules.empty?
18
+ end
19
+
20
+ # Returns a rule
21
+ def next
22
+ @rules.pop
23
+ end
24
+
25
+ attr_accessor :rules
26
+
27
+ end
@@ -0,0 +1,56 @@
1
+ class RewriteRule
2
+
3
+ attr_accessor :possibilities, :substitution
4
+
5
+ def initialize(line)
6
+ self.parse line
7
+ end
8
+
9
+ # Parse an apache RewriteRule and transform it into a Ruby object
10
+ def parse(line)
11
+
12
+ match_data = /RewriteRule ([^ ]+) ([^ ]+) \[([^ ]+)\](\n)?$/.match(line)
13
+
14
+ return if match_data.nil?
15
+
16
+ @regex = match_data[1]
17
+ @possibilities = generate_possibilities @regex
18
+ @substitution = match_data[2].gsub(/\$[0-9]+/, '')
19
+ @flags = match_data[3].split(',')
20
+
21
+ end
22
+
23
+ def valid?
24
+ !@regex.nil? && !@substitution.nil? && !@flags.nil?
25
+ end
26
+
27
+ def redirection?
28
+ !@flags.nil? && @flags.include?('R=301')
29
+ end
30
+
31
+ def redirects
32
+ @possibilities.map { |possibility|
33
+ { possibility => @substitution}
34
+ }
35
+ end
36
+
37
+ def generate_possibilities regex
38
+ some = []
39
+ base = regex.gsub(/\^|\$/,'')
40
+
41
+ # Maybe will generate two possibilities, with and without
42
+ maybe_regex = /\(([^*+]+)\)\?/
43
+ match_data = maybe_regex.match(base)
44
+ if match_data.nil?
45
+ some << base
46
+ else
47
+ some << base.gsub(match_data[0], match_data[1])
48
+ some << base.gsub(match_data[0], '')
49
+ end
50
+
51
+ # Anything will be replaced by nothing
52
+ some.map { |possibility|
53
+ "http://www.clicrdv.com#{possibility.gsub('(.*)', '')}"
54
+ }
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rewrite-tester
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Bonaud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This tool was built to do full integration testing of HTTP requests
42
+ email: paul.bonaud@clicrdv.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE
48
+ - README.md
49
+ - lib/redirects.rb
50
+ - lib/rewrite_rule.rb
51
+ homepage: http://rubygems.org/gems/rewrite-tester
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.2.2
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Make HTTP request and test answers
75
+ test_files: []