コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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()
コード例 #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)
コード例 #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)
コード例 #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()
コード例 #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)
コード例 #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)
コード例 #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())
コード例 #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())
コード例 #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)
コード例 #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)
コード例 #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'])
コード例 #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'])
コード例 #23
0
 def test_close_none(self):
     check = SmtpHealthCheck()
     self.mox.ReplayAll()
     check._close(False)
コード例 #24
0
 def test_connect_bad_dns(self):
     check = SmtpHealthCheck()
     with self.assertRaises(DNSError):
         check._connect([])
コード例 #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)
コード例 #26
0
 def test_check_output_critical(self):
     check = SmtpHealthCheck()
     check.results = OrderedDict([('Status', 'CRITICAL')])
     f = StringIO()
     self.assertEqual(1, check.output(f))
コード例 #27
0
 def test_check_output_critical(self):
     check = SmtpHealthCheck()
     check.results = OrderedDict([('Status', 'CRITICAL')])
     f = StringIO()
     self.assertEqual(1, check.output(f))
コード例 #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'])
コード例 #29
0
 def test_connect_bad_dns(self):
     check = SmtpHealthCheck()
     with self.assertRaises(DNSError):
         check._connect([])
コード例 #30
0
 def test_constructor(self):
     check = SmtpHealthCheck()
     self.assertEquals({'Status': 'CRITICAL'}, check.results)
コード例 #31
0
 def test_close_none(self):
     check = SmtpHealthCheck()
     self.mox.ReplayAll()
     check._close(False)
コード例 #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'])
コード例 #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'])
コード例 #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'])
コード例 #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)
コード例 #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'])
コード例 #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'])