diff options
author | Takuya Noguchi <takninnovationresearch@gmail.com> | 2022-07-17 08:08:51 +0000 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-07-22 12:07:23 +0900 |
commit | d7ffd3fea402239b16833cc434404a7af82d44f3 (patch) | |
tree | 9794942135111c36e6b6bce69e070ca556b89028 /test/rubygems/test_gem_security.rb | |
parent | 388c4e1076ac5a58d5008abc8e0a8d017698875a (diff) | |
download | ruby-d7ffd3fea402239b16833cc434404a7af82d44f3.tar.gz |
RubyGems: Enable Style/StringLiterals cop
Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
Diffstat (limited to 'test/rubygems/test_gem_security.rb')
-rw-r--r-- | test/rubygems/test_gem_security.rb | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/test/rubygems/test_gem_security.rb b/test/rubygems/test_gem_security.rb index 415ec2b5f6..f0b9824aab 100644 --- a/test/rubygems/test_gem_security.rb +++ b/test/rubygems/test_gem_security.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true -require_relative 'helper' -require 'rubygems/security' +require_relative "helper" +require "rubygems/security" unless Gem::HAVE_OPENSSL - warn 'Skipping Gem::Security tests. openssl not found.' + warn "Skipping Gem::Security tests. openssl not found." end if Gem.java_platform? - warn 'Skipping Gem::Security tests on jruby.' + warn "Skipping Gem::Security tests on jruby." end class TestGemSecurity < Gem::TestCase - CHILD_KEY = load_key 'child' - EC_KEY = load_key 'private_ec', 'Foo bar' + CHILD_KEY = load_key "child" + EC_KEY = load_key "private_ec", "Foo bar" - ALTERNATE_CERT = load_cert 'child' - CHILD_CERT = load_cert 'child' - EXPIRED_CERT = load_cert 'expired' + ALTERNATE_CERT = load_cert "child" + CHILD_CERT = load_cert "child" + EXPIRED_CERT = load_cert "expired" def setup super @@ -42,19 +42,19 @@ class TestGemSecurity < Gem::TestCase assert_equal 3, cert.extensions.length, cert.extensions.map {|e| e.to_a.first } - constraints = cert.extensions.find {|ext| ext.oid == 'basicConstraints' } - assert_equal 'CA:FALSE', constraints.value + constraints = cert.extensions.find {|ext| ext.oid == "basicConstraints" } + assert_equal "CA:FALSE", constraints.value - key_usage = cert.extensions.find {|ext| ext.oid == 'keyUsage' } - assert_equal 'Digital Signature, Key Encipherment, Data Encipherment', + key_usage = cert.extensions.find {|ext| ext.oid == "keyUsage" } + assert_equal "Digital Signature, Key Encipherment, Data Encipherment", key_usage.value - key_ident = cert.extensions.find {|ext| ext.oid == 'subjectKeyIdentifier' } + key_ident = cert.extensions.find {|ext| ext.oid == "subjectKeyIdentifier" } assert_equal 59, key_ident.value.length - assert_equal '5F:43:6E:F6:9A:8E:45:25:E9:22:E3:7D:37:5E:A4:D5:36:02:85:1B', + assert_equal "5F:43:6E:F6:9A:8E:45:25:E9:22:E3:7D:37:5E:A4:D5:36:02:85:1B", key_ident.value - assert_equal '', cert.issuer.to_s + assert_equal "", cert.issuer.to_s assert_equal name.to_s, cert.subject.to_s end @@ -63,12 +63,12 @@ class TestGemSecurity < Gem::TestCase cert = @SEC.create_cert_self_signed subject, PRIVATE_KEY, 60 - assert_equal '/CN=nobody/DC=example', cert.issuer.to_s + assert_equal "/CN=nobody/DC=example", cert.issuer.to_s assert_equal "sha256WithRSAEncryption", cert.signature_algorithm end def test_class_create_cert_email - email = 'nobody@example' + email = "nobody@example" name = PUBLIC_CERT.subject key = PRIVATE_KEY @@ -87,37 +87,37 @@ class TestGemSecurity < Gem::TestCase assert_equal 5, cert.extensions.length, cert.extensions.map {|e| e.to_a.first } - constraints = cert.extensions.find {|ext| ext.oid == 'subjectAltName' } - assert_equal 'email:nobody@example', constraints.value + constraints = cert.extensions.find {|ext| ext.oid == "subjectAltName" } + assert_equal "email:nobody@example", constraints.value - constraints = cert.extensions.find {|ext| ext.oid == 'basicConstraints' } - assert_equal 'CA:FALSE', constraints.value + constraints = cert.extensions.find {|ext| ext.oid == "basicConstraints" } + assert_equal "CA:FALSE", constraints.value - key_usage = cert.extensions.find {|ext| ext.oid == 'keyUsage' } - assert_equal 'Digital Signature, Key Encipherment, Data Encipherment', + key_usage = cert.extensions.find {|ext| ext.oid == "keyUsage" } + assert_equal "Digital Signature, Key Encipherment, Data Encipherment", key_usage.value - key_ident = cert.extensions.find {|ext| ext.oid == 'subjectKeyIdentifier' } + key_ident = cert.extensions.find {|ext| ext.oid == "subjectKeyIdentifier" } assert_equal 59, key_ident.value.length - assert_equal '5F:43:6E:F6:9A:8E:45:25:E9:22:E3:7D:37:5E:A4:D5:36:02:85:1B', + assert_equal "5F:43:6E:F6:9A:8E:45:25:E9:22:E3:7D:37:5E:A4:D5:36:02:85:1B", key_ident.value end def test_class_create_key - key = @SEC.create_key 'rsa' + key = @SEC.create_key "rsa" assert_kind_of OpenSSL::PKey::RSA, key end def test_class_create_key_downcases - key = @SEC.create_key 'DSA' + key = @SEC.create_key "DSA" assert_kind_of OpenSSL::PKey::DSA, key end def test_class_create_key_raises_unknown_algorithm e = assert_raise Gem::Security::Exception do - @SEC.create_key 'NOT_RSA' + @SEC.create_key "NOT_RSA" end assert_equal "NOT_RSA algorithm not found. RSA, DSA, and EC algorithms are supported.", @@ -137,17 +137,17 @@ class TestGemSecurity < Gem::TestCase end def test_class_email_to_name - assert_equal '/CN=nobody/DC=example', - @SEC.email_to_name('nobody@example').to_s + assert_equal "/CN=nobody/DC=example", + @SEC.email_to_name("nobody@example").to_s - assert_equal '/CN=nobody/DC=example/DC=com', - @SEC.email_to_name('nobody@example.com').to_s + assert_equal "/CN=nobody/DC=example/DC=com", + @SEC.email_to_name("nobody@example.com").to_s - assert_equal '/CN=no.body/DC=example', - @SEC.email_to_name('no.body@example').to_s + assert_equal "/CN=no.body/DC=example", + @SEC.email_to_name("no.body@example").to_s - assert_equal '/CN=no_body/DC=example', - @SEC.email_to_name('no+body@example').to_s + assert_equal "/CN=no_body/DC=example", + @SEC.email_to_name("no+body@example").to_s end def test_class_re_sign @@ -168,7 +168,7 @@ class TestGemSecurity < Gem::TestCase end child_alt_name = CHILD_CERT.extensions.find do |extension| - extension.oid == 'subjectAltName' + extension.oid == "subjectAltName" end assert_equal "#{child_alt_name.value} is not self-signed, contact " + @@ -217,20 +217,20 @@ class TestGemSecurity < Gem::TestCase assert_equal 4, signed.extensions.length, signed.extensions.map {|e| e.to_a.first } - constraints = signed.extensions.find {|ext| ext.oid == 'issuerAltName' } - assert_equal 'email:nobody@example', constraints.value, 'issuerAltName' + constraints = signed.extensions.find {|ext| ext.oid == "issuerAltName" } + assert_equal "email:nobody@example", constraints.value, "issuerAltName" - constraints = signed.extensions.find {|ext| ext.oid == 'basicConstraints' } - assert_equal 'CA:FALSE', constraints.value + constraints = signed.extensions.find {|ext| ext.oid == "basicConstraints" } + assert_equal "CA:FALSE", constraints.value - key_usage = signed.extensions.find {|ext| ext.oid == 'keyUsage' } - assert_equal 'Digital Signature, Key Encipherment, Data Encipherment', + key_usage = signed.extensions.find {|ext| ext.oid == "keyUsage" } + assert_equal "Digital Signature, Key Encipherment, Data Encipherment", key_usage.value key_ident = - signed.extensions.find {|ext| ext.oid == 'subjectKeyIdentifier' } + signed.extensions.find {|ext| ext.oid == "subjectKeyIdentifier" } assert_equal 59, key_ident.value.length - assert_equal '5F:43:6E:F6:9A:8E:45:25:E9:22:E3:7D:37:5E:A4:D5:36:02:85:1B', + assert_equal "5F:43:6E:F6:9A:8E:45:25:E9:22:E3:7D:37:5E:A4:D5:36:02:85:1B", key_ident.value assert signed.verify key @@ -240,7 +240,7 @@ class TestGemSecurity < Gem::TestCase issuer = PUBLIC_CERT.subject signee = OpenSSL::X509::Name.parse "/CN=signee/DC=example" - cert = @SEC.create_cert_email 'signee@example', PRIVATE_KEY + cert = @SEC.create_cert_email "signee@example", PRIVATE_KEY signed = @SEC.sign cert, PRIVATE_KEY, PUBLIC_CERT, 60 @@ -256,23 +256,23 @@ class TestGemSecurity < Gem::TestCase assert_equal 5, signed.extensions.length, signed.extensions.map {|e| e.to_a.first } - constraints = signed.extensions.find {|ext| ext.oid == 'issuerAltName' } - assert_equal 'email:nobody@example', constraints.value, 'issuerAltName' + constraints = signed.extensions.find {|ext| ext.oid == "issuerAltName" } + assert_equal "email:nobody@example", constraints.value, "issuerAltName" - constraints = signed.extensions.find {|ext| ext.oid == 'subjectAltName' } - assert_equal 'email:signee@example', constraints.value, 'subjectAltName' + constraints = signed.extensions.find {|ext| ext.oid == "subjectAltName" } + assert_equal "email:signee@example", constraints.value, "subjectAltName" - constraints = signed.extensions.find {|ext| ext.oid == 'basicConstraints' } - assert_equal 'CA:FALSE', constraints.value + constraints = signed.extensions.find {|ext| ext.oid == "basicConstraints" } + assert_equal "CA:FALSE", constraints.value - key_usage = signed.extensions.find {|ext| ext.oid == 'keyUsage' } - assert_equal 'Digital Signature, Key Encipherment, Data Encipherment', + key_usage = signed.extensions.find {|ext| ext.oid == "keyUsage" } + assert_equal "Digital Signature, Key Encipherment, Data Encipherment", key_usage.value key_ident = - signed.extensions.find {|ext| ext.oid == 'subjectKeyIdentifier' } + signed.extensions.find {|ext| ext.oid == "subjectKeyIdentifier" } assert_equal 59, key_ident.value.length - assert_equal '5F:43:6E:F6:9A:8E:45:25:E9:22:E3:7D:37:5E:A4:D5:36:02:85:1B', + assert_equal "5F:43:6E:F6:9A:8E:45:25:E9:22:E3:7D:37:5E:A4:D5:36:02:85:1B", key_ident.value assert signed.verify PUBLIC_KEY @@ -281,15 +281,15 @@ class TestGemSecurity < Gem::TestCase def test_class_trust_dir trust_dir = @SEC.trust_dir - expected = File.join Gem.user_home, '.gem/trust' + expected = File.join Gem.user_home, ".gem/trust" assert_equal expected, trust_dir.dir end def test_class_write - key = @SEC.create_key 'rsa' + key = @SEC.create_key "rsa" - path = File.join @tempdir, 'test-private_key.pem' + path = File.join @tempdir, "test-private_key.pem" @SEC.write key, path @@ -301,11 +301,11 @@ class TestGemSecurity < Gem::TestCase end def test_class_write_encrypted - key = @SEC.create_key 'rsa' + key = @SEC.create_key "rsa" - path = File.join @tempdir, 'test-private_encrypted_key.pem' + path = File.join @tempdir, "test-private_encrypted_key.pem" - passphrase = 'It should be long.' + passphrase = "It should be long." @SEC.write key, path, 0600, passphrase @@ -317,13 +317,13 @@ class TestGemSecurity < Gem::TestCase end def test_class_write_encrypted_cipher - key = @SEC.create_key 'rsa' + key = @SEC.create_key "rsa" - path = File.join @tempdir, 'test-private_encrypted__with_non_default_cipher_key.pem' + path = File.join @tempdir, "test-private_encrypted__with_non_default_cipher_key.pem" - passphrase = 'It should be long.' + passphrase = "It should be long." - cipher = OpenSSL::Cipher.new 'AES-192-CBC' + cipher = OpenSSL::Cipher.new "AES-192-CBC" @SEC.write key, path, 0600, passphrase, cipher |