Exemplo n.º 1
0
 def test_close_ssl_exception(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMock(ssl.SSLSocket)
     check.sock.unwrap().AndRaise(ssl.SSLError)
     check.sock.close()
     self.mox.ReplayAll()
     check._close(True)
Exemplo n.º 2
0
 def test_lookup(self):
     check = SmtpHealthCheck()
     self.mox.StubOutWithMock(socket, 'getaddrinfo')
     socket.getaddrinfo('test', 13, socket.AF_INET, socket.SOCK_STREAM)
     self.mox.ReplayAll()
     check._lookup('test', 13)
     self.assertIn('Dns-Elapsed', check.results)
Exemplo n.º 3
0
 def test_close_ssl_exception(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMock(ssl.SSLSocket)
     check.sock.unwrap().AndRaise(ssl.SSLError)
     check.sock.close()
     self.mox.ReplayAll()
     check._close(True)
Exemplo n.º 4
0
 def test_lookup(self):
     check = SmtpHealthCheck()
     self.mox.StubOutWithMock(socket, 'getaddrinfo')
     socket.getaddrinfo('test', 13, socket.AF_INET, socket.SOCK_STREAM)
     self.mox.ReplayAll()
     check._lookup('test', 13)
     self.assertIn('Dns-Elapsed', check.results)
Exemplo n.º 5
0
 def test_close_ssl(self):
     check = SmtpHealthCheck()
     orig_sock = self.mox.CreateMock(socket.socket)
     check.sock = self.mox.CreateMock(ssl.SSLSocket)
     check.sock.unwrap().AndReturn(orig_sock)
     orig_sock.close()
     self.mox.ReplayAll()
     check._close(True)
Exemplo n.º 6
0
 def test_close_ssl(self):
     check = SmtpHealthCheck()
     orig_sock = self.mox.CreateMock(socket.socket)
     check.sock = self.mox.CreateMock(ssl.SSLSocket)
     check.sock.unwrap().AndReturn(orig_sock)
     orig_sock.close()
     self.mox.ReplayAll()
     check._close(True)
Exemplo n.º 7
0
 def test_get_banner_multiline(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     check.sock.recv(IsA(int)).AndReturn('220-Part One\r\n')
     self.mox.ReplayAll()
     banner = check._get_banner()
     self.assertIn('Banner-Elapsed', check.results)
     self.assertEqual('220-Part One\r\n', banner)
Exemplo n.º 8
0
 def test_close(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMock(socket.socket)
     check.sock.close()
     check.sock.close().AndRaise(socket.error)
     self.mox.ReplayAll()
     check._close(False)
     check._close(False)
Exemplo n.º 9
0
 def test_get_banner_multiline(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     check.sock.recv(IsA(int)).AndReturn('220-Part One\r\n')
     self.mox.ReplayAll()
     banner = check._get_banner()
     self.assertIn('Banner-Elapsed', check.results)
     self.assertEqual('220-Part One\r\n', banner)
Exemplo n.º 10
0
 def test_close(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMock(socket.socket)
     check.sock.close()
     check.sock.close().AndRaise(socket.error)
     self.mox.ReplayAll()
     check._close(False)
     check._close(False)
Exemplo n.º 11
0
 def test_get_banner_long(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     check.sock.recv(IsA(int)).AndReturn('a'*5120)
     check.sock.recv(IsA(int)).AndReturn('a'*5120)
     check.sock.recv(IsA(int)).AndReturn('a')
     self.mox.ReplayAll()
     with self.assertRaises(BannerError):
         check._get_banner()
Exemplo n.º 12
0
 def test_connect(self):
     check = SmtpHealthCheck()
     self.mox.StubOutWithMock(socket, 'socket')
     sock = self.mox.CreateMockAnything()
     socket.socket(1, 2, 3).AndReturn(sock)
     sock.connect(('test', 13))
     self.mox.ReplayAll()
     check._connect([(1, 2, 3, '', ('test', 13))])
     self.assertIn('Connect-Elapsed', check.results)
Exemplo n.º 13
0
 def test_connect(self):
     check = SmtpHealthCheck()
     self.mox.StubOutWithMock(socket, 'socket')
     sock = self.mox.CreateMockAnything()
     socket.socket(1, 2, 3).AndReturn(sock)
     sock.connect(('test', 13))
     self.mox.ReplayAll()
     check._connect([(1, 2, 3, '', ('test', 13))])
     self.assertIn('Connect-Elapsed', check.results)
Exemplo n.º 14
0
 def test_get_banner_long(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     check.sock.recv(IsA(int)).AndReturn('a' * 5120)
     check.sock.recv(IsA(int)).AndReturn('a' * 5120)
     check.sock.recv(IsA(int)).AndReturn('a')
     self.mox.ReplayAll()
     with self.assertRaises(BannerError):
         check._get_banner()
Exemplo n.º 15
0
 def test_wrap_ssl(self):
     check = SmtpHealthCheck()
     check.sock = 13
     ssl_sock = self.mox.CreateMock(ssl.SSLSocket)
     self.mox.StubOutWithMock(ssl, 'wrap_socket')
     ssl.wrap_socket(13).AndReturn(ssl_sock)
     ssl_sock.do_handshake()
     self.mox.ReplayAll()
     check._wrap_ssl()
     self.assertEqual(ssl_sock, check.sock)
Exemplo n.º 16
0
 def test_wrap_ssl(self):
     check = SmtpHealthCheck()
     check.sock = 13
     ssl_sock = self.mox.CreateMock(ssl.SSLSocket)
     self.mox.StubOutWithMock(ssl, 'wrap_socket')
     ssl.wrap_socket(13).AndReturn(ssl_sock)
     ssl_sock.do_handshake()
     self.mox.ReplayAll()
     check._wrap_ssl()
     self.assertEqual(ssl_sock, check.sock)
Exemplo n.º 17
0
    def test_check_output(self):
        check = SmtpHealthCheck()
        check.results = OrderedDict([('Status', 'OK'), ('TestFloat', 1.004),
                                     ('TestInt', 10), ('TestNone', None)])
        f = StringIO()
        self.assertEqual(0, check.output(f))
        self.assertEqual(
            """\
Status: OK
TestFloat: 1.00400
TestInt: 10
TestNone: 
""", f.getvalue())
Exemplo n.º 18
0
    def test_check_output(self):
        check = SmtpHealthCheck()
        check.results = OrderedDict([('Status', 'OK'),
                                     ('TestFloat', 1.004),
                                     ('TestInt', 10),
                                     ('TestNone', None)])
        f = StringIO()
        self.assertEqual(0, check.output(f))
        self.assertEqual("""\
Status: OK
TestFloat: 1.00400
TestInt: 10
TestNone: 
""", f.getvalue())
Exemplo n.º 19
0
 def test_get_banner_slow(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     check.sock.recv(IsA(int)).AndReturn('2')
     check.sock.recv(IsA(int)).AndReturn('2')
     check.sock.recv(IsA(int)).AndReturn('0')
     check.sock.recv(IsA(int)).AndReturn(' ')
     check.sock.recv(IsA(int)).AndReturn('O')
     check.sock.recv(IsA(int)).AndReturn('k')
     check.sock.recv(IsA(int)).AndReturn('\r')
     check.sock.recv(IsA(int)).AndReturn('\n')
     self.mox.ReplayAll()
     banner = check._get_banner()
     self.assertIn('Banner-Elapsed', check.results)
     self.assertEqual('220 Ok\r\n', banner)
Exemplo n.º 20
0
 def test_get_banner_slow(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     check.sock.recv(IsA(int)).AndReturn('2')
     check.sock.recv(IsA(int)).AndReturn('2')
     check.sock.recv(IsA(int)).AndReturn('0')
     check.sock.recv(IsA(int)).AndReturn(' ')
     check.sock.recv(IsA(int)).AndReturn('O')
     check.sock.recv(IsA(int)).AndReturn('k')
     check.sock.recv(IsA(int)).AndReturn('\r')
     check.sock.recv(IsA(int)).AndReturn('\n')
     self.mox.ReplayAll()
     banner = check._get_banner()
     self.assertIn('Banner-Elapsed', check.results)
     self.assertEqual('220 Ok\r\n', banner)
Exemplo n.º 21
0
 def test_run_exception(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     self.mox.StubOutWithMock(check, '_lookup')
     self.mox.StubOutWithMock(check, '_connect')
     self.mox.StubOutWithMock(check, '_get_banner')
     self.mox.StubOutWithMock(check, '_check_banner')
     check._lookup('test', 13).AndReturn('beep')
     check._connect('beep').AndRaise(Exception('test test'))
     check.sock.close()
     self.mox.ReplayAll()
     check.run('test', 13)
     self.assertEqual('Exception', check.results['Exception-Type'])
     self.assertEqual('test test', check.results['Exception-Value'])
Exemplo n.º 22
0
 def test_run_exception(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     self.mox.StubOutWithMock(check, '_lookup')
     self.mox.StubOutWithMock(check, '_connect')
     self.mox.StubOutWithMock(check, '_get_banner')
     self.mox.StubOutWithMock(check, '_check_banner')
     check._lookup('test', 13).AndReturn('beep')
     check._connect('beep').AndRaise(Exception('test test'))
     check.sock.close()
     self.mox.ReplayAll()
     check.run('test', 13)
     self.assertEqual('Exception', check.results['Exception-Type'])
     self.assertEqual('test test', check.results['Exception-Value'])
Exemplo n.º 23
0
 def test_close_none(self):
     check = SmtpHealthCheck()
     self.mox.ReplayAll()
     check._close(False)
Exemplo n.º 24
0
 def test_connect_bad_dns(self):
     check = SmtpHealthCheck()
     with self.assertRaises(DNSError):
         check._connect([])
Exemplo n.º 25
0
 def test_run_ssl(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     self.mox.StubOutWithMock(check, '_lookup')
     self.mox.StubOutWithMock(check, '_connect')
     self.mox.StubOutWithMock(check, '_wrap_ssl')
     self.mox.StubOutWithMock(check, '_get_banner')
     self.mox.StubOutWithMock(check, '_check_banner')
     check._lookup('test', 13).AndReturn('beep')
     check._connect('beep')
     check._wrap_ssl()
     check._get_banner().AndReturn('beep beep')
     check._check_banner('beep beep')
     check.sock.unwrap().AndReturn(check.sock)
     check.sock.close()
     self.mox.ReplayAll()
     check.run('test', 13, with_ssl=True)
Exemplo n.º 26
0
 def test_check_output_critical(self):
     check = SmtpHealthCheck()
     check.results = OrderedDict([('Status', 'CRITICAL')])
     f = StringIO()
     self.assertEqual(1, check.output(f))
Exemplo n.º 27
0
 def test_check_output_critical(self):
     check = SmtpHealthCheck()
     check.results = OrderedDict([('Status', 'CRITICAL')])
     f = StringIO()
     self.assertEqual(1, check.output(f))
Exemplo n.º 28
0
 def test_check_banner_invalid(self):
     check = SmtpHealthCheck()
     with self.assertRaises(BannerSyntaxError):
         check._check_banner('asdf\r\n')
     self.assertEquals('CRITICAL', check.results['Status'])
Exemplo n.º 29
0
 def test_connect_bad_dns(self):
     check = SmtpHealthCheck()
     with self.assertRaises(DNSError):
         check._connect([])
Exemplo n.º 30
0
 def test_constructor(self):
     check = SmtpHealthCheck()
     self.assertEquals({'Status': 'CRITICAL'}, check.results)
Exemplo n.º 31
0
 def test_close_none(self):
     check = SmtpHealthCheck()
     self.mox.ReplayAll()
     check._close(False)
Exemplo n.º 32
0
 def test_check_banner_invalid(self):
     check = SmtpHealthCheck()
     with self.assertRaises(BannerSyntaxError):
         check._check_banner('asdf\r\n')
     self.assertEquals('CRITICAL', check.results['Status'])
Exemplo n.º 33
0
 def test_check_banner_failure(self):
     check = SmtpHealthCheck()
     with self.assertRaises(BannerError):
         check._check_banner('520 No!\r\n')
     self.assertEquals('CRITICAL', check.results['Status'])
Exemplo n.º 34
0
 def test_check_banner_failure(self):
     check = SmtpHealthCheck()
     with self.assertRaises(BannerError):
         check._check_banner('520 No!\r\n')
     self.assertEquals('CRITICAL', check.results['Status'])
Exemplo n.º 35
0
 def test_run_ssl(self):
     check = SmtpHealthCheck()
     check.sock = self.mox.CreateMockAnything()
     self.mox.StubOutWithMock(check, '_lookup')
     self.mox.StubOutWithMock(check, '_connect')
     self.mox.StubOutWithMock(check, '_wrap_ssl')
     self.mox.StubOutWithMock(check, '_get_banner')
     self.mox.StubOutWithMock(check, '_check_banner')
     check._lookup('test', 13).AndReturn('beep')
     check._connect('beep')
     check._wrap_ssl()
     check._get_banner().AndReturn('beep beep')
     check._check_banner('beep beep')
     check.sock.unwrap().AndReturn(check.sock)
     check.sock.close()
     self.mox.ReplayAll()
     check.run('test', 13, with_ssl=True)
Exemplo n.º 36
0
 def test_check_banner(self):
     check = SmtpHealthCheck()
     check._check_banner('220 Ok\r\n')
     self.assertEqual('220', check.results['Banner-Code'])
     self.assertEqual('Ok', check.results['Banner-Message'])
     self.assertEqual('OK', check.results['Status'])
Exemplo n.º 37
0
 def test_check_banner(self):
     check = SmtpHealthCheck()
     check._check_banner('220 Ok\r\n')
     self.assertEqual('220', check.results['Banner-Code'])
     self.assertEqual('Ok', check.results['Banner-Message'])
     self.assertEqual('OK', check.results['Status'])