handcart 0.0.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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +247 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/handcart/application.js +16 -0
- data/app/assets/stylesheets/handcart/application.css +15 -0
- data/app/assets/stylesheets/handcart/layout.css.scss +21 -0
- data/app/controllers/handcart/application_controller.rb +4 -0
- data/app/controllers/handcart/ip_addresses_controller.rb +56 -0
- data/app/controllers/handcart/subdomains_controller.rb +55 -0
- data/app/helpers/handcart/application_helper.rb +14 -0
- data/app/helpers/handcart/url_helper.rb +16 -0
- data/app/models/handcart/concerns/handcarts.rb +30 -0
- data/app/models/handcart/domain_constraint.rb +20 -0
- data/app/models/handcart/ip_address.rb +18 -0
- data/app/models/handcart/setting_constraint.rb +26 -0
- data/app/models/handcart/subdomain.rb +36 -0
- data/app/views/handcart/ip_addresses/_form.html.haml +12 -0
- data/app/views/handcart/ip_addresses/edit.html.haml +3 -0
- data/app/views/handcart/ip_addresses/index.html.haml +36 -0
- data/app/views/handcart/ip_addresses/new.html.haml +3 -0
- data/app/views/handcart/ip_addresses/show.html.haml +20 -0
- data/app/views/handcart/subdomains/_form.html.haml +9 -0
- data/app/views/handcart/subdomains/edit.html.haml +3 -0
- data/app/views/handcart/subdomains/index.html.haml +31 -0
- data/app/views/handcart/subdomains/new.html.haml +3 -0
- data/app/views/handcart/subdomains/show.html.haml +20 -0
- data/app/views/layouts/handcart/_navbar.html.haml +15 -0
- data/app/views/layouts/handcart/application.html.haml +60 -0
- data/config/handcart.json +6 -0
- data/config/locales/en.yml +61 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20131009165427_create_handcart_subdomains.rb +9 -0
- data/db/migrate/20131203000934_create_handcart_ip_addresses.rb +12 -0
- data/lib/handcart.rb +67 -0
- data/lib/handcart/acts_as_handcart.rb +16 -0
- data/lib/handcart/controller_additions.rb +152 -0
- data/lib/handcart/engine.rb +27 -0
- data/lib/handcart/ip_authorization.rb +27 -0
- data/lib/handcart/simple_form.rb +179 -0
- data/lib/handcart/strategies/base_ip_strategy.rb +21 -0
- data/lib/handcart/strategies/containment_strategy.rb +16 -0
- data/lib/handcart/strategies/inclusion_strategy.rb +17 -0
- data/lib/handcart/templates/rspec/controller/controller_spec.rb +17 -0
- data/lib/handcart/templates/rspec/scaffold/routing_spec.rb +40 -0
- data/lib/handcart/version.rb +3 -0
- data/spec/controllers/handcart/ip_addresses_controller_spec.rb +134 -0
- data/spec/controllers/handcart/subdomains_controller_spec.rb +138 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/layout.css.scss +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +7 -0
- data/spec/dummy/app/controllers/custom_constraints_controller.rb +2 -0
- data/spec/dummy/app/controllers/ip_addresses_controller.rb +7 -0
- data/spec/dummy/app/controllers/master/companies_controller.rb +51 -0
- data/spec/dummy/app/controllers/master/dashboard_controller.rb +4 -0
- data/spec/dummy/app/controllers/master_controller.rb +2 -0
- data/spec/dummy/app/controllers/public_controller.rb +12 -0
- data/spec/dummy/app/controllers/subdomain_controller.rb +8 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/company.rb +7 -0
- data/spec/dummy/app/views/ip_addresses/index.html.haml +12 -0
- data/spec/dummy/app/views/ip_addresses/show.html.haml +1 -0
- data/spec/dummy/app/views/layouts/_navbar.html.haml +11 -0
- data/spec/dummy/app/views/layouts/application.html.haml +53 -0
- data/spec/dummy/app/views/layouts/public.html.haml +41 -0
- data/spec/dummy/app/views/master/companies/_form.html.haml +19 -0
- data/spec/dummy/app/views/master/companies/edit.html.haml +7 -0
- data/spec/dummy/app/views/master/companies/index.html.haml +25 -0
- data/spec/dummy/app/views/master/companies/new.html.haml +5 -0
- data/spec/dummy/app/views/master/companies/show.html.haml +12 -0
- data/spec/dummy/app/views/master/dashboard/index.html.haml +2 -0
- data/spec/dummy/app/views/public/forbidden.html.haml +3 -0
- data/spec/dummy/app/views/public/index.html.haml +2 -0
- data/spec/dummy/app/views/subdomain/index.html.haml +2 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +40 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +26 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/handcart.json +6 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/handcart.rb +16 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +12 -0
- data/spec/dummy/config/routes.rb +23 -0
- data/spec/dummy/db/migrate/20131010194534_create_companies.rb +10 -0
- data/spec/dummy/db/migrate/20131016183624_add_active_to_companies.rb +5 -0
- data/spec/dummy/db/schema.rb +41 -0
- data/spec/dummy/log/development.log +14 -0
- data/spec/dummy/log/test.log +786 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/spec/models/company_spec.rb +36 -0
- data/spec/dummy/spec/routing/custom_constraints_routing_spec.rb +37 -0
- data/spec/dummy/tmp/cache/assets/development/sass/27d34b7cbcb5b92ab03220c4d4b91379cc64c2c0/layout.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sass/dc98e44780f42e6521ebbf14c4db22f6a78c41ef/layout.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/05974a1f812cf4a61bb242d48722fd19 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/063a74a7c73c9501ee373ef00111f159 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/073d2b13ed9366ce539940749eb3844d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0d76367ded60510a66afc3dea891e76a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/106c3f4e1fc71e9dc70abae55d432886 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13ae4613233656a42188d4d3ddbb7fc1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/18c826ba1d6dac1633cae2da25c0402a +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/247df6a90ce931f763db1ade5227d4b1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2860df473a6cf4c483cd6f251fea3ae0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2a99072e783dcef4637b38221531ea61 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2ab4b3177ab6c9d837c0905b61eedad5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2b84c9cc30f71e24310dd1a4381caae8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2bebf0981bc585e24939ca8ffe10081c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2c45a1517014fd239c930e48a71a93f0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2d5147f4ea70131b4e330cab38aeb1a1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3124588878c79981009129f32d5fe408 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/33325c558d8db2071bf8a938517e5af2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/350c8c72b1dbd7a84f85424b5cd4def1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3a3d69c38e3b3d20e94420ebebd05a69 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3b1656b46a35a6120c3407b930d468ba +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3c0fc39d9b84afb4937545b620cd2d72 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3fa878a57cb0b42be266336564609b18 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/40f26b5e75d0f747e691c0b38529fb59 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/42aa8e53e39d8f5247f1b3e89cb00adc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/42e1f4c72bf58cf112dd11eae8ee768b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/433be3db83a4d9f93f5d1fa2ae3bde4e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4b6f9f46d7a2e230321d7f8df06ea470 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4c17c77b444339bb3ab293047da0ff0d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4ee93c096bb850d38032eb457afebf69 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/4f25edc4354919ba67721f488ba10e12 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/58fb821d4a4a44fdb2a89d4f487a8390 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5f97a76ac644497413f4c8dc547ddea6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6076ab56e9c62fd04155d6f6c43e575e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/60b75d9635ed84e08a0b9a245d8a3202 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/64ad9f343408809fdfb1df851186853d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6e79870e51ea835a6847f8c65e23e14b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6e9d2e7aafa45c939731291fa453b8c2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/78f915513059378e161ceb6f2d14fbd9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8102cf6724f489a310fe3a6b764bb2e9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/81108a1123b15b10c7f7f2e0d1207267 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/81b3dcc0aa61577b08de13ba5633dbc4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/83e686634b5ac6d4b183677ed2edda8b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8581aae276f167a9b7b2158641b0bf87 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/94cb3819408e525700729fbd473432c8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/99eb5e50b6d0e5d0d6b6c37cbde33864 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a7c86e9a777f7789dd1c78d26a662a87 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a9e19eb45005fa24bc8b90b6a374089f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ac4492393938e58cede2b6277afb0bc6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ad1d96635f4dae7eb22d1984947d7440 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/af718c632887ccb6c1c35c4b65c61293 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b2f45720a78d375468b99bb25f121c4e +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b559f2694561fc6c44e3319f507de1e7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b6e8c6ba59755a8fe132457f81065f96 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b796b57f310287a7a619afa9d5b99952 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b7c36a1c00d7804d9e827d704c0dd811 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bc28a210f3df576c74059aff8233eae3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/bc414fbd5123e40c4f5e69f4c294f489 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c0181c32e0ed10ec8fa3049f9a80f551 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c17130f66131c854d6f8c2196902b596 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c4c0e10aa5c21ece42c0bfe998a5d8c0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c63bcc000975adbdf423db3ad43eb93f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c962f9220062a6407dfc7d9447565273 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cb8b538b6fce61b500edebe63156bf62 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cfcef2015b7df990ed90006632877389 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cff56d2d0a8b8a25d4b0388d242be9c8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d32fc7356f764b22ecbcebbcb9b47ee1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d776667bae72eb3d582da5803fc931ca +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dfc307d14a0cf64cf8c3a4e94fdbcfb9 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e4b6570b82329477bc7043183b64b105 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/eff1316ad12dd5b8f4cbf0ba9e448229 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f2348b747b81ca6e3a24d5bd0b7023c4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f6f921309fcc78b6850abcf2418279fe +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7e1dbf50c19c9d439de52caa4296164 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/ff2adfc3ed446b68ac2d0077e8af34e2 +0 -0
- data/spec/factories/companies.rb +7 -0
- data/spec/factories/handcart_ip_addresses.rb +8 -0
- data/spec/factories/handcart_subdomains.rb +5 -0
- data/spec/models/handcart/base_ip_strategy_spec.rb +23 -0
- data/spec/models/handcart/containment_strategy_spec.rb +23 -0
- data/spec/models/handcart/domain_constraint_spec.rb +38 -0
- data/spec/models/handcart/engine_spec.rb +14 -0
- data/spec/models/handcart/handcart_spec.rb +38 -0
- data/spec/models/handcart/inclusion_strategy_spec.rb +29 -0
- data/spec/models/handcart/ip_address_spec.rb +51 -0
- data/spec/models/handcart/ip_authorization_spec.rb +17 -0
- data/spec/models/handcart/subdomain_spec.rb +153 -0
- data/spec/routing/handcart/ip_addresses_routing_spec.rb +38 -0
- data/spec/routing/handcart/subdomains_routing_spec.rb +38 -0
- data/spec/spec_helper.rb +65 -0
- data/spec/support/subdomains.rb +26 -0
- metadata +565 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
module Strategies
|
|
5
|
+
describe ContainmentStrategy do
|
|
6
|
+
let(:strategy) { ContainmentStrategy.new }
|
|
7
|
+
|
|
8
|
+
it "should have none for the strategy" do
|
|
9
|
+
strategy.strategy.should eq(:containment)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "authorize IP addresses that are only contained in the list" do
|
|
13
|
+
company = create(:company, name: "Planet Express")
|
|
14
|
+
ip1 = create(:handcart_ip_address, handcart: company)
|
|
15
|
+
ip2 = create(:handcart_ip_address, handcart: company)
|
|
16
|
+
company.ip_addresses.permitted.should include(ip1)
|
|
17
|
+
company.ip_addresses.permitted.should include(ip2)
|
|
18
|
+
strategy.is_in_range?(ip1, company).should eq(true)
|
|
19
|
+
strategy.is_in_range?(ip2, company).should eq(true)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
|
|
5
|
+
shared_examples "a domain constraint" do
|
|
6
|
+
it "should be able to read its domain" do
|
|
7
|
+
constraint.domain.should eq("dummy.dev")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should add it to Handcart's module variable" do
|
|
11
|
+
Handcart.domain_constraints.should include(constraint.domain)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "concerning the controller and route matching" do
|
|
15
|
+
before(:each) do
|
|
16
|
+
@request = ActionController::TestRequest.new
|
|
17
|
+
@request.host = "dummy.dev"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should have a matches? method" do
|
|
21
|
+
@request.domain.should eq("dummy.dev")
|
|
22
|
+
constraint.matches?(@request).should eq(true)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe DomainConstraint do
|
|
29
|
+
it_behaves_like "a domain constraint" do
|
|
30
|
+
let(:constraint) { DomainConstraint.new("dummy.dev") }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should have a default domain constraint" do
|
|
34
|
+
DomainConstraint.default_constraint.should_not be_nil
|
|
35
|
+
DomainConstraint.default_constraint.domain.should eq("dummy.test")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
describe Handcart::Engine do
|
|
5
|
+
it "should have a config file" do
|
|
6
|
+
Handcart::Engine::CONFIG.should_not be_nil
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should have a default domain constraint" do
|
|
10
|
+
Handcart::Engine::CONFIG.should have_key(:domain_constraint)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
|
|
5
|
+
describe Handcart do
|
|
6
|
+
|
|
7
|
+
it "should not enforce IP Authorization by default" do
|
|
8
|
+
Handcart.ip_authorization_strategy.should_not be_nil
|
|
9
|
+
Handcart.ip_authorization_strategy.should eq(:inclusion)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should have an IP Authorization singleton" do
|
|
13
|
+
Handcart.ip_authorization.should_not be_nil
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should enable global ip blocking in development and production" do
|
|
17
|
+
Handcart.global_ip_blocking_enabled_environments.should include("development")
|
|
18
|
+
Handcart.global_ip_blocking_enabled_environments.should include("production")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should disable global ip blocking in test and staging" do
|
|
22
|
+
Handcart.global_ip_blocking_enabled_environments.should_not include("test")
|
|
23
|
+
Handcart.global_ip_blocking_enabled_environments.should_not include("staging")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should enable global ip forwarding in development, staging, and production" do
|
|
27
|
+
Handcart.global_ip_forwarding_enabled_environments.should include("development")
|
|
28
|
+
Handcart.global_ip_forwarding_enabled_environments.should include("staging")
|
|
29
|
+
Handcart.global_ip_forwarding_enabled_environments.should include("production")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should disable global ip forwarding in test" do
|
|
33
|
+
Handcart.global_ip_forwarding_enabled_environments.should_not include("test")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
module Strategies
|
|
5
|
+
describe InclusionStrategy do
|
|
6
|
+
let(:strategy) { InclusionStrategy.new }
|
|
7
|
+
let(:company) { create(:company, name: "Planet Express") }
|
|
8
|
+
|
|
9
|
+
it "should have none for the strategy" do
|
|
10
|
+
strategy.strategy.should eq(:inclusion)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should allow an authorized IP address" do
|
|
14
|
+
native_ip_address = create(:handcart_ip_address, handcart: company, address: '10.10.9.1', subnet_mask: '255.255.255.128', blacklisted: false)
|
|
15
|
+
strategy.is_in_range?(IPAddr.new("10.10.9.8"), company).should eq(true)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should reject an UNAUTHORIZED IP address" do
|
|
19
|
+
native_ip_address = create(:handcart_ip_address, handcart: company, address: '10.10.9.1', subnet_mask: '255.255.255.128', blacklisted: false)
|
|
20
|
+
strategy.is_in_range?(IPAddr.new("10.10.9.253"), company).should eq(false)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should reject an AUTHORIZED BLACKLISTED IP address" do
|
|
24
|
+
native_ip_address = create(:handcart_ip_address, handcart: company, address: '10.10.9.1', subnet_mask: '255.255.255.128', blacklisted: true)
|
|
25
|
+
strategy.is_in_range?(IPAddr.new("10.10.9.8"), company).should eq(false)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
describe IpAddress do
|
|
5
|
+
|
|
6
|
+
describe "concerning validations" do
|
|
7
|
+
it "should have a valid factory" do
|
|
8
|
+
build(:handcart_ip_address).should be_valid
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should require an address" do
|
|
12
|
+
build(:handcart_ip_address, address: nil).should_not be_valid
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should require a unique address" do
|
|
16
|
+
create(:handcart_ip_address, address: "10.10.9.1").should be_valid
|
|
17
|
+
build(:handcart_ip_address, address: "10.10.9.1").should_not be_valid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should require a properly formatted address" do
|
|
21
|
+
build(:handcart_ip_address, address: "256.256.256.256").should_not be_valid
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should require a subnet mask" do
|
|
25
|
+
build(:handcart_ip_address, subnet_mask: nil).should_not be_valid
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should require a properly formatted subnet mask" do
|
|
29
|
+
build(:handcart_ip_address, subnet_mask: "256.256.256.256").should_not be_valid
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should not allow two handcarts to have the same IP" do
|
|
33
|
+
sub_1 = create(:handcart_subdomain, name: 'planet')
|
|
34
|
+
sub_2 = create(:handcart_subdomain, name: 'moms')
|
|
35
|
+
company1 = create(:company, name: "Planet Express", subdomain: sub_1)
|
|
36
|
+
company2 = create(:company, name: "Moms Friendly Robot Company", subdomain: sub_2)
|
|
37
|
+
create(:handcart_ip_address, handcart: company1, address: '10.10.9.1', subnet_mask: '255.255.255.128', blacklisted: false).should be_valid
|
|
38
|
+
build(:handcart_ip_address, handcart: company2, address: '10.10.9.1', subnet_mask: '255.255.255.128', blacklisted: false).should_not be_valid
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "concerning relations" do
|
|
43
|
+
it "should belong to the handcart" do
|
|
44
|
+
company = create(:company, name: "Planet Express")
|
|
45
|
+
ip_address = create(:handcart_ip_address, handcart: company)
|
|
46
|
+
ip_address.handcart.should eq(company)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
describe IpAuthorization do
|
|
5
|
+
it "should set the strategy variable to the engine's strategy" do
|
|
6
|
+
Handcart.ip_authorization.should_not be_nil
|
|
7
|
+
Handcart.ip_authorization.ip_authorization_strategy.should eq(:inclusion)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should set the strategy to a class" do
|
|
11
|
+
Handcart.ip_authorization.should_not be_nil
|
|
12
|
+
Handcart.ip_authorization.strategy.should_not be_nil
|
|
13
|
+
Handcart.ip_authorization.strategy.class.should eq(Handcart::Strategies::InclusionStrategy)
|
|
14
|
+
Handcart.ip_authorization.strategy.strategy.should eq(:inclusion)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
describe Subdomain do
|
|
5
|
+
describe "reserved subdomains" do
|
|
6
|
+
it "can list the reserved subdomains" do
|
|
7
|
+
Handcart.reserved_subdomains.should eq(["www", "ftp", "ssh", "pop3", "staging", "master"])
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should reserved the following subdomains by default" do
|
|
11
|
+
Handcart.reserved_subdomains.should include("www")
|
|
12
|
+
Handcart.reserved_subdomains.should include("ftp")
|
|
13
|
+
Handcart.reserved_subdomains.should include("ssh")
|
|
14
|
+
Handcart.reserved_subdomains.should include("pop3")
|
|
15
|
+
Handcart.reserved_subdomains.should include("staging")
|
|
16
|
+
Handcart.reserved_subdomains.should include("master")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "validations" do
|
|
21
|
+
it "should have a valid factory" do
|
|
22
|
+
build(:handcart_subdomain).should be_valid
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should be valid if the name is not in the exclusion list" do
|
|
26
|
+
build(:handcart_subdomain, name: 'mark').should be_valid
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "concerning invalid characters" do
|
|
31
|
+
it "should remove spaces in the name" do
|
|
32
|
+
create(:handcart_subdomain, name: 'this has spaces').name.should eq("thishasspaces")
|
|
33
|
+
create(:handcart_subdomain, name: 'this has s p aces').name.should eq("thishasspaces")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should remove the '+'' character" do
|
|
37
|
+
create(:handcart_subdomain, name: 'this has a + in it').name.should eq("thishasainit")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should remove the '/' character" do
|
|
41
|
+
create(:handcart_subdomain, name: 'this has a / in it').name.should eq("thishasainit")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should remove the '=' character" do
|
|
45
|
+
create(:handcart_subdomain, name: 'this has a = in it').name.should eq("thishasainit")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should remove the '?' character" do
|
|
49
|
+
create(:handcart_subdomain, name: 'this has a ? in it').name.should eq("thishasainit")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe "invalid subdomains" do
|
|
54
|
+
it "should not be valid if the name is reserved" do
|
|
55
|
+
Handcart.reserved_subdomains.each do |reserved_sub_domain|
|
|
56
|
+
build(:handcart_subdomain, name: reserved_sub_domain).should_not be_valid
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should require a name" do
|
|
61
|
+
build(:handcart_subdomain, name: nil).should_not be_valid
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should require a unique name" do
|
|
65
|
+
create(:handcart_subdomain, name: 'mark').should be_valid
|
|
66
|
+
build(:handcart_subdomain, name: 'mark').should_not be_valid
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should require a unique name regardless of case" do
|
|
70
|
+
create(:handcart_subdomain, name: 'mark').should be_valid
|
|
71
|
+
build(:handcart_subdomain, name: 'MARK').should_not be_valid
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "concerning associations" do
|
|
76
|
+
it "should have one company" do
|
|
77
|
+
subdomain = create(:handcart_subdomain, name: 'mark')
|
|
78
|
+
company = create(:company, subdomain: subdomain)
|
|
79
|
+
subdomain.handcart.should eq(company)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe "concerning scopes" do
|
|
84
|
+
it 'should have an allocated scope' do
|
|
85
|
+
subdomain = create(:handcart_subdomain, name: 'mark')
|
|
86
|
+
company = create(:company, subdomain: subdomain)
|
|
87
|
+
expected = Subdomain.allocated
|
|
88
|
+
expected.should include(subdomain)
|
|
89
|
+
expected.should have(1).entries
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should have an unallocated scope" do
|
|
93
|
+
subdomain = create(:handcart_subdomain, name: 'mark')
|
|
94
|
+
subdomain.handcart.should be_nil
|
|
95
|
+
expected = Subdomain.unallocated
|
|
96
|
+
expected.should include(subdomain)
|
|
97
|
+
expected.should have(1).entries
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should have an unallocated or current scope" do
|
|
101
|
+
unallocated = create(:handcart_subdomain, name: 'mark')
|
|
102
|
+
current = create(:handcart_subdomain, name: 'holmberg')
|
|
103
|
+
company = create(:company, subdomain: current)
|
|
104
|
+
unallocated.handcart.should be_nil
|
|
105
|
+
current.handcart.should_not be_nil
|
|
106
|
+
expected = Subdomain.unallocated_or_current(company)
|
|
107
|
+
expected.should include(current)
|
|
108
|
+
expected.should include(unallocated)
|
|
109
|
+
expected.should have(2).entries
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe "concerning activation of handcarts" do
|
|
115
|
+
describe "concerning handcarts that dont respond_to :active?" do
|
|
116
|
+
before(:each) do
|
|
117
|
+
Company.any_instance.stub(:active?).and_return(true)
|
|
118
|
+
@subdomain = create(:handcart_subdomain, name: 'example')
|
|
119
|
+
@company = create(:company, subdomain: @subdomain, active: true)
|
|
120
|
+
@request = ActionController::TestRequest.new
|
|
121
|
+
@request.host = "example.dummy.dev"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "should return true if the handcart doesnt respond_to :active?" do
|
|
125
|
+
Subdomain.matches?(@request).should eq(true)
|
|
126
|
+
# @company.should_not respond_to(:active?)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe "concering handcarts that do respond_to :active?" do
|
|
131
|
+
before(:each) do
|
|
132
|
+
@subdomain = create(:handcart_subdomain, name: 'example')
|
|
133
|
+
@company = create(:company, subdomain: @subdomain)
|
|
134
|
+
@request = ActionController::TestRequest.new
|
|
135
|
+
@request.host = "example.dummy.dev"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "should return true if it is active" do
|
|
139
|
+
@company.stub(:active?).and_return(true)
|
|
140
|
+
@company.should respond_to(:active?)
|
|
141
|
+
@company.active?.should eq(true)
|
|
142
|
+
Subdomain.matches?(@request).should eq(true)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "should return false if it is NOT active" do
|
|
146
|
+
@company.stub(:active?).and_return(false)
|
|
147
|
+
@company.should respond_to(:active?)
|
|
148
|
+
@company.active?.should eq(false)
|
|
149
|
+
Subdomain.matches?(@request).should eq(true)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
describe IpAddressesController do
|
|
5
|
+
describe "routing" do
|
|
6
|
+
routes { Handcart::Engine.routes }
|
|
7
|
+
|
|
8
|
+
it "routes to #index" do
|
|
9
|
+
get("/ip_addresses").should route_to("handcart/ip_addresses#index")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "routes to #new" do
|
|
13
|
+
get("/ip_addresses/new").should route_to("handcart/ip_addresses#new")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "routes to #show" do
|
|
17
|
+
get("/ip_addresses/1").should route_to("handcart/ip_addresses#show", id: "1")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "routes to #edit" do
|
|
21
|
+
get("/ip_addresses/1/edit").should route_to("handcart/ip_addresses#edit", id: "1")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "routes to #create" do
|
|
25
|
+
post("/ip_addresses").should route_to("handcart/ip_addresses#create")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "routes to #update" do
|
|
29
|
+
put("/ip_addresses/1").should route_to("handcart/ip_addresses#update", id: "1")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "routes to #destroy" do
|
|
33
|
+
delete("/ip_addresses/1").should route_to("handcart/ip_addresses#destroy", id: "1")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
module Handcart
|
|
4
|
+
describe SubdomainsController do
|
|
5
|
+
describe "routing" do
|
|
6
|
+
routes { Handcart::Engine.routes }
|
|
7
|
+
|
|
8
|
+
it "routes to #index" do
|
|
9
|
+
get("/subdomains").should route_to("handcart/subdomains#index")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "routes to #new" do
|
|
13
|
+
get("/subdomains/new").should route_to("handcart/subdomains#new")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "routes to #show" do
|
|
17
|
+
get("/subdomains/1").should route_to("handcart/subdomains#show", id: "1")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "routes to #edit" do
|
|
21
|
+
get("/subdomains/1/edit").should route_to("handcart/subdomains#edit", id: "1")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "routes to #create" do
|
|
25
|
+
post("/subdomains").should route_to("handcart/subdomains#create")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "routes to #update" do
|
|
29
|
+
put("/subdomains/1").should route_to("handcart/subdomains#update", id: "1")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "routes to #destroy" do
|
|
33
|
+
delete("/subdomains/1").should route_to("handcart/subdomains#destroy", id: "1")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|