Browse Source

Fix test for ECDH curves

master
aeris 2 years ago
parent
commit
b5e828a139
2 changed files with 17 additions and 15 deletions
  1. 1
    2
      spec/cryptcheck/support/analysis.rb
  2. 16
    13
      spec/helpers.rb

+ 1
- 2
spec/cryptcheck/support/analysis.rb View File

@@ -40,8 +40,7 @@ RSpec.shared_examples :analysis do
40 40
 				analyze 'localhost', 5000
41 41
 			end
42 42
 
43
-			expect(grades).to be_a CryptCheck::AnalysisFailure
44
-			expect(grades.to_s).to eq 'Unable to resolve localhost'
43
+			expect_grade_error grades, 'localhost', nil, 5000, 'Unable to resolve localhost'
45 44
 		end
46 45
 
47 46
 		it 'return error if analysis too long' do

+ 16
- 13
spec/helpers.rb View File

@@ -7,6 +7,12 @@ Dir['./spec/**/support/**/*.rb'].sort.each { |f| require f }
7 7
 CryptCheck::Logger.level = ENV['LOG'] || :none
8 8
 
9 9
 module Helpers
10
+	DEFAULT_KEY = 'rsa-1024'
11
+	DEFAULT_METHOD = :TLSv1_2
12
+	DEFAULT_CIPHERS = %w(AES128-SHA)
13
+	DEFAULT_ECC_CURVE = 'secp256k1'
14
+	DEFAULT_DH_SIZE = 1024
15
+
10 16
 	OpenSSL::PKey::EC.send :alias_method, :private?, :private_key?
11 17
 
12 18
 	def key(name)
@@ -89,9 +95,9 @@ module Helpers
89 95
 		end
90 96
 	end
91 97
 
92
-	def context(key: 'rsa-1024', domain: 'localhost', # Key & certificate
93
-				version: :TLSv1_2, ciphers: 'AES128-SHA', # TLS version and ciphers
94
-				dh: 1024, ecdh: 'secp256r1') # DHE & ECDHE
98
+	def context(key: DEFAULT_KEY, domain: 'localhost', # Key & certificate
99
+				version: DEFAULT_METHOD, ciphers: DEFAULT_CIPHERS, # TLS version and ciphers
100
+				dh: DEFAULT_DH_SIZE, ecdh: DEFAULT_ECC_CURVE) # DHE & ECDHE
95 101
 		key  = key key
96 102
 		cert = certificate key, domain
97 103
 
@@ -104,17 +110,14 @@ module Helpers
104 110
 			dh                      = dh dh
105 111
 			context.tmp_dh_callback = proc { dh }
106 112
 		end
107
-		if ecdh
108
-			ecdh                      = key ecdh
109
-			context.tmp_ecdh_callback = proc { ecdh }
110
-		end
113
+		context.ecdh_curves = ecdh if ecdh
111 114
 
112 115
 		context
113 116
 	end
114 117
 
115
-	def tls_serv(key: 'rsa-1024', domain: 'localhost', # Key & certificate
116
-				 version: :TLSv1_2, ciphers: 'AES128-SHA', # TLS version and ciphers
117
-				 dh: 1024, ecdh: 'secp256r1', # DHE & ECDHE
118
+	def tls_serv(key: DEFAULT_KEY, domain: 'localhost', # Key & certificate
119
+				 version: DEFAULT_METHOD, ciphers: DEFAULT_CIPHERS, # TLS version and ciphers
120
+				 dh: DEFAULT_DH_SIZE, ecdh: DEFAULT_ECC_CURVE, # DHE & ECDHE
118 121
 				 host: '127.0.0.1', port: 5000, # Binding
119 122
 				 process: nil, &block)
120 123
 		context    = context(key: key, domain: domain, version: version, ciphers: ciphers, dh: dh, ecdh: ecdh)
@@ -137,9 +140,9 @@ module Helpers
137 140
 		end
138 141
 	end
139 142
 
140
-	def starttls_serv(key: 'rsa-1024', domain: 'localhost', # Key & certificate
141
-					  version: :TLSv1_2, ciphers: 'AES128-SHA', # TLS version and ciphers
142
-					  dh: 1024, ecdh: 'secp256r1', # DHE & ECDHE
143
+	def starttls_serv(key: DEFAULT_KEY, domain: 'localhost', # Key & certificate
144
+					  version: DEFAULT_METHOD, ciphers: DEFAULT_CIPHERS, # TLS version and ciphers
145
+					  dh: DEFAULT_DH_SIZE, ecdh: DEFAULT_ECC_CURVE, # DHE & ECDHE
143 146
 					  host: '127.0.0.1', port: 5000, # Binding
144 147
 					  plain_process: nil, process: nil, &block)
145 148
 		context                      = context(key: key, domain: domain, version: version, ciphers: ciphers, dh: dh, ecdh: ecdh)

Loading…
Cancel
Save