sslocal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/puma/plugin/sslocal.rb +33 -0
- data/lib/sslocal.rb +11 -0
- data/lib/sslocal/puma_rebinder.rb +74 -0
- data/lib/sslocal/railtie.rb +25 -0
- data/lib/sslocal/state.rb +23 -0
- data/spec/puma/plugin/sslocal_spec.rb +51 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/sslocal/puma_rebinder_spec.rb +79 -0
- data/spec/sslocal/state_spec.rb +61 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fc5b3d34e3f44dc24ac304305a1cbfaf60888ff6496c90a1a4d6142ade226555
|
4
|
+
data.tar.gz: db30eb94f25c9458c6eadb43c8c9fd8a80836bb6bced032647b3116c201a8961
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04fc271a743ddc37ed8976d5900ae7ec3a7dde455af53d894571586b2f97e2ffc2167a72ec0c61c728efb43deaa151f51114f08c5267974e43e7ed6a620dd21a
|
7
|
+
data.tar.gz: ea541b4193a031ac8b3bed4cfcb9a307c4e2a1b5a349f50ec68cadc327097f1c8994a4469245437fd9a016a77d21e38a3130cf3edcf70d65a518eecbf7a02db9
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
inherit_from:
|
2
|
+
- https://gist.githubusercontent.com/pat/ba3b8ffb1901bfe5439b460943b6b019/raw/.rubocop.yml
|
3
|
+
- https://gist.githubusercontent.com/pat/ba3b8ffb1901bfe5439b460943b6b019/raw/performance.yml
|
4
|
+
|
5
|
+
require:
|
6
|
+
- rubocop-packaging
|
7
|
+
- rubocop-performance
|
8
|
+
|
9
|
+
AllCops:
|
10
|
+
TargetRubyVersion: 2.7
|
11
|
+
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
|
+
Enabled: false
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at pat@freelancing-gods.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Pat Allan
|
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,53 @@
|
|
1
|
+
# SSLocal
|
2
|
+
|
3
|
+
SSLocal helps to make running SSL in your local Ruby development environment as streamlined as possible. Currently it's built to work with Rack apps that use Puma (including Rails).
|
4
|
+
|
5
|
+
Please **do not use this gem in production environments** - it's only meant for local development.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Install [mkcert](https://github.com/FiloSottile/mkcert)
|
10
|
+
2. Add `config/certificates` to your application's `.gitignore` file.
|
11
|
+
3. Add this gem to your application's Gemfile - ideally just for the development environment.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "sslocal", group: :development
|
15
|
+
```
|
16
|
+
|
17
|
+
4. Add the following lines to the end of your `config/puma.rb` file - adjusting the environment variable name if appropriate.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
if ENV.fetch("RAILS_ENV", "development") == "development"
|
21
|
+
require "sslocal"
|
22
|
+
plugin :sslocal
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
1. Ensure the `config/certificates` folder exists (`mkdir -p config/certificates`).
|
29
|
+
2. Generate the local certificate via `mkcert`:
|
30
|
+
|
31
|
+
```sh
|
32
|
+
mkcert --cert-file config/certificates/development.crt \
|
33
|
+
--key-file config/certificates/development.key \
|
34
|
+
localhost 127.0.0.1
|
35
|
+
```
|
36
|
+
|
37
|
+
3. Boot your Rack/Rails app (whether via `rails server`, Foreman, Overmind, etc), and it should automatically use SSL using the generated certificate files.
|
38
|
+
|
39
|
+
If you're using SSLocal with a Rails app, it will change your app's settings dynamically to use HTTPS for Webpacker and ActionCable (if they're being used). However, if you are using Webpacker, you'll almost certainly want to install and set up [the SSLocal library for JavaScript](https://github.com/pat/sslocal-js) as well to keep matching protocols.
|
40
|
+
|
41
|
+
If you want to switch back to HTTP, just delete the certificate files and restart your Rack/Rails app. The certificate files are not precious, and can be deleted/regenerated as much as you like.
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pat/sslocal-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/pat/sslocal-rb/blob/master/CODE_OF_CONDUCT.md).
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is copyright Pat Allan, 2020, and is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in SSLocal's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pat/sslocal-rb/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "sslocal"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "puma"
|
4
|
+
require "puma/plugin"
|
5
|
+
require "sslocal/puma_rebinder"
|
6
|
+
|
7
|
+
module Puma
|
8
|
+
class Plugin
|
9
|
+
class SSLocal
|
10
|
+
# Puma 4.x supplies an argument, but 5.x does not. We don't need it
|
11
|
+
# either way.
|
12
|
+
def initialize(_loader = nil); end
|
13
|
+
|
14
|
+
# We don't actually want to modify the configuration here, as it only
|
15
|
+
# impacts the file_config values. user_config values take precedence,
|
16
|
+
# and the only way to cleanly impact those is via the launcher object
|
17
|
+
# supplied in the `start` call.
|
18
|
+
def config(_dsl); end
|
19
|
+
|
20
|
+
# User-provided configuration (command-line arguments, environment
|
21
|
+
# variables) take precedence over file-provided configuration (such as in
|
22
|
+
# config/puma.rb). If there are certificate files present, we want each
|
23
|
+
# configuration to use SSL if appropriate, so we rebind each one.
|
24
|
+
def start(launcher)
|
25
|
+
launcher.config.configure do |user_config, file_config, default_config|
|
26
|
+
::SSLocal::PumaRebinder.call(user_config)
|
27
|
+
::SSLocal::PumaRebinder.call(file_config)
|
28
|
+
::SSLocal::PumaRebinder.call(default_config)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/sslocal.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sslocal/state"
|
4
|
+
|
5
|
+
module SSLocal
|
6
|
+
# Takes a Puma configuration/dsl object, and - if there are any non-SSL TCP
|
7
|
+
# bindings and if the expected certificate files exist - then change those
|
8
|
+
# bindings to use SSL with the certificate files.
|
9
|
+
#
|
10
|
+
# If there's an unexpected binding string, then return to the originally
|
11
|
+
# supplied bindings.
|
12
|
+
class PumaRebinder
|
13
|
+
UnexpectedBindFormat = Class.new(StandardError)
|
14
|
+
|
15
|
+
def self.call(dsl)
|
16
|
+
new(dsl).call
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(dsl)
|
20
|
+
@dsl = dsl
|
21
|
+
@binds = dsl.get(:binds)
|
22
|
+
end
|
23
|
+
|
24
|
+
def call
|
25
|
+
return if binds.nil?
|
26
|
+
return unless state.enabled?
|
27
|
+
|
28
|
+
dsl.clear_binds!
|
29
|
+
rebind
|
30
|
+
rescue UnexpectedBindFormat => error
|
31
|
+
puts "SSLocal: ssl not enabled due to #{error.message}"
|
32
|
+
reset
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :dsl, :binds
|
38
|
+
|
39
|
+
def environment
|
40
|
+
@environment ||= dsl.get(:environment)
|
41
|
+
end
|
42
|
+
|
43
|
+
def host_and_port(bind)
|
44
|
+
matches = bind.scan(%r{\Atcp://(.*):(\d+)\z}).first
|
45
|
+
if matches.nil? || matches.length != 2
|
46
|
+
raise UnexpectedBindFormat, "unexpected bind format #{bind}"
|
47
|
+
end
|
48
|
+
|
49
|
+
matches.first.empty? ? ["0.0.0.0", matches.last] : matches
|
50
|
+
end
|
51
|
+
|
52
|
+
def rebind
|
53
|
+
binds.each do |bind|
|
54
|
+
if bind.start_with?("tcp://")
|
55
|
+
dsl.ssl_bind(
|
56
|
+
*host_and_port(bind),
|
57
|
+
:key => state.key_path, :cert => state.cert_path
|
58
|
+
)
|
59
|
+
else
|
60
|
+
dsl.bind(bind)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def reset
|
66
|
+
dsl.clear_binds!
|
67
|
+
binds.each { |bind| dsl.bind(bind) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def state
|
71
|
+
@state ||= ::SSLocal::State.new(environment)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sslocal/state"
|
4
|
+
|
5
|
+
module SSLocal
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer "sslocal.set_up_webpacker", :before => "webpacker.proxy" do
|
8
|
+
state = SSLocal::State.new(Rails.env.to_s)
|
9
|
+
Webpacker.config.dev_server[:https] = true if state.enabled?
|
10
|
+
end
|
11
|
+
|
12
|
+
config.after_initialize do |app|
|
13
|
+
state = SSLocal::State.new(Rails.env.to_s)
|
14
|
+
next unless state.enabled?
|
15
|
+
|
16
|
+
policy = app.config.content_security_policy&.connect_src
|
17
|
+
next if policy.blank?
|
18
|
+
|
19
|
+
secure_policy = policy.collect do |item|
|
20
|
+
item.gsub("http://", "https://").gsub("ws://", "wss://")
|
21
|
+
end
|
22
|
+
app.config.content_security_policy.connect_src(*secure_policy)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SSLocal
|
4
|
+
class State
|
5
|
+
attr_reader :environment
|
6
|
+
|
7
|
+
def initialize(environment)
|
8
|
+
@environment = environment
|
9
|
+
end
|
10
|
+
|
11
|
+
def cert_path
|
12
|
+
File.expand_path("config/certificates/#{environment}.crt")
|
13
|
+
end
|
14
|
+
|
15
|
+
def enabled?
|
16
|
+
File.exist?(key_path) && File.exist?(cert_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def key_path
|
20
|
+
File.expand_path("config/certificates/#{environment}.key")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "puma/plugin/sslocal"
|
4
|
+
|
5
|
+
RSpec.describe Puma::Plugin::SSLocal do
|
6
|
+
it "responds to initialize without an argument" do
|
7
|
+
expect { described_class.new }.to_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "responds to initialize with an argument" do
|
11
|
+
expect { described_class.new double }.to_not raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
it "responds to config" do
|
15
|
+
expect { subject.config double }.to_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#start" do
|
19
|
+
let(:launcher) { double(:launcher, :config => configuration) }
|
20
|
+
let(:configuration) { double(:configuration) }
|
21
|
+
let(:user_config) { double }
|
22
|
+
let(:file_config) { double }
|
23
|
+
let(:default_config) { double }
|
24
|
+
let(:rebinder) { double(:rebinder, :call => nil) }
|
25
|
+
|
26
|
+
before :each do
|
27
|
+
allow(configuration).to receive(:configure).
|
28
|
+
and_yield(user_config, file_config, default_config)
|
29
|
+
|
30
|
+
stub_const("SSLocal::PumaRebinder", rebinder)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "rebinds the user configuration" do
|
34
|
+
subject.start(launcher)
|
35
|
+
|
36
|
+
expect(rebinder).to have_received(:call).with(user_config)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "rebinds the file configuration" do
|
40
|
+
subject.start(launcher)
|
41
|
+
|
42
|
+
expect(rebinder).to have_received(:call).with(file_config)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "rebinds the default configuration" do
|
46
|
+
subject.start(launcher)
|
47
|
+
|
48
|
+
expect(rebinder).to have_received(:call).with(default_config)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sslocal"
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
# Enable flags like --only-failures and --next-failure
|
7
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
8
|
+
|
9
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
10
|
+
config.disable_monkey_patching!
|
11
|
+
|
12
|
+
config.expect_with :rspec do |c|
|
13
|
+
c.syntax = :expect
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sslocal/puma_rebinder"
|
4
|
+
|
5
|
+
RSpec.describe SSLocal::PumaRebinder do
|
6
|
+
let(:dsl) do
|
7
|
+
double(:dsl, :clear_binds! => nil, :ssl_bind => nil, :bind => nil)
|
8
|
+
end
|
9
|
+
let(:binds) { ["tcp://0.0.0.0:3000"] }
|
10
|
+
let(:state) do
|
11
|
+
double(:state, :enabled? => true, :key_path => "my.key",
|
12
|
+
:cert_path => "my.crt")
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { described_class }
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
allow(dsl).to receive(:get).with(:binds).and_return(binds)
|
19
|
+
allow(dsl).to receive(:get).with(:environment).and_return("test")
|
20
|
+
|
21
|
+
allow(SSLocal::State).to receive(:new).and_return(state)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does nothing if there are no binds" do
|
25
|
+
allow(dsl).to receive(:get).with(:binds).and_return(nil)
|
26
|
+
|
27
|
+
subject.call dsl
|
28
|
+
|
29
|
+
expect(dsl).to_not have_received(:clear_binds!)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "loads the state for the supplied environment" do
|
33
|
+
subject.call dsl
|
34
|
+
|
35
|
+
expect(SSLocal::State).to have_received(:new).with("test")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "does nothing if the state is disabled" do
|
39
|
+
allow(state).to receive(:enabled?).and_return(false)
|
40
|
+
|
41
|
+
subject.call dsl
|
42
|
+
|
43
|
+
expect(dsl).to_not have_received(:clear_binds!)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "replaces TCP bindings with SSL" do
|
47
|
+
subject.call dsl
|
48
|
+
|
49
|
+
expect(dsl).to have_received(:ssl_bind).with(
|
50
|
+
"0.0.0.0", "3000", :key => "my.key", :cert => "my.crt"
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "does not modify unix bindings" do
|
55
|
+
allow(dsl).to receive(:get).with(:binds).and_return(["unix:///path.socket"])
|
56
|
+
|
57
|
+
subject.call dsl
|
58
|
+
|
59
|
+
expect(dsl).to have_received(:bind).with("unix:///path.socket")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "uses 0.0.0.0 if the binding does not specify a host" do
|
63
|
+
allow(dsl).to receive(:get).with(:binds).and_return(["tcp://:4000"])
|
64
|
+
|
65
|
+
subject.call dsl
|
66
|
+
|
67
|
+
expect(dsl).to have_received(:ssl_bind).with(
|
68
|
+
"0.0.0.0", "4000", :key => "my.key", :cert => "my.crt"
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "does not modify any bindings if there's an unknown TCP format" do
|
73
|
+
allow(dsl).to receive(:get).with(:binds).and_return(["tcp://foo"])
|
74
|
+
|
75
|
+
subject.call dsl
|
76
|
+
|
77
|
+
expect(dsl).to have_received(:bind).with("tcp://foo")
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "sslocal/state"
|
4
|
+
|
5
|
+
RSpec.describe SSLocal::State do
|
6
|
+
subject { described_class.new "test" }
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
allow(File).to receive(:exist?).and_return(false)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#enabled?" do
|
13
|
+
it "returns true if both files exist" do
|
14
|
+
allow(File).to receive(:exist?).with(
|
15
|
+
File.expand_path("config/certificates/test.key")
|
16
|
+
).and_return(true)
|
17
|
+
|
18
|
+
allow(File).to receive(:exist?).with(
|
19
|
+
File.expand_path("config/certificates/test.crt")
|
20
|
+
).and_return(true)
|
21
|
+
|
22
|
+
expect(subject).to be_enabled
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns false if only the key file exists" do
|
26
|
+
allow(File).to receive(:exist?).with(
|
27
|
+
File.expand_path("config/certificates/test.key")
|
28
|
+
).and_return(true)
|
29
|
+
|
30
|
+
allow(File).to receive(:exist?).with(
|
31
|
+
File.expand_path("config/certificates/test.crt")
|
32
|
+
).and_return(false)
|
33
|
+
|
34
|
+
expect(subject).to_not be_enabled
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns false if only the cert file exists" do
|
38
|
+
allow(File).to receive(:exist?).with(
|
39
|
+
File.expand_path("config/certificates/test.key")
|
40
|
+
).and_return(false)
|
41
|
+
|
42
|
+
allow(File).to receive(:exist?).with(
|
43
|
+
File.expand_path("config/certificates/test.crt")
|
44
|
+
).and_return(true)
|
45
|
+
|
46
|
+
expect(subject).to_not be_enabled
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns false if neither file exists" do
|
50
|
+
allow(File).to receive(:exist?).with(
|
51
|
+
File.expand_path("config/certificates/test.key")
|
52
|
+
).and_return(false)
|
53
|
+
|
54
|
+
allow(File).to receive(:exist?).with(
|
55
|
+
File.expand_path("config/certificates/test.crt")
|
56
|
+
).and_return(false)
|
57
|
+
|
58
|
+
expect(subject).to_not be_enabled
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sslocal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pat Allan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: puma
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: '3.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-packaging
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-performance
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- pat@freelancing-gods.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".rspec"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/puma/plugin/sslocal.rb
|
100
|
+
- lib/sslocal.rb
|
101
|
+
- lib/sslocal/puma_rebinder.rb
|
102
|
+
- lib/sslocal/railtie.rb
|
103
|
+
- lib/sslocal/state.rb
|
104
|
+
- spec/puma/plugin/sslocal_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/sslocal/puma_rebinder_spec.rb
|
107
|
+
- spec/sslocal/state_spec.rb
|
108
|
+
homepage: https://github.com/pat/sslocal-rb
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://github.com/pat/sslocal-rb
|
113
|
+
source_code_uri: https://github.com/pat/sslocal-rb
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubygems_version: 3.1.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Make local environment SSL as streamlined as possible.
|
133
|
+
test_files:
|
134
|
+
- bin/setup
|
135
|
+
- bin/console
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
- spec/puma/plugin/sslocal_spec.rb
|
138
|
+
- spec/sslocal/state_spec.rb
|
139
|
+
- spec/sslocal/puma_rebinder_spec.rb
|
140
|
+
- ".rspec"
|
141
|
+
- ".rubocop.yml"
|
142
|
+
- Gemfile
|
143
|
+
- Rakefile
|