Browse Source

More tests

aeris 2 years ago
parent
commit
9dbaedcb10
1 changed files with 68 additions and 6 deletions
  1. 68
    6
      spec/cryptcheck/tls/server_spec.rb

+ 68
- 6
spec/cryptcheck/tls/server_spec.rb View File

@@ -9,15 +9,81 @@ describe CryptCheck::Tls::Server do
9 9
 		FakeTime.unfreeze
10 10
 	end
11 11
 
12
+	def server
13
+		CryptCheck::Tls::TcpServer.new 'localhost', ::Socket::PF_INET, '127.0.0.1', 5000
14
+	end
15
+
16
+	describe '#certs' do
17
+		it 'must detect RSA certificate' do
18
+			tls_serv material: [[:rsa, 1024]] do
19
+				certs = server.certs.collect &:fingerprint
20
+				expect(certs).to contain_exactly 'a11802a4407aaeb93ccd0bd8c8a61be17eaba6b378433af5ad45ecbb1d633f71'
21
+			end
22
+		end
23
+
24
+		it 'must detect ECDSA certificate' do
25
+			tls_serv material: [[:ecdsa, :prime256v1]] do
26
+				certs = server.certs.collect &:fingerprint
27
+				expect(certs).to contain_exactly '531ab9545f052818ff0559f648a147b104223834cc8f780516b3aacf1fdc8c06'
28
+			end
29
+		end
30
+
31
+		it 'must detect RSA and ECDSA certificates' do
32
+			tls_serv material: [[:ecdsa, :prime256v1], [:rsa, 1024]] do
33
+				certs = server.certs.collect &:fingerprint
34
+				expect(certs).to contain_exactly '531ab9545f052818ff0559f648a147b104223834cc8f780516b3aacf1fdc8c06',
35
+												 'a11802a4407aaeb93ccd0bd8c8a61be17eaba6b378433af5ad45ecbb1d633f71'
36
+			end
37
+		end
38
+	end
39
+
40
+	describe '#supported_curves' do
41
+		it 'must detect supported curves for RSA' do
42
+			tls_serv material: [[:rsa, 1024]], curves: %i(prime256v1 sect571r1) do
43
+				curves = server.supported_curves.collect &:name
44
+				expect(curves).to contain_exactly :prime256v1, :sect571r1
45
+			end
46
+		end
47
+
48
+		it 'must detect supported curves from ECDSA' do
49
+			tls_serv material: [[:ecdsa, :prime256v1]],
50
+					 curves: %i(prime256v1), server_preference: false do
51
+				curves = server.supported_curves.collect &:name
52
+				expect(curves).to contain_exactly :prime256v1
53
+			end
54
+		end
55
+
56
+		it 'must detect supported curves from ECDSA and ECDHE' do
57
+			tls_serv material: [[:ecdsa, :prime256v1]],
58
+					 curves: %i(prime256v1 sect571r1), server_preference: false do
59
+				curves = server.supported_curves.collect &:name
60
+				expect(curves).to contain_exactly :prime256v1, :sect571r1
61
+			end
62
+		end
63
+
64
+		# No chance here :'(
65
+		it 'can\'t detect supported curves from ECDHE if server preference enforced' do
66
+			tls_serv material: [[:ecdsa, :prime256v1]],
67
+					 curves: %i(prime256v1 sect571r1), server_preference: true do
68
+				curves = server.supported_curves.collect &:name
69
+				expect(curves).to contain_exactly :prime256v1
70
+			end
71
+
72
+			tls_serv material: [[:ecdsa, :prime256v1]],
73
+					 curves: %i(sect571r1 prime256v1), server_preference: true do
74
+				curves = server.supported_curves.collect &:name
75
+				expect(curves).to contain_exactly :prime256v1, :sect571r1
76
+			end
77
+		end
78
+	end
79
+
12 80
 	describe '#md5_sign?' do
13 81
 		it 'must detect server using MD5 certificate' do
14 82
 			tls_serv do
15
-				server = CryptCheck::Tls::TcpServer.new 'localhost', ::Socket::PF_INET, '127.0.0.1', 5000
16 83
 				expect(server.md5_sign?).to be false
17 84
 			end
18 85
 
19 86
 			tls_serv material: [:md5, [:rsa, 1024]] do
20
-				server = CryptCheck::Tls::TcpServer.new 'localhost', ::Socket::PF_INET, '127.0.0.1', 5000
21 87
 				expect(server.md5_sign?).to be true
22 88
 			end
23 89
 		end
@@ -26,12 +92,10 @@ describe CryptCheck::Tls::Server do
26 92
 	describe '#sha1_sign?' do
27 93
 		it 'must detect server using SHA1 certificate' do
28 94
 			tls_serv do
29
-				server = CryptCheck::Tls::TcpServer.new 'localhost', ::Socket::PF_INET, '127.0.0.1', 5000
30 95
 				expect(server.sha1_sign?).to be false
31 96
 			end
32 97
 
33 98
 			tls_serv material: [:sha1, [:rsa, 1024]] do
34
-				server = CryptCheck::Tls::TcpServer.new 'localhost', ::Socket::PF_INET, '127.0.0.1', 5000
35 99
 				expect(server.sha1_sign?).to be true
36 100
 			end
37 101
 		end
@@ -40,12 +104,10 @@ describe CryptCheck::Tls::Server do
40 104
 	describe '#sha2_sign?' do
41 105
 		it 'must detect server using SHA2 certificate' do
42 106
 			tls_serv do
43
-				server = CryptCheck::Tls::TcpServer.new 'localhost', ::Socket::PF_INET, '127.0.0.1', 5000
44 107
 				expect(server.sha2_sign?).to be true
45 108
 			end
46 109
 
47 110
 			tls_serv material: [:md5, :sha1] do
48
-				server = CryptCheck::Tls::TcpServer.new 'localhost', ::Socket::PF_INET, '127.0.0.1', 5000
49 111
 				expect(server.sha2_sign?).to be false
50 112
 			end
51 113
 		end

Loading…
Cancel
Save