pco-url 2.1.3 → 3.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a47c1ef878b865141332322e7f958d66fab196eae64291067e391185fdb6b0e3
4
- data.tar.gz: 072b303a7a0f34857339bc3ca5b87558656ba4f23e2226b9b83bcc056ad6e50a
3
+ metadata.gz: '0687cb14bb063264a30307b10d9b6efcb49d8f4cbf77b711b15192fe35217048'
4
+ data.tar.gz: ece4ec24c39990c45bf02e44a564a6f9bc460af66348bdd5e97166319252612f
5
5
  SHA512:
6
- metadata.gz: 273a73234504876c551343c81410a333a59e9859de1ddf5e2740eafc87f6a046ed255838f472ffbc66b166ab524058152a15f109a6c2a2ba3891ca96cb62e425
7
- data.tar.gz: dee2c23967f577864f39e87d6605e207733b592edc8221c10fe1f5e9e19123380c65585a8247d53245f13f9d1fae7a53f61189e2c1c45703e624f16956f2586e
6
+ metadata.gz: 55eaac7abd9b009155137ee6cbfa8a339296bab1fbeb409dca080921591c6e623921f3d3accb6981e3552f1029a7d1ee4b4ec1984944112e5a4d74e198aa856b
7
+ data.tar.gz: acb674cba783b53cfe924ac820b8b5a67af7db82c0d5f399aeb81c8faabe9a3eac6a39e03322fb1fb40ef090ee8f943db784098c7572dc191a0eadbd61f92d1c
data/.circleci/config.yml CHANGED
@@ -17,7 +17,7 @@ workflows:
17
17
  jobs:
18
18
  build:
19
19
  docker:
20
- - image: circleci/ruby:2.5
20
+ - image: circleci/ruby:2.7
21
21
  environment:
22
22
  BUNDLE_JOBS: 3
23
23
  BUNDLE_RETRY: 3
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5
1
+ 2.7
data/Appraisals CHANGED
@@ -1,15 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "rails-5.0" do
4
- gem "rails", "~> 5.0.0"
5
- gem "sqlite3", "< 1.4"
6
- end
7
-
8
- appraise "rails-5.1" do
9
- gem "rails", "~> 5.1.0"
10
- gem "sqlite3", "< 1.4"
11
- end
12
-
13
3
  appraise "rails-5.2" do
14
4
  gem "rails", "~> 5.2.0"
15
5
  end
@@ -17,3 +7,11 @@ end
17
7
  appraise "rails-6.0" do
18
8
  gem "rails", "~> 6.0.0"
19
9
  end
10
+
11
+ appraise "rails-6.1" do
12
+ gem "rails", "~> 6.1.0"
13
+ end
14
+
15
+ appraise "rails-edge" do
16
+ gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
17
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v3.0.0 (2021-02-25)
2
+
3
+ * Feature: add middleware in production/staging to maintain second-level domain, e.g. planningcenter.com when generating URLs
4
+ * Chore: test on more modern versions of Ruby and Rails
5
+
1
6
  # v2.1.3 (2020-01-14)
2
7
 
3
8
  * Chore: no code changes; just bumping the version and rebuilding the gem file with proper file permissions [Tim Morgan]
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.0.0"
6
- gem "sqlite3", "< 1.4"
5
+ gem "rails", "~> 6.1.0"
7
6
 
8
7
  gemspec path: "../"
@@ -2,7 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.1.0"
6
- gem "sqlite3", "< 1.4"
5
+ gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
7
6
 
8
7
  gemspec path: "../"
data/lib/pco/url.rb CHANGED
@@ -7,6 +7,13 @@ require "uri"
7
7
 
8
8
  module PCO
9
9
  class URL
10
+ DOMAINS = {
11
+ 'development' => %w[pco.test pco.codes],
12
+ 'test' => %w[pco.test pco.codes],
13
+ 'staging' => %w[planningcenteronline.com planningcenter.com],
14
+ 'production' => %w[planningcenteronline.com planningcenter.com],
15
+ }.freeze
16
+
10
17
  class << self
