certmeister 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3a26696f474a3c8396726f7b84840b062172f86
4
- data.tar.gz: 1e1e66376dda66c3a1a805b2f9335e516c8503a4
3
+ metadata.gz: be85393abd963582ce00c505d139f625c1ace511
4
+ data.tar.gz: aed65798d23b24263b03bc2177fc9ea8de6e3343
5
5
  SHA512:
6
- metadata.gz: 929dbfe79056c3e6150c69571f50a1ef4d46e4a2205790c9b1a0b248a7b6f371b64cab6312eb3853180ccdb99ad740057be4fb2cb1db5ba41f70ae5754ec1f0b
7
- data.tar.gz: e3e1e03909bce76551b33b588cc4081e08d5274d7e5966b83545888f8f509b340d4c82fb2d082210a70fce6cdb7baae8c4d6295ca9f20c6b9153953eb09dce8b
6
+ metadata.gz: b13f427a191e415dbdfd322fd23fffcc764e877cbcb9a6bf413a405591108a8ad1b10d998f68484782f428a7eaee57103800771dcd88e872d3c2ecc19b9d31fb
7
+ data.tar.gz: 564a1d95235f1f233f5f7fd68ed40587ff18963cb79ce7eaae67b1ab63282f5fcdec9862f94cadf5c5e20f4ccd723beb1df6c957f5cfa70d8f4ad2387dd40e93
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- certmeister (1.1.0)
5
- certmeister-rack (1.1.0)
6
- certmeister (= 1.1.0)
4
+ certmeister (1.2.0)
5
+ certmeister-rack (1.2.0)
6
+ certmeister (= 1.2.0)
7
7
  rack (~> 1.5)
8
8
 
9
9
  GEM
@@ -10,25 +10,30 @@ module Certmeister
10
10
 
11
11
  def test(req = {cn: 'test', ip: '127.0.0.1'})
12
12
  begin
13
- res = @ca.remove(req)
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)
@@ -1,5 +1,5 @@
1
1
  module Certmeister
2
2
 
3
- VERSION = '1.1.0' unless defined?(VERSION)
3
+ VERSION = '1.2.0' unless defined?(VERSION)
4
4
 
5
5
  end
@@ -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
- describe "#test(req = {cn: 'test', ip: '127.0.0.1'})" do
10
+ context "when the CA is functioning correctly" do
11
11
 
12
- context "when the CA is functioning correctly" do
12
+ let(:ca) { Certmeister.new(CertmeisterConfigHelper::valid_config) }
13
13
 
14
- let(:ca) { Certmeister.new(CertmeisterConfigHelper::valid_config) }
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
- context "when the CA is malfunctioning" do
23
+ describe "#test!(req = {cn: 'test', ip: '127.0.0.1'})" do
24
24
 
25
- let(:store) { Certmeister::InMemoryStore.new.tap { |o| o.send(:break!) } }
26
- let(:ca) { Certmeister.new(CertmeisterConfigHelper::custom_config(store: store)) }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: certmeister
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn