using test server for spec

This commit is contained in:
Yaroslav Sidlovsky 2018-09-11 12:18:24 +03:00
parent 6c39ea859b
commit 1915577937
5 changed files with 24 additions and 3 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
/doc/ /doc/
/lib/ /lib/
/bin/ /bin/
test/*
/.shards/ /.shards/
# Libraries don't need dependency lock # Libraries don't need dependency lock

14
Makefile Normal file
View file

@ -0,0 +1,14 @@
URL=http://central.maven.org/maven2/com/icegreen/greenmail-standalone/1.5.8/greenmail-standalone-1.5.8.jar
JAR=greenmail.jar
PARAMS=-Dgreenmail.verbose -Dgreenmail.setup.test.imaps -Dgreenmail.users=test:test@test.org
.PHONY: clean
clean:
rm -f test/*
test_server: test/greenmail.jar
java ${PARAMS} -jar test/${JAR}
test/greenmail.jar:
wget -O test/${JAR} ${URL}

View file

@ -4,7 +4,9 @@ describe Imap do
# TODO: Write tests # TODO: Write tests
it "should count emails in mailbox" do it "should count emails in mailbox" do
imap = Imap::Client.new(host: "imap.gmail.com", port: 993, username: "***", password: "***") imap = Imap::Client.new(host: "127.0.0.1", port: 3993,
username: "test", password: "test",
verify: OpenSSL::SSL::VerifyMode::NONE)
mailboxes = imap.list mailboxes = imap.list
if mailboxes.size > 0 if mailboxes.size > 0
mailbox = mailboxes.first mailbox = mailboxes.first

View file

@ -12,12 +12,16 @@ module Imap
@logger : Logger @logger : Logger
@idling = false @idling = false
def initialize(host = "imap.gmail.com", port = 993, username = "", password = "", loglevel = Logger::ERROR) def initialize(host = "imap.gmail.com", port = 993, username = "", password = "",
loglevel = Logger::ERROR, verify = OpenSSL::SSL::VerifyMode::PEER)
@logger = Logger.new(STDERR) @logger = Logger.new(STDERR)
@logger.level = loglevel @logger.level = loglevel
@socket = TCPSocket.new(host, port) @socket = TCPSocket.new(host, port)
tls_socket = OpenSSL::SSL::Socket::Client.new(@socket.as(TCPSocket), sync_close: true, hostname: host) context = OpenSSL::SSL::Context::Client.new
context.verify_mode = verify
tls_socket = OpenSSL::SSL::Socket::Client.new(@socket.as(TCPSocket),
context: context, sync_close: true, hostname: host)
tls_socket.sync = false tls_socket.sync = false
@socket = tls_socket @socket = tls_socket

0
test/.gitignore vendored Normal file
View file