Class: Certmeister::SelfTest
- Inherits:
-
Object
- Object
- Certmeister::SelfTest
- Defined in:
- lib/certmeister/self_test.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#initialize(ca, key = nil) ⇒ SelfTest
constructor
Pass in PEM-encoded key for fast tests that don’t need lots of entropy.
- #test(req = {cn: 'test', ip: '127.0.0.1'}) ⇒ Object
- #test!(req = {cn: 'test', ip: '127.0.0.1'}) ⇒ Object
Constructor Details
#initialize(ca, key = nil) ⇒ SelfTest
Pass in PEM-encoded key for fast tests that don’t need lots of entropy.
6 7 8 9 |
# File 'lib/certmeister/self_test.rb', line 6 def initialize(ca, key = nil) @ca = ca @key = key end |
Instance Method Details
#test(req = {cn: 'test', ip: '127.0.0.1'}) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/certmeister/self_test.rb', line 11 def test(req = {cn: 'test', ip: '127.0.0.1'}) begin test!(req = {cn: 'test', ip: '127.0.0.1'}) Result.new(true, {message: "OK"}) rescue Exception => e Result.new(false, {message: e.}) end end |
#test!(req = {cn: 'test', ip: '127.0.0.1'}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/certmeister/self_test.rb', line 20 def test!(req = {cn: 'test', ip: '127.0.0.1'}) res = @ca.remove(req) res.hit? or res.miss? or raise "Test certificate remove failed: #{res.error}" csr = get_csr("C=ZA, ST=Western Cape, L=Cape Town, O=Hetzner PTY Ltd, CN=#{req[:cn]}") res = @ca.sign(cn: 'test', csr: csr.to_pem, ip: '127.0.0.1') res.hit? or raise "Test certificate signing failed: #{res.error}" res = @ca.fetch(cn: 'test', ip: '127.0.0.1') res.hit? or raise "Test certificate fetch failed: #{res.error}" cert = OpenSSL::X509::Certificate.new(res.pem) cert.subject.to_s =~ /CN=#{req[:cn]}/ or raise "Test certificate common name mismatch" nil end |