11
18
  def decrypt_query_params(string)
12
19
  Encryption.decrypt(string)
@@ -82,13 +89,15 @@ module PCO
82
89
  def domain
83
90
  return @domain if @domain
84
91
 
92
+ return PCO::URL::Engine.domain if PCO::URL::Engine.domain
93
+
85
94
  case env
86
95
  when "production", "staging"
87
96
  "planningcenteronline.com"
88
97
  when "test"
89
98
  "pco.test"
90
99
  when "development"
91
- PCO::URL::Engine.domain || "pco.test"
100
+ "pco.test"
92
101
  end
93
102
  end
94
103
 
@@ -12,7 +12,7 @@ module PCO
12
12
  end
13
13
 
14
14
  initializer "pco_url.add_middleware" do |app|
15
- app.middleware.use PCO::URL::Engine::DomainMiddleware if Rails.env.development? || Rails.env.test?
15
+ app.middleware.use PCO::URL::Engine::DomainMiddleware
16
16
  end
17
17
  end
18
18
  end
@@ -11,7 +11,8 @@ module PCO
11
11
  end
12
12
 
13
13
  def call(env)
14
- PCO::URL::Engine.domain = env["SERVER_NAME"].downcase.match(/[a-z0-9-]+\.[a-z]+$/).to_s
14
+ domain = env["SERVER_NAME"].downcase.match(/[a-z0-9-]+\.[a-z]+$/).to_s
15
+ PCO::URL::Engine.domain = PCO::URL::DOMAINS[Rails.env].include?(domain) ? domain : nil
15
16
  @app.call(env)
16
17
  end
17
18
  end
@@ -1,5 +1,5 @@
1
1
  module PCO
2
2
  class URL
3
- VERSION = "2.1.3".freeze
3
+ VERSION = "3.0.0".freeze
4
4
  end
5
5
  end
@@ -8,7 +8,19 @@ require "pco/url"
8
8
  module Dummy
9
9
  class Application < Rails::Application
10
10
  config.eager_load = false
11
- config.hosts << /accounts\.pco\.(test|codes)/ if Rails::VERSION::MAJOR >= 6
11
+ if Rails::VERSION::MAJOR >= 6
12
+ config.hosts << "accounts.pco.test"
13
+ config.hosts << "accounts.pco.codes"
14
+ config.hosts << "accounts.planningcenteronline.com"
15
+ config.hosts << "accounts.planningcenter.com"
16
+ config.hosts << "accounts-staging.planningcenteronline.com"
17
+ config.hosts << "accounts-staging.planningcenter.com"
18
+
19
+ # We would obviously never have this in a real Rails app, but we need it here
20
+ # to test that PCO::URL cannot get tricked by a bad host, should an attacker
21
+ # somehow sneak one through by some other means.
22
+ config.hosts << "accounts.evilplanningcenter.com"
23
+ end
12
24
  config.secret_key_base = "123abc"
13
25
  end
14
26
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe PCO::URL::Engine::DomainMiddleware, type: :request do
4
- context "in development mode" do
6
+ context "in development" do
5
7
  before do
6
8
  ENV["DEPLOY_ENV"] = Rails.env = "development"
7
9
  end
@@ -10,48 +12,51 @@ describe PCO::URL::Engine::DomainMiddleware, type: :request do
10
12
  host! "accounts.pco.test"
11
13
  get "/test"
12
14
  expect(response.body).to eq("http://people.pco.test")
15
+
13
16
  host! "accounts.pco.codes"
14
17
  get "/test"
15
18
  expect(response.body).to eq("http://people.pco.codes")
16
19
  end
17
20
  end
18
21
 
19
- context "in test mode" do
22
+ context "in staging" do
20
23
  before do
