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

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
- 0
spec/cryptcheck/smtp_spec.rb View File

@@ -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