certmeister-rack 1.0.1 → 1.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 +4 -4
- data/lib/certmeister/rack/self_test_app.rb +34 -0
- data/spec/certmeister/rack/self_test_app_spec.rb +63 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d16f63fef2111a2c8baeb24bb3fd4124fa804878
|
4
|
+
data.tar.gz: c80adc761adc3c5aea86abc42871e86435bbb1cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16c7e9d4809dedc1649ac1bd94b8e6263c4c2718bda4241d0fcf4e16d6f704ecb31d038267788d1abbc9cc6124d9262b94fc8c208bc3c817ab4796bda73feb5c
|
7
|
+
data.tar.gz: aaa450b7b30569f2246265ea2e8e7c002478dc6190dcc3a5284bfb98688994eadcea4d70aa198c4602b0b1a0a384935c6364ea70dd00b922354b8a066b4e2673
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Certmeister
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
|
5
|
+
class SelfTestApp
|
6
|
+
|
7
|
+
def initialize(self_test)
|
8
|
+
@self_test = self_test
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
res = @self_test.test
|
13
|
+
if res.ok?
|
14
|
+
ok
|
15
|
+
else
|
16
|
+
service_unavailable(res.message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def ok(body = '200 OK', content_type = 'text/plain')
|
23
|
+
[200, {'Content-Type' => content_type}, [body]]
|
24
|
+
end
|
25
|
+
|
26
|
+
def service_unavailable(reason)
|
27
|
+
[503, {'Content-Type' => 'text/plain'}, [reason]]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'helpers/certmeister_config_helper'
|
4
|
+
|
5
|
+
require 'certmeister'
|
6
|
+
require 'certmeister/rack/self_test_app'
|
7
|
+
|
8
|
+
describe Certmeister::Rack::SelfTestApp do
|
9
|
+
|
10
|
+
include Rack::Test::Methods
|
11
|
+
|
12
|
+
let(:response) { double(Certmeister::Response).as_null_object }
|
13
|
+
let(:ca) { Certmeister.new(CertmeisterConfigHelper::valid_config) }
|
14
|
+
let(:self_test) { Certmeister::SelfTest.new(ca, File.read('fixtures/client.key')) }
|
15
|
+
let(:app) { Certmeister::Rack::SelfTestApp.new(self_test) }
|
16
|
+
|
17
|
+
describe "GET /test" do
|
18
|
+
|
19
|
+
context "when the CA is functioning" do
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
#allow(ca).to receive(sign).and_raise("Nobody expects the Spanish Inquisition!")
|
23
|
+
get "/test"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns 200" do
|
27
|
+
expect(last_response.status).to eql 200
|
28
|
+
end
|
29
|
+
|
30
|
+
it "describes the HTTP status in the body" do
|
31
|
+
expect(last_response.body).to eql '200 OK'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "describes the body as text/plain" do
|
35
|
+
expect(last_response.headers['Content-Type']).to eql 'text/plain'
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when the CA is broken" do
|
41
|
+
|
42
|
+
before(:each) do
|
43
|
+
allow(ca).to receive(:sign).and_raise("Nobody expects the Spanish Inquisition!")
|
44
|
+
get "/test"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns 503" do
|
48
|
+
expect(last_response.status).to eql 503
|
49
|
+
end
|
50
|
+
|
51
|
+
it "describes the error in the body" do
|
52
|
+
expect(last_response.body).to match /the Spanish Inquisition/
|
53
|
+
end
|
54
|
+
|
55
|
+
it "describes the body as text/plain" do
|
56
|
+
expect(last_response.headers['Content-Type']).to eql 'text/plain'
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: certmeister-rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon Hearn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: certmeister
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0
|
19
|
+
version: 1.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0
|
26
|
+
version: 1.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,8 +61,10 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- lib/certmeister/rack/app.rb
|
64
|
+
- lib/certmeister/rack/self_test_app.rb
|
64
65
|
- lib/certmeister/rack/symbolic_hash_accessor.rb
|
65
66
|
- spec/certmeister/rack/app_spec.rb
|
67
|
+
- spec/certmeister/rack/self_test_app_spec.rb
|
66
68
|
homepage: https://github.com/sheldonh/certmeister
|
67
69
|
licenses:
|
68
70
|
- MIT
|
@@ -89,3 +91,4 @@ specification_version: 4
|
|
89
91
|
summary: Rack application for certmeister
|
90
92
|
test_files:
|
91
93
|
- spec/certmeister/rack/app_spec.rb
|
94
|
+
- spec/certmeister/rack/self_test_app_spec.rb
|