Browse Source

More unit tests (SMTP)

master
Aeris 3 years ago
parent
commit
41cdbaa83f
2 changed files with 31 additions and 1 deletions
  1. 2
    1
      lib/cryptcheck/tls/smtp/server.rb
  2. 29
    0
      spec/cryptcheck/smtp_spec.rb

+ 2
- 1
lib/cryptcheck/tls/smtp/server.rb View File

@@ -6,13 +6,14 @@ module CryptCheck
6 6
 
7 7
 				def initialize(hostname, family, ip, port, domain:)
8 8
 					@domain = domain
9
-					super
9
+					super hostname, family, ip, port
10 10
 				end
11 11
 
12 12
 				def ssl_connect(socket, context, method, &block)
13 13
 					socket.recv 1024
14 14
 					socket.write "EHLO #{Socket.gethostbyname(Socket.gethostname).first}\r\n"
15 15
 					features = socket.recv(1024).split "\r\n"
16
+					features
16 17
 					starttls = features.find { |f| /250[- ]STARTTLS/ =~ f }
17 18
 					raise TLSNotAvailableException unless starttls
18 19
 					socket.write "STARTTLS\r\n"

+ 29
- 0
spec/cryptcheck/smtp_spec.rb View File

@@ -0,0 +1,29 @@
1
+describe CryptCheck::Tls::Smtp do
2
+	def server(*args, **kargs, &block)
3
+		kargs[:plain_process] = proc do |socket|
4
+			socket.write "220 localhost\r\n"
5
+			socket.gets
6
+			socket.write "250-STARTTLS\r\n"
7
+			socket.gets
8
+			socket.write "220 Ready to start TLS\r\n"
9
+			true
10
+		end unless kargs.include? :plain_process
11
+		starttls_serv *args, **kargs, &block
12
+	end
13
+
14
+	def plain_server(*args, **kargs, &block)
15
+		kargs[:plain_process] = proc do |socket|
16
+			socket.write "220 localhost\r\n"
17
+			socket.gets
18
+			socket.write "250 DONE\r\n"
19
+			false
20
+		end unless kargs.include? :plain_process
21
+		starttls_serv *args, **kargs, &block
22
+	end
23
+
24
+	def analyze(*args)
25
+		CryptCheck::Tls::Smtp.analyze *args
26
+	end
27
+
28
+	include_examples :analysis
29
+end

Loading…
Cancel
Save