File: test_syslog.py

package info (click to toggle)
nufw 2.4.3-2.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 5,728 kB
  • sloc: ansic: 32,174; sh: 10,146; python: 4,176; makefile: 965; perl: 630; lex: 176; php: 168; yacc: 117; xml: 34
file content (42 lines) | stat: -rwxr-xr-x 1,264 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
from unittest import TestCase, main
from common import getNuauthConf, createClientWithCerts, connectClient
from nuauth import Nuauth
from nuauth_conf import NuauthConf
from logging import warning

class TestLog(TestCase):
    def setUp(self):
        config = getNuauthConf()
        config["nuauth_tls_request_cert"] = "0"
        config["nuauth_user_logs_module"] = '"syslog"'
        config["nuauth_user_session_logs_module"] = '"syslog"'
        self.nuauth = Nuauth(config)

    def tearDown(self):
        self.nuauth.stop()

    def findLog(self, match):
        warning("Search string >%s< in log" % match)
        matched = False
        for line in self.nuauth.readlines(total_timeout=2.0):
            if match in line:
                return True
        return False

    def testLogin(self):
        # Client login
        client = createClientWithCerts()
        self.assert_(connectClient(client))

        # Check log output
        self.assert_(self.findLog("[nuauth] User %s connect on " % client.username))

        # Client logout
        client.stop()
        self.assert_(self.findLog("[nuauth] User %s disconnect on " % client.username))

if __name__ == "__main__":
    print "Test nuauth module 'log_syslog'"
    main()