summaryrefslogtreecommitdiffstats
path: root/tests/integration/saml2/__init__.py
blob: 6b3123c42681b0a253dbed24ef15cd1a4f5ccfd5 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sys
import os
import signal
import subprocess
import time
import twill
import urllib2

AUTHENTIC_SRCDIR = '/usr/local/src/authentic'
AUTHENTICCTL = '/usr/sbin/authenticctl.py'
AUTHENTIC_DATA_DIR = '/usr/share/authentic/'
LCSCTL = '/usr/sbin/lcsctl.py'
LCS_DATADIR = '/usr/share/lcs/'

try:
    from config import *
except ImportError:
    pass

pids = []

def waitforport(port, start):
    while True:
        if time.time() - start > 90:
            raise Exception('Servers did not start in 90 seconds!!')
        time.sleep(5)
        try:
            urllib2.urlopen('http://localhost:%s' % port)
        except urllib2.URLError:
            continue
        else:
            break

def setup():
    if not os.path.exists(AUTHENTIC_SRCDIR):
        print >> sys.stderr, 'Authentic source dir (%s) does not exist' % AUTHENTIC_SRCDIR
        print >> sys.stderr, 'Create it or edit tests/config.py to match your local installation'
        sys.exit(1)

    twill.commands.reset_browser()
    twill.set_output(file('/dev/null', 'w'))
    base = []
    if os.path.exists('/usr/bin/valgrind'):
        base = ['./valgrind-wrapper.sh', 'python']

    os.environ['PYTHONPATH'] = '../../bindings/python:../../bindings/python/.libs'
    os.mkdir('/tmp/.tests')
    authentic_command = base + [AUTHENTICCTL, 'start',
            '--app-dir', '/tmp/.tests/authentictests',
            '--data-dir', AUTHENTIC_DATADIR,
            '--extra', os.path.join(AUTHENTIC_SRCDIR, 'extra', 'conformance'),
            '--port', '10001', '--http', '--silent']
    print authentic_command
    sp = subprocess.Popen(authentic_command)
    pids.append(sp.pid)
    lcs_command = base + [LCSCTL, 'start',
            '--app-dir', '/tmp/.tests/lcstests',
            '--data-dir', LCS_DATADIR,
            '--port', '10002', '--http', '--silent']
    print lcs_command
    sp = subprocess.Popen(lcs_command)
    pids.append(sp.pid)

    # Wait for the daemons to load themselves
    starttime = time.time()
    waitforport(10001, starttime)
    waitforport(10002, starttime)


def teardown():
    for pid in pids:
        try:
            # valgrind seems to prefer SIGINT to SIGTERM
            os.kill(pid, signal.SIGINT)
        except OSError:
            print >> sys.stderr, 'failed to kill pid %s' % pid
    os.system('rm -rf /tmp/.tests/')