21
- ENV["DEPLOY_ENV"] = Rails.env = "test"
24
+ ENV["DEPLOY_ENV"] = Rails.env = "staging"
22
25
  end
23
26
 
24
27
  it "sets the generated URL domain to be the same as the host" do
25
- host! "accounts.pco.test"
26
- get "/test"
27
- expect(response.body).to eq("http://people.pco.test")
28
- host! "accounts.pco.codes"
28
+ host! "accounts-staging.planningcenteronline.com"
29
29
  get "/test"
30
- expect(response.body).to eq("http://people.pco.test")
31
- end
32
- end
33
-
34
- context "in staging mode" do
35
- before do
36
- ENV["DEPLOY_ENV"] = Rails.env = "staging"
37
- end
30
+ expect(response.body).to eq("https://people-staging.planningcenteronline.com")
38
31
 
39
- it "does not change the domain based on host" do
40
- host! "accounts.pco.test"
32
+ host! "accounts-staging.planningcenter.com"
41
33
  get "/test"
42
- expect(response.body).to eq("https://people-staging.planningcenteronline.com")
34
+ expect(response.body).to eq("https://people-staging.planningcenter.com")
43
35
  end
44
36
  end
45
37
 
46
- context "in production mode" do
38
+ context "in production" do
47
39
  before do
48
40
  ENV["DEPLOY_ENV"] = Rails.env = "production"
49
41
  end
50
42
 
51
- it "does not change the domain based on host" do
52
- host! "accounts.pco.test"
43
+ it "sets the generated URL domain to be the same as the host" do
44
+ host! "accounts.planningcenteronline.com"
53
45
  get "/test"
54
46
  expect(response.body).to eq("https://people.planningcenteronline.com")
47
+
48
+ host! "accounts.planningcenter.com"
49
+ get "/test"
50
+ expect(response.body).to eq("https://people.planningcenter.com")
51
+ end
52
+
53
+ context "when the host is something unrecognized" do
54
+ before { host! "accounts.evilplanningcenter.com" }
55
+
56
+ it "sets the generated URL domain to be .planningcenteronline.com" do
57
+ get "/test"
58
+ expect(response.body).to eq("https://people.planningcenteronline.com")
59
+ end
55
60
  end
56
61
  end
57
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pco-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Miller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-14 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -128,10 +128,10 @@ files:
128
128
  - LICENSE.txt
129
129
  - README.md
130
130
  - Rakefile
131
- - gemfiles/rails_5.0.gemfile
132
- - gemfiles/rails_5.1.gemfile
133
131
  - gemfiles/rails_5.2.gemfile
134
132
  - gemfiles/rails_6.0.gemfile
133
+ - gemfiles/rails_6.1.gemfile
134
+ - gemfiles/rails_edge.gemfile
135
135
  - lib/pco/url.rb
136
136
  - lib/pco/url/church_center.rb
137
137
  - lib/pco/url/encryption.rb
@@ -146,7 +146,7 @@ files:
146
146
  - spec/pco/url/church_center_spec.rb
147
147
  - spec/pco/url/encryption_spec.rb
148
148
  - spec/pco_url_spec.rb
149
- - spec/requests/dev_domain_spec.rb
149
+ - spec/requests/domain_middleware_spec.rb
150
150
  - spec/spec_helper.rb
151
151
  homepage: https://github.com/ministrycentered/pco-url
152
152
  licenses:
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubygems_version: 3.0.6
170
+ rubygems_version: 3.2.6
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Generate URLs for PCO apps in all environments
@@ -178,5 +178,5 @@ test_files:
178
178
  - spec/pco/url/church_center_spec.rb
179
179
  - spec/pco/url/encryption_spec.rb
180
180
  - spec/pco_url_spec.rb
181
- - spec/requests/dev_domain_spec.rb
181
+ - spec/requests/domain_middleware_spec.rb
182
182
  - spec/spec_helper.rb