Browse Source

More unit tests (SMTP)

v1
Aeris 6 years ago
parent
commit
41cdbaa83f
  1. 3
      lib/cryptcheck/tls/smtp/server.rb
  2. 29
      spec/cryptcheck/smtp_spec.rb

3
lib/cryptcheck/tls/smtp/server.rb

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

29
spec/cryptcheck/smtp_spec.rb

@ -0,0 +1,29 @@
describe CryptCheck::Tls::Smtp do
def server(*args, **kargs, &block)
kargs[:plain_process] = proc do |socket|
socket.write "220 localhost\r\n"
socket.gets
socket.write "250-STARTTLS\r\n"
socket.gets
socket.write "220 Ready to start TLS\r\n"
true
end unless kargs.include? :plain_process
starttls_serv *args, **kargs, &block
end
def plain_server(*args, **kargs, &block)
kargs[:plain_process] = proc do |socket|
socket.write "220 localhost\r\n"
socket.gets
socket.write "250 DONE\r\n"
false
end unless kargs.include? :plain_process
starttls_serv *args, **kargs, &block
end
def analyze(*args)
CryptCheck::Tls::Smtp.analyze *args
end
include_examples :analysis
end
Loading…
Cancel
Save