diff options
| author | mo khan <mo.khan@gmail.com> | 2020-09-15 15:34:34 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-09-15 15:34:34 -0600 |
| commit | 4b46a3cbf564fcc79c54607be33923e8015d7031 (patch) | |
| tree | f44cd70e98346323032f0210328a77b4eab7c586 | |
| parent | 3ff585b2fcc616c2b2f16bf82e312f91d920b472 (diff) | |
refactor: extract class to generate self signed certificate
| -rw-r--r-- | lib/e2e.rb | 3 | ||||
| -rw-r--r-- | lib/e2e/x509.rb | 13 | ||||
| -rw-r--r-- | spec/gemnasium_maven_spec.rb | 15 |
3 files changed, 17 insertions, 14 deletions
@@ -1,4 +1,5 @@ -require 'json' require 'e2e/dependency_scanning_report' require 'e2e/docker' require 'e2e/project' +require 'e2e/x509' +require 'json' diff --git a/lib/e2e/x509.rb b/lib/e2e/x509.rb new file mode 100644 index 0000000..898ecc1 --- /dev/null +++ b/lib/e2e/x509.rb @@ -0,0 +1,13 @@ +class X509 + def self.self_signed(key: OpenSSL::PKey::RSA.new(4096)) + certificate = OpenSSL::X509::Certificate.new + certificate.subject = certificate.issuer = OpenSSL::X509::Name.parse("/C=/ST=/L=/O=/OU=/CN=") + certificate.not_before = Time.now.to_i + certificate.not_after = Time.now.to_i + 600 + certificate.public_key = key.public_key + certificate.serial = 0x01 + certificate.version = 2 + certificate.sign(key, OpenSSL::Digest::SHA256.new) + certificate + end +end diff --git a/spec/gemnasium_maven_spec.rb b/spec/gemnasium_maven_spec.rb index 90fde6e..d84050a 100644 --- a/spec/gemnasium_maven_spec.rb +++ b/spec/gemnasium_maven_spec.rb @@ -13,20 +13,9 @@ RSpec.describe 'gemnasium-maven' do let(:docker) { Docker.new(pwd: Pathname.pwd.join('src/gemnasium-maven')) } let(:project_path) { project.path } let(:docker_image) { 'gemnasium-maven:latest' } - let(:env) { { 'ADDITIONAL_CA_CERT_BUNDLE' => x509, 'DS_JAVA_VERSION' => java_version } } + let(:env) { { 'ADDITIONAL_CA_CERT_BUNDLE' => x509.to_pem, 'DS_JAVA_VERSION' => java_version } } let(:project) { Project.new } - let(:x509) do - rsa_key = OpenSSL::PKey::RSA.new(4096) - certificate = OpenSSL::X509::Certificate.new - certificate.subject = certificate.issuer = OpenSSL::X509::Name.parse("/C=/ST=/L=/O=/OU=/CN=") - certificate.not_before = Time.now.to_i - certificate.not_after = Time.now.to_i + 600 - certificate.public_key = rsa_key.public_key - certificate.serial = 0x01 - certificate.version = 2 - certificate.sign(rsa_key, OpenSSL::Digest::SHA256.new) - certificate.to_pem - end + let(:x509) { X509.self_signed } around(:example) do |example| project.mount(dir: fixture_file('java/maven/custom-tls')) |
