pco-url 2.0.0 → 2.1.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 +5 -5
- data/.gitignore +1 -0
- data/CHANGELOG.md +12 -0
- data/lib/pco/url.rb +2 -1
- data/lib/pco/url/encryption.rb +6 -1
- data/lib/pco/url/engine.rb +19 -0
- data/lib/pco/url/engine/domain_middleware.rb +16 -0
- data/lib/pco/url/version.rb +1 -1
- data/pco-url.gemspec +2 -0
- data/spec/dummy/config/application.rb +22 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/pco/url/encryption_spec.rb +10 -0
- data/spec/requests/dev_domain_spec.rb +57 -0
- data/spec/spec_helper.rb +4 -6
- metadata +39 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4731a995e9e8f3944ba316db910452830ba0a0606f0a9cc07db1a6a51ef7890c
|
4
|
+
data.tar.gz: 436e8ac79dcfe60f89d81676b5b2149269561510e827c90548f2d3c804dd5f1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d587df8300f3b0ff06db697ee73a7c6375a6e1b29122cb67a0730691fb56da073d466fce254f76fee308c17500beeca68731179d02eb18510fbb3b7f265153e5
|
7
|
+
data.tar.gz: b1fc2d8431d4b6abe9b0b21ddef546c095de4b0afdb7d7e168dce643a168dc9bad1692739d3219326a641db467e9a11d6801d44e00c29d3f9d2cacb287267d3c
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# v2.1.0 (2019-11-05)
|
2
|
+
|
3
|
+
* Feature: Add support in dev for any TLD [Tim Morgan]
|
4
|
+
|
5
|
+
# v2.0.2 (2019-01-21)
|
6
|
+
|
7
|
+
* Fix: Repair downcased encrypted params even better
|
8
|
+
|
9
|
+
# v2.0.1 (2013-01-21)
|
10
|
+
|
11
|
+
* Fix: Repair downcased encrypted params
|
12
|
+
|
1
13
|
# v2.0.0 (2018-09-21)
|
2
14
|
|
3
15
|
* Chore: inline URLcrypt for threadsafety
|
data/lib/pco/url.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative "url/version"
|
|
2
2
|
require_relative "url/church_center"
|
3
3
|
require_relative "url/get"
|
4
4
|
require_relative "url/encryption"
|
5
|
+
require_relative "url/engine"
|
5
6
|
require "uri"
|
6
7
|
|
7
8
|
module PCO
|
@@ -85,7 +86,7 @@ module PCO
|
|
85
86
|
when "production", "staging"
|
86
87
|
"planningcenteronline.com"
|
87
88
|
when "development", "test"
|
88
|
-
"pco.test"
|
89
|
+
PCO::URL::Engine.domain || "pco.test"
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
data/lib/pco/url/encryption.rb
CHANGED
@@ -75,7 +75,7 @@ module PCO
|
|
75
75
|
|
76
76
|
def decrypt(data, key: @default_key)
|
77
77
|
raise MissingKeyError, "default key or key: argument must be set" if key.nil?
|
78
|
-
iv, encrypted = data.split("Z").map { |part| decode(part) }
|
78
|
+
iv, encrypted = case_corrected(data).split("Z").map { |part| decode(part) }
|
79
79
|
raise DecryptError, "not a valid string to decrypt" unless iv && encrypted
|
80
80
|
decrypter = cipher(:decrypt, key: key)
|
81
81
|
decrypter.iv = iv
|
@@ -91,6 +91,11 @@ module PCO
|
|
91
91
|
|
92
92
|
private
|
93
93
|
|
94
|
+
def case_corrected(data)
|
95
|
+
return data unless data[26] == "z"
|
96
|
+
data.tr("a", "A").sub(/\A([#{TABLE}]{26})z/, '\1Z')
|
97
|
+
end
|
98
|
+
|
94
99
|
def chunks(str, size)
|
95
100
|
result = []
|
96
101
|
bytes = str.bytes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "./engine/domain_middleware"
|
2
|
+
|
3
|
+
module PCO
|
4
|
+
class URL
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
def self.domain
|
7
|
+
Thread.current[:pco_url_domain]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.domain=(d)
|
11
|
+
Thread.current[:pco_url_domain] = d
|
12
|
+
end
|
13
|
+
|
14
|
+
initializer "pco_url.add_middleware" do |app|
|
15
|
+
app.middleware.use PCO::URL::Engine::DomainMiddleware if Rails.env.development? || Rails.env.test?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PCO
|
2
|
+
class URL
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
class DomainMiddleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
PCO::URL::Engine.domain = env["SERVER_NAME"].downcase.match(/[a-z0-9-]+\.[a-z]+$/).to_s
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/pco/url/version.rb
CHANGED
data/pco-url.gemspec
CHANGED
@@ -18,7 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rails", "~> 5.0"
|
21
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
23
|
spec.add_development_dependency "rspec", ">= 3.0.0", "< 4"
|
24
|
+
spec.add_development_dependency "rspec-rails", "~> 3.9.0"
|
23
25
|
spec.add_development_dependency "rubocop", "0.54.0"
|
24
26
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "./boot"
|
2
|
+
require "action_controller/railtie"
|
3
|
+
|
4
|
+
require 'pco/url'
|
5
|
+
|
6
|
+
module Dummy
|
7
|
+
class Application < Rails::Application
|
8
|
+
config.eager_load = false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Dummy::Application.initialize!
|
13
|
+
|
14
|
+
class TestsController < ActionController::Base
|
15
|
+
def show
|
16
|
+
render plain: PCO::URL.people
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Rails.application.routes.draw do
|
21
|
+
resource :test
|
22
|
+
end
|
@@ -30,6 +30,16 @@ describe PCO::URL::Encryption do
|
|
30
30
|
|
31
31
|
expect(described_class.decrypt(encrypted)).to eq("Horseman")
|
32
32
|
end
|
33
|
+
|
34
|
+
context "when the encrypted string gets downcased for some dumb reason" do
|
35
|
+
it "decrypts correctly" do
|
36
|
+
described_class.default_key = TEST_DEFAULT_KEY
|
37
|
+
encrypted = described_class.encrypt("Butterscotch").downcase
|
38
|
+
decrypted = described_class.decrypt(encrypted)
|
39
|
+
|
40
|
+
expect(decrypted).to eq("Butterscotch")
|
41
|
+
end
|
42
|
+
end
|
33
43
|
end
|
34
44
|
|
35
45
|
context "when no default key is set" do
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PCO::URL::Engine::DomainMiddleware, type: :request do
|
4
|
+
context "in development mode" do
|
5
|
+
before do
|
6
|
+
ENV["DEPLOY_ENV"] = Rails.env = "development"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "sets the generated URL domain to be the same as the host" do
|
10
|
+
host! "accounts.pco.test"
|
11
|
+
get "/test"
|
12
|
+
expect(response.body).to eq("http://people.pco.test")
|
13
|
+
host! "accounts.pco.codes"
|
14
|
+
get "/test"
|
15
|
+
expect(response.body).to eq("http://people.pco.codes")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "in test mode" do
|
20
|
+
before do
|
21
|
+
ENV["DEPLOY_ENV"] = Rails.env = "test"
|
22
|
+
end
|
23
|
+
|
24
|
+
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"
|
29
|
+
get "/test"
|
30
|
+
expect(response.body).to eq("http://people.pco.codes")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "in staging mode" do
|
35
|
+
before do
|
36
|
+
ENV["DEPLOY_ENV"] = Rails.env = "staging"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "does not change the domain based on host" do
|
40
|
+
host! "accounts.pco.test"
|
41
|
+
get "/test"
|
42
|
+
expect(response.body).to eq("https://people-staging.planningcenteronline.com")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "in production mode" do
|
47
|
+
before do
|
48
|
+
ENV["DEPLOY_ENV"] = Rails.env = "production"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does not change the domain based on host" do
|
52
|
+
host! "accounts.pco.test"
|
53
|
+
get "/test"
|
54
|
+
expect(response.body).to eq("https://people.planningcenteronline.com")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require "rails"
|
2
|
+
require File.expand_path("dummy/config/application", __dir__)
|
3
|
+
|
1
4
|
require "rspec"
|
5
|
+
require "rspec/rails"
|
2
6
|
require "pco/url"
|
3
7
|
|
4
8
|
RSpec.configure do |config|
|
@@ -11,9 +15,3 @@ RSpec.configure do |config|
|
|
11
15
|
PCO::URL::Encryption.remove_instance_variable(:@default_key)
|
12
16
|
end
|
13
17
|
end
|
14
|
-
|
15
|
-
class Rails
|
16
|
-
class << self
|
17
|
-
attr_accessor :env
|
18
|
-
end
|
19
|
-
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.
|
4
|
+
version: 2.1.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:
|
11
|
+
date: 2019-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +72,20 @@ dependencies:
|
|
58
72
|
- - "<"
|
59
73
|
- !ruby/object:Gem::Version
|
60
74
|
version: '4'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec-rails
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 3.9.0
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 3.9.0
|
61
89
|
- !ruby/object:Gem::Dependency
|
62
90
|
name: rubocop
|
63
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,13 +120,18 @@ files:
|
|
92
120
|
- lib/pco/url.rb
|
93
121
|
- lib/pco/url/church_center.rb
|
94
122
|
- lib/pco/url/encryption.rb
|
123
|
+
- lib/pco/url/engine.rb
|
124
|
+
- lib/pco/url/engine/domain_middleware.rb
|
95
125
|
- lib/pco/url/get.rb
|
96
126
|
- lib/pco/url/version.rb
|
97
127
|
- pco-url.gemspec
|
98
128
|
- spec/.rubocop.yml
|
129
|
+
- spec/dummy/config/application.rb
|
130
|
+
- spec/dummy/config/boot.rb
|
99
131
|
- spec/pco/url/church_center_spec.rb
|
100
132
|
- spec/pco/url/encryption_spec.rb
|
101
133
|
- spec/pco_url_spec.rb
|
134
|
+
- spec/requests/dev_domain_spec.rb
|
102
135
|
- spec/spec_helper.rb
|
103
136
|
homepage: https://github.com/ministrycentered/pco-url
|
104
137
|
licenses:
|
@@ -119,14 +152,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
152
|
- !ruby/object:Gem::Version
|
120
153
|
version: '0'
|
121
154
|
requirements: []
|
122
|
-
|
123
|
-
rubygems_version: 2.5.2.3
|
155
|
+
rubygems_version: 3.0.6
|
124
156
|
signing_key:
|
125
157
|
specification_version: 4
|
126
158
|
summary: Generate URLs for PCO apps in all environments
|
127
159
|
test_files:
|
128
160
|
- spec/.rubocop.yml
|
161
|
+
- spec/dummy/config/application.rb
|
162
|
+
- spec/dummy/config/boot.rb
|
129
163
|
- spec/pco/url/church_center_spec.rb
|
130
164
|
- spec/pco/url/encryption_spec.rb
|
131
165
|
- spec/pco_url_spec.rb
|
166
|
+
- spec/requests/dev_domain_spec.rb
|
132
167
|
- spec/spec_helper.rb
|