certmeister 1.1.0 → 1.2.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/Gemfile.lock +3 -3
- data/lib/certmeister/self_test.rb +18 -13
- data/lib/certmeister/version.rb +1 -1
- data/spec/certmeister/self_test_spec.rb +26 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be85393abd963582ce00c505d139f625c1ace511
|
4
|
+
data.tar.gz: aed65798d23b24263b03bc2177fc9ea8de6e3343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b13f427a191e415dbdfd322fd23fffcc764e877cbcb9a6bf413a405591108a8ad1b10d998f68484782f428a7eaee57103800771dcd88e872d3c2ecc19b9d31fb
|
7
|
+
data.tar.gz: 564a1d95235f1f233f5f7fd68ed40587ff18963cb79ce7eaae67b1ab63282f5fcdec9862f94cadf5c5e20f4ccd723beb1df6c957f5cfa70d8f4ad2387dd40e93
|
data/Gemfile.lock
CHANGED
@@ -10,25 +10,30 @@ module Certmeister
|
|
10
10
|
|
11
11
|
def test(req = {cn: 'test', ip: '127.0.0.1'})
|
12
12
|
begin
|
13
|
-
|
14
|
-
res.hit? or res.miss? or raise "Test certificate remove failed: #{res.error}"
|
15
|
-
|
16
|
-
csr = get_csr("C=ZA, ST=Western Cape, L=Cape Town, O=Hetzner PTY Ltd, CN=#{req[:cn]}")
|
17
|
-
res = @ca.sign(cn: 'test', csr: csr.to_pem, ip: '127.0.0.1')
|
18
|
-
res.hit? or raise "Test certificate signing failed: #{res.error}"
|
19
|
-
|
20
|
-
res = @ca.fetch(cn: 'test', ip: '127.0.0.1')
|
21
|
-
res.hit? or raise "Test certificate fetch failed: #{res.error}"
|
22
|
-
|
23
|
-
cert = OpenSSL::X509::Certificate.new(res.pem)
|
24
|
-
cert.subject.to_s =~ /CN=#{req[:cn]}/ or raise "Test certificate common name mismatch"
|
25
|
-
|
13
|
+
test!(req = {cn: 'test', ip: '127.0.0.1'})
|
26
14
|
Result.new(true, {message: "OK"})
|
27
15
|
rescue Exception => e
|
28
16
|
Result.new(false, {message: e.message})
|
29
17
|
end
|
30
18
|
end
|
31
19
|
|
20
|
+
def test!(req = {cn: 'test', ip: '127.0.0.1'})
|
21
|
+
res = @ca.remove(req)
|
22
|
+
res.hit? or res.miss? or raise "Test certificate remove failed: #{res.error}"
|
23
|
+
|
24
|
+
csr = get_csr("C=ZA, ST=Western Cape, L=Cape Town, O=Hetzner PTY Ltd, CN=#{req[:cn]}")
|
25
|
+
res = @ca.sign(cn: 'test', csr: csr.to_pem, ip: '127.0.0.1')
|
26
|
+
res.hit? or raise "Test certificate signing failed: #{res.error}"
|
27
|
+
|
28
|
+
res = @ca.fetch(cn: 'test', ip: '127.0.0.1')
|
29
|
+
res.hit? or raise "Test certificate fetch failed: #{res.error}"
|
30
|
+
|
31
|
+
cert = OpenSSL::X509::Certificate.new(res.pem)
|
32
|
+
cert.subject.to_s =~ /CN=#{req[:cn]}/ or raise "Test certificate common name mismatch"
|
33
|
+
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
32
37
|
private
|
33
38
|
|
34
39
|
def get_csr(subject)
|
data/lib/certmeister/version.rb
CHANGED
@@ -7,11 +7,11 @@ describe Certmeister::SelfTest do
|
|
7
7
|
|
8
8
|
subject { Certmeister::SelfTest.new(ca, File.read('fixtures/client.key')) }
|
9
9
|
|
10
|
-
|
10
|
+
context "when the CA is functioning correctly" do
|
11
11
|
|
12
|
-
|
12
|
+
let(:ca) { Certmeister.new(CertmeisterConfigHelper::valid_config) }
|
13
13
|
|
14
|
-
|
14
|
+
describe "#test(req = {cn: 'test', ip: '127.0.0.1'})" do
|
15
15
|
|
16
16
|
it "returns success" do
|
17
17
|
res = subject.test(cn: 'test', ip: '127.0.0.1')
|
@@ -20,10 +20,22 @@ describe Certmeister::SelfTest do
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
describe "#test!(req = {cn: 'test', ip: '127.0.0.1'})" do
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
it "returns nil" do
|
26
|
+
expect(subject.test!(cn: 'test', ip: '127.0.0.1')).to be nil
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the CA is malfunctioning" do
|
34
|
+
|
35
|
+
let(:store) { Certmeister::InMemoryStore.new.tap { |o| o.send(:break!) } }
|
36
|
+
let(:ca) { Certmeister.new(CertmeisterConfigHelper::custom_config(store: store)) }
|
37
|
+
|
38
|
+
describe "#test(req = {cn: 'test', ip: '127.0.0.1'})" do
|
27
39
|
|
28
40
|
it "returns an error" do
|
29
41
|
res = subject.test(cn: 'test', ip: '127.0.0.1')
|
@@ -37,6 +49,14 @@ describe Certmeister::SelfTest do
|
|
37
49
|
|
38
50
|
end
|
39
51
|
|
52
|
+
describe "#test!(req = {cn: 'test', ip: '127.0.0.1'})" do
|
53
|
+
|
54
|
+
it "raises an exception" do
|
55
|
+
expect { subject.test!(cn: 'test', ip: '127.0.0.1') }.to raise_error(/in-memory store is broken/)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
40
60
|
end
|
41
61
|
|
42
62
|
end
|