foreign-fqdn-routing 0.0.1
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.
- data/.gitignore +2 -0
- data/MIT-LICENSE +18 -0
- data/README +130 -0
- data/Rakefile +56 -0
- data/VERSION.yml +4 -0
- data/foreign-fqdn-routing.gemspec +51 -0
- data/init.rb +1 -0
- data/lib/foreign_fqdn_routing.rb +46 -0
- data/lib/foreign_fqdn_routing/routing_extensions.rb +57 -0
- data/rails/init.rb +5 -0
- data/test/foreign_fqdn_routing_test.rb +168 -0
- data/test/test_helper.rb +12 -0
- metadata +69 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
2
|
+
a copy of this software and associated documentation files (the
|
3
|
+
"Software"), to deal in the Software without restriction, including
|
4
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
5
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
6
|
+
permit persons to whom the Software is furnished to do so, subject to
|
7
|
+
the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be
|
10
|
+
included in all copies or substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
15
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
16
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
17
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
Foreign FQDN Routing +
|
2
|
+
Request Routing Plugin for Ruby on Rails
|
3
|
+
-----------------------------------------
|
4
|
+
= Foreign FQDN Request Routing
|
5
|
+
|
6
|
+
-------------------------------------------------------------------------------
|
7
|
+
Foreign FQDN Routing provides simple handling of foreign domains in Rails.
|
8
|
+
It borrows largely from SubdomainFu and some other snippets found around the web.
|
9
|
+
|
10
|
+
Request routing allows you to define routing conditions that test
|
11
|
+
methods/properties of the request object such as subdomain, domain,
|
12
|
+
port. You can test them either against a value or with a Regexp
|
13
|
+
(assuming the method returns a string)
|
14
|
+
|
15
|
+
Merging these two plugins allows them to work together and enhance the routing
|
16
|
+
capability of Rails.
|
17
|
+
|
18
|
+
Documentation from the original plugins follows...
|
19
|
+
|
20
|
+
-------------------------------------------------------------------------------
|
21
|
+
Foreign FQDN Routing
|
22
|
+
-------------------------------------------------------------------------------
|
23
|
+
|
24
|
+
Installation
|
25
|
+
============
|
26
|
+
|
27
|
+
Foreign FQDN Routing is available as a plugin or a gem. To install it as a
|
28
|
+
plugin with Rails 2.1 or later):
|
29
|
+
|
30
|
+
script/plugin install git://github.com/autodata/foreign-fqdn-routing.git
|
31
|
+
|
32
|
+
To install as a gem:
|
33
|
+
|
34
|
+
gem install foreign-fqdn-routing
|
35
|
+
|
36
|
+
Examples
|
37
|
+
========
|
38
|
+
|
39
|
+
Foreign FQDN Routing extends Rails's routing mechanisms to provide a way to
|
40
|
+
redirect non-native domains.
|
41
|
+
|
42
|
+
Let's say my rails app domain is 'mydomain.com' and I am creating an app that
|
43
|
+
allows users to add a CNAME record to map their subdomain so that
|
44
|
+
'foo.usersdomain.com' would actually point to 'mydomain.com/users/1234'.
|
45
|
+
|
46
|
+
The route at the top of config/routes.rb would look like:
|
47
|
+
|
48
|
+
map.connect '*path', :controller => 'users',
|
49
|
+
:action => 'index', :conditions => { :foreign_domain => true }
|
50
|
+
|
51
|
+
And in the users controller:
|
52
|
+
|
53
|
+
@user = User.find_by_foreign_domain(request.host.downcase)
|
54
|
+
# this example would require a database field called foreign_domain
|
55
|
+
|
56
|
+
Configuration
|
57
|
+
=============
|
58
|
+
|
59
|
+
You will need to configure Foreign FQDN Routing based on your native hostnames.
|
60
|
+
|
61
|
+
native_domains
|
62
|
+
--------
|
63
|
+
|
64
|
+
A hash of arrays for the native domain names for each relevant environment.
|
65
|
+
|
66
|
+
Create the file config/initializers/native_domains.rb and put something like:
|
67
|
+
|
68
|
+
ForeignFQDNRouting.init_native_domains = {
|
69
|
+
:development => ['localhost'],
|
70
|
+
:staging => ['staging.example.com'],
|
71
|
+
:production => ['example.com', 'example.org', 'example.net']
|
72
|
+
} # set all at once (also the defaults)
|
73
|
+
|
74
|
+
|
75
|
+
Or set the native domains on the fly with:
|
76
|
+
|
77
|
+
ForeignFQDNRouting.native_domains =
|
78
|
+
['example.com', 'example.org', 'example.net'] # sets for current environment
|
79
|
+
|
80
|
+
Resources
|
81
|
+
=========
|
82
|
+
|
83
|
+
* GitHub Repository: http://github.com/autodata/foreign_fqdn_routing
|
84
|
+
* 2008 by Brian Mulloy (http://landlessness.net/), with contributions from Joe Scharf and William Melody. Released under the MIT license.
|
85
|
+
|
86
|
+
|
87
|
+
*******************************************************************************
|
88
|
+
|
89
|
+
-------------------------------------------------------------------------------
|
90
|
+
Request Routing Plugin for Ruby on Rails
|
91
|
+
-------------------------------------------------------------------------------
|
92
|
+
(c) Dan Webb 2006 (dan@vivabit.com)
|
93
|
+
|
94
|
+
Plugin that allows you to define routing conditions that test
|
95
|
+
methods/properties of the request object such as subdomain, domain,
|
96
|
+
port. You can test them either against a value or with a Regexp
|
97
|
+
(assuming the method returns a string)
|
98
|
+
|
99
|
+
*UPDATE* Now works with the new routing code as implemented in edge rails. Note the
|
100
|
+
change in API: use :conditions instead of :requirements.
|
101
|
+
|
102
|
+
== Installation
|
103
|
+
|
104
|
+
ruby script/plugin install http://svn.vivabit.net/external/rubylibs/request_routing/
|
105
|
+
|
106
|
+
== Usage
|
107
|
+
|
108
|
+
In routes.rb you can specify use the :requirements hash with request properties:
|
109
|
+
|
110
|
+
map.connect '', :controller => 'main', :conditions => { :subdomain => 'www' }
|
111
|
+
|
112
|
+
map.connect 'admin', :controller => 'admin', :conditions => { :remote_ip => /^127\.0\.0\.[0-9]$/ }
|
113
|
+
|
114
|
+
You can also, of course, use the conditions hash in map.with_options calls.
|
115
|
+
|
116
|
+
The allowed properties are:
|
117
|
+
|
118
|
+
:subdomain (only checks the first subdomain)
|
119
|
+
:domain (only accurate for single tld domain names at the moment)
|
120
|
+
:method (a symbol)
|
121
|
+
:port (a number)
|
122
|
+
:remote_ip
|
123
|
+
:content_type (content type of the post body)
|
124
|
+
:accepts
|
125
|
+
:request_uri (the entire request uri)
|
126
|
+
:protocol (either http:// or https://)
|
127
|
+
|
128
|
+
== Copyright
|
129
|
+
|
130
|
+
Copyright (c) 2009 Joe Scharf. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "foreign-fqdn-routing"
|
8
|
+
gem.summary = %Q{This version of foreign_fqdn_routing merges foreign_fqdn_routing with request_routing}
|
9
|
+
gem.email = "william@kyakia.com"
|
10
|
+
gem.homepage = "http://github.com/autodata/foreign-fqdn-routing"
|
11
|
+
gem.authors = ["Brian Mulloy", "Joe Scharf", "William Melody"]
|
12
|
+
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = false
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "foreign-fqdn-routing-gem #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION.yml
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{foreign-fqdn-routing}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Brian Mulloy", "Joe Scharf", "William Melody"]
|
12
|
+
s.date = %q{2009-12-10}
|
13
|
+
s.email = %q{william@kyakia.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".gitignore",
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION.yml",
|
23
|
+
"foreign-fqdn-routing.gemspec",
|
24
|
+
"init.rb",
|
25
|
+
"lib/foreign_fqdn_routing.rb",
|
26
|
+
"lib/foreign_fqdn_routing/routing_extensions.rb",
|
27
|
+
"rails/init.rb",
|
28
|
+
"test/foreign_fqdn_routing_test.rb",
|
29
|
+
"test/test_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/autodata/foreign-fqdn-routing}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{This version of foreign_fqdn_routing merges foreign_fqdn_routing with request_routing}
|
36
|
+
s.test_files = [
|
37
|
+
"test/foreign_fqdn_routing_test.rb",
|
38
|
+
"test/test_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'foreign_fqdn_routing/routing_extensions'
|
2
|
+
|
3
|
+
module ForeignFQDNRouting
|
4
|
+
DEFAULT_NATIVE_DOMAINS = {:development => ['localhost:3000'], :test => ['test.host'], :production => ['example.com'] }
|
5
|
+
mattr_accessor :init_native_domains
|
6
|
+
@@init_native_domains = DEFAULT_NATIVE_DOMAINS.dup
|
7
|
+
|
8
|
+
def self.native_domains
|
9
|
+
init_native_domains[RAILS_ENV.to_sym]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.native_domains=(value)
|
13
|
+
init_native_domains[RAILS_ENV.to_sym] = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.foreign_domain?(host)
|
17
|
+
native_domains.each do |domain|
|
18
|
+
return false if host =~ /#{domain}\Z/i
|
19
|
+
end
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.foreign_fqdn?(host)
|
24
|
+
native_domains.each do |domain|
|
25
|
+
return false if host =~ /\A#{domain}\Z/i
|
26
|
+
end
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
module Controller
|
31
|
+
def self.included(controller)
|
32
|
+
controller.helper_method(:foreign_domain?)
|
33
|
+
controller.helper_method(:foreign_fqdn?)
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def foreign_domain?
|
39
|
+
ForeignFQDNRouting.foreign_domain?(request.host)
|
40
|
+
end
|
41
|
+
|
42
|
+
def foreign_fqdn?
|
43
|
+
ForeignFQDNRouting.foreign_fqdn?(request.host)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ForeignFQDNRouting
|
2
|
+
module RouteExtensions
|
3
|
+
|
4
|
+
TESTABLE_REQUEST_METHODS = [:subdomain, :domain, :method, :port, :remote_ip,
|
5
|
+
:content_type, :accepts, :request_uri, :protocol]
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.alias_method_chain :recognition_conditions, :foreign_domain
|
9
|
+
end
|
10
|
+
|
11
|
+
def recognition_conditions_with_foreign_domain
|
12
|
+
result = recognition_conditions_without_foreign_domain
|
13
|
+
result << "ForeignFQDNRouting.foreign_domain?(env[:host])" if conditions[:foreign_domain] == true
|
14
|
+
result << "!ForeignFQDNRouting.foreign_domain?(env[:host])" if conditions[:foreign_domain] == false
|
15
|
+
result << "ForeignFQDNRouting.foreign_fqdn?(env[:host])" if conditions[:foreign_fqdn] == true
|
16
|
+
result << "!ForeignFQDNRouting.foreign_fqdn?(env[:host])" if conditions[:foreign_fqdn] == false
|
17
|
+
|
18
|
+
conditions.each do |method, value|
|
19
|
+
if TESTABLE_REQUEST_METHODS.include? method
|
20
|
+
result << if value.is_a? Regexp
|
21
|
+
"conditions[#{method.inspect}] =~ env[#{method.inspect}]"
|
22
|
+
else
|
23
|
+
"conditions[#{method.inspect}] === env[#{method.inspect}]"
|
24
|
+
end
|
25
|
+
else
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module RouteSetExtensions
|
35
|
+
def self.included(base)
|
36
|
+
base.alias_method_chain :extract_request_environment, :foreign_domain
|
37
|
+
end
|
38
|
+
|
39
|
+
def extract_request_environment_with_foreign_domain(request)
|
40
|
+
extract_request_environment_without_foreign_domain(request).merge({
|
41
|
+
:host => request.host,
|
42
|
+
:method => request.method,
|
43
|
+
:subdomain => request.subdomains.first.to_s,
|
44
|
+
:domain => request.domain,
|
45
|
+
:port => request.port,
|
46
|
+
:remote_ip => request.remote_ip,
|
47
|
+
:content_type => request.content_type,
|
48
|
+
:accepts => request.accepts.map(&:to_s).join(','),
|
49
|
+
:request_uri => request.request_uri,
|
50
|
+
:protocol => request.protocol
|
51
|
+
})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
ActionController::Routing::RouteSet.send :include, ForeignFQDNRouting::RouteSetExtensions
|
57
|
+
ActionController::Routing::Route.send :include, ForeignFQDNRouting::RouteExtensions
|
data/rails/init.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/../init"
|
4
|
+
RAILS_ENV = :test
|
5
|
+
|
6
|
+
class TestController < Class.new(ActionController::Base)
|
7
|
+
def thing
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class OtherTestController < Class.new(ActionController::Base)
|
12
|
+
def thing
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MockRequest < Struct.new(:path, :subdomains, :method, :remote_ip, :protocol, :path_parameters, :domain, :port, :content_type, :accepts, :request_uri, :host)
|
17
|
+
end
|
18
|
+
|
19
|
+
class ForeignFQDNRoutingTest < ActionController::TestCase
|
20
|
+
attr_reader :rs
|
21
|
+
def setup
|
22
|
+
@rs = ::ActionController::Routing::RouteSet.new
|
23
|
+
ActionController::Routing.use_controllers! %w(test) if ActionController::Routing.respond_to? :use_controllers!
|
24
|
+
@rs.draw {|m| m.connect ':controller/:action/:id' }
|
25
|
+
@request = MockRequest.new(
|
26
|
+
'',
|
27
|
+
['www'],
|
28
|
+
:post,
|
29
|
+
'1.2.3.4',
|
30
|
+
'http://',
|
31
|
+
'',
|
32
|
+
'thing.com',
|
33
|
+
3432,
|
34
|
+
'text/html',
|
35
|
+
['*/*'],
|
36
|
+
'/',
|
37
|
+
'www.example.com'
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
test "should route normally" do
|
42
|
+
assert_raise(ActionController::RoutingError) do
|
43
|
+
@rs.recognize(@request)
|
44
|
+
end
|
45
|
+
|
46
|
+
@request.path = '/test/thing'
|
47
|
+
assert(@rs.recognize(@request))
|
48
|
+
end
|
49
|
+
|
50
|
+
test "should route conditionally on subdomain" do
|
51
|
+
@rs.draw { |m| m.connect 'thing', :controller => 'test', :conditions => { :subdomain => 'www' } }
|
52
|
+
@request.path = '/thing'
|
53
|
+
assert(@rs.recognize(@request))
|
54
|
+
@request.subdomains = ['sdkg']
|
55
|
+
assert_raise(ActionController::RoutingError) do
|
56
|
+
@rs.recognize(@request)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
test "should route conditionally on protocol" do
|
61
|
+
@rs.draw { |m| m.connect 'thing', :controller => 'test', :conditions => { :protocol => /^https:/ } }
|
62
|
+
@request.path = '/thing'
|
63
|
+
assert_raise(ActionController::RoutingError) do
|
64
|
+
@rs.recognize(@request)
|
65
|
+
end
|
66
|
+
|
67
|
+
@request.protocol = "https://"
|
68
|
+
assert(@rs.recognize(@request))
|
69
|
+
end
|
70
|
+
|
71
|
+
test "should route conditionally on alternate conditionals" do
|
72
|
+
@rs.draw { |m|
|
73
|
+
m.connect 'thing', :controller => 'test', :conditions => { :remote_ip => '1.2.3.4' }
|
74
|
+
m.connect 'thing', :controller => 'other_test', :conditions => { :remote_ip => '1.2.3.5' }
|
75
|
+
}
|
76
|
+
|
77
|
+
@request.path = '/thing'
|
78
|
+
assert(@rs.recognize(@request))
|
79
|
+
|
80
|
+
@request.remote_ip = '1.2.3.5'
|
81
|
+
assert(@rs.recognize(@request))
|
82
|
+
end
|
83
|
+
|
84
|
+
test "should route conditionally on foreign domain" do
|
85
|
+
ForeignFQDNRouting.init_native_domains = {
|
86
|
+
:development => ['localhost'],
|
87
|
+
:test => ['www.example.com'],
|
88
|
+
:production => ['example.com', 'example.org', 'example.net']
|
89
|
+
}
|
90
|
+
|
91
|
+
@rs.draw { |m| m.connect 'thing', :controller => 'test', :conditions => { :foreign_domain => false } }
|
92
|
+
@request.path = '/thing'
|
93
|
+
assert(@rs.recognize(@request))
|
94
|
+
@request.host = ['foreign.domain.com']
|
95
|
+
assert_raise(ActionController::RoutingError) do
|
96
|
+
@rs.recognize(@request)
|
97
|
+
end
|
98
|
+
@rs.draw { |m| m.connect 'thing', :controller => 'test', :conditions => { :foreign_domain => true } }
|
99
|
+
@request.path = '/thing'
|
100
|
+
assert(@rs.recognize(@request))
|
101
|
+
end
|
102
|
+
|
103
|
+
test "should route conditionally on foreign domain and protocol" do
|
104
|
+
ForeignFQDNRouting.init_native_domains = {
|
105
|
+
:development => ['localhost'],
|
106
|
+
:test => ['www.example.com'],
|
107
|
+
:production => ['example.com', 'example.org', 'example.net']
|
108
|
+
}
|
109
|
+
|
110
|
+
@rs.draw { |m| m.connect 'thing', :controller => 'test', :conditions => { :foreign_domain => false, :protocol => /^http:/ } }
|
111
|
+
@request.path = '/thing'
|
112
|
+
# :foreign_domain => false, :protocol => http:// (MATCH)
|
113
|
+
assert(@rs.recognize(@request))
|
114
|
+
|
115
|
+
# :foreign_domain => false, :protocol => https:// (NO MATCH)
|
116
|
+
@request.protocol = "https://"
|
117
|
+
assert_raise(ActionController::RoutingError) do
|
118
|
+
@rs.recognize(@request)
|
119
|
+
end
|
120
|
+
|
121
|
+
# :foreign_domain => true, :protocol => http:// (NO MATCH)
|
122
|
+
@request.host = ['foreign.domain.com']
|
123
|
+
@request.protocol = "http://"
|
124
|
+
assert_raise(ActionController::RoutingError) do
|
125
|
+
@rs.recognize(@request)
|
126
|
+
end
|
127
|
+
|
128
|
+
# :foreign_domain => true, :protocol => https:// (NO MATCH)
|
129
|
+
@request.protocol = "https://"
|
130
|
+
assert_raise(ActionController::RoutingError) do
|
131
|
+
@rs.recognize(@request)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
test "should route conditionally on foreign fqdn and protocol" do
|
137
|
+
ForeignFQDNRouting.init_native_domains = {
|
138
|
+
:development => ['localhost'],
|
139
|
+
:test => ['www.example.com'],
|
140
|
+
:production => ['example.com', 'example.org', 'example.net']
|
141
|
+
}
|
142
|
+
|
143
|
+
@rs.draw { |m| m.connect 'thing', :controller => 'test', :conditions => { :foreign_fqdn => false, :protocol => /^http:/ } }
|
144
|
+
@request.path = '/thing'
|
145
|
+
# :foreign_fqdn => false, :protocol => http:// (MATCH)
|
146
|
+
assert(@rs.recognize(@request))
|
147
|
+
|
148
|
+
# :foreign_fqdn => false, :protocol => https:// (NO MATCH)
|
149
|
+
@request.protocol = "https://"
|
150
|
+
assert_raise(ActionController::RoutingError) do
|
151
|
+
@rs.recognize(@request)
|
152
|
+
end
|
153
|
+
|
154
|
+
# :foreign_fqdn => true, :protocol => http:// (NO MATCH)
|
155
|
+
@request.host = ['foreign.example.com']
|
156
|
+
@request.protocol = "http://"
|
157
|
+
assert_raise(ActionController::RoutingError) do
|
158
|
+
@rs.recognize(@request)
|
159
|
+
end
|
160
|
+
|
161
|
+
# :foreign_fqdn => true, :protocol => https:// (NO MATCH)
|
162
|
+
@request.protocol = "https://"
|
163
|
+
assert_raise(ActionController::RoutingError) do
|
164
|
+
@rs.recognize(@request)
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'action_controller'
|
5
|
+
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'foreign_domain_routing'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreign-fqdn-routing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Mulloy
|
8
|
+
- Joe Scharf
|
9
|
+
- William Melody
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2009-12-10 00:00:00 -06:00
|
15
|
+
default_executable:
|
16
|
+
dependencies: []
|
17
|
+
|
18
|
+
description:
|
19
|
+
email: william@kyakia.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files:
|
25
|
+
- README
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- MIT-LICENSE
|
29
|
+
- README
|
30
|
+
- Rakefile
|
31
|
+
- VERSION.yml
|
32
|
+
- foreign-fqdn-routing.gemspec
|
33
|
+
- init.rb
|
34
|
+
- lib/foreign_fqdn_routing.rb
|
35
|
+
- lib/foreign_fqdn_routing/routing_extensions.rb
|
36
|
+
- rails/init.rb
|
37
|
+
- test/foreign_fqdn_routing_test.rb
|
38
|
+
- test/test_helper.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/autodata/foreign-fqdn-routing
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: This version of foreign_fqdn_routing merges foreign_fqdn_routing with request_routing
|
67
|
+
test_files:
|
68
|
+
- test/foreign_fqdn_routing_test.rb
|
69
|
+
- test/test_helper.rb
|