-def force_remove(op, name, info):
- os.chmod(name, 0700)
- os.remove(name)
-
-
-def setup_http(httpdir, addr, port):
- os.mkdir(httpdir)
- os.mkdir(httpdir + '/conf.d')
- os.mkdir(httpdir + '/html')
- os.mkdir(httpdir + '/logs')
- os.symlink('/etc/httpd/modules', httpdir + '/modules')
-
- with open('tests/httpd.conf') as f:
- t = Template(f.read())
- text = t.substitute({'HTTPROOT': httpdir,
- 'HTTPADDR': addr, 'HTTPPORT': port})
- with open(httpdir + '/httpd.conf', 'w+') as f:
- f.write(text)
-
-
-def setup_test(path, test):
- profile = 'tests/%s.cfg' % test
- if not os.path.exists(profile):
- raise ValueError('Unrecognized test name [%s]' % test)
-
- opts = {}
- config = ConfigParser.ConfigParser()
- config.read(profile)
- if 'tests' not in config.sections():
- raise ValueError('Missing [tests] in profile [%s]' % test)
- T = config.options('tests')
- for t in T:
- opts[t] = config.get('tests', t)
-
- base = '%s/%s' % (path, test)
- if os.path.exists(base):
- shutil.rmtree(base, onerror=force_remove)
- os.makedirs(base)
- shutil.copytree('templates', base + '/templates')
- os.mkdir(base + '/etc')
- os.mkdir(base + '/lib')
- os.mkdir(base + '/lib/' + test)
- os.mkdir(base + '/log')
-
- with open(profile) as f:
- t = Template(f.read())
- text = t.substitute({'TESTDIR': base, 'ROOTDIR': os.getcwd(),
- 'TEST_USER': pwd.getpwuid(os.getuid())[0]})
- with open(base + '/profile.cfg', 'w+') as f:
- f.write(text)
-
- opts['basedir'] = base
- return opts
-
-
-def generate_profile(profile, name):
- config = ConfigParser.ConfigParser()
- config.read(profile)
-
- global_section = '%s_globals' % name
- global_options = {}
- if global_section in config.sections():
- G = config.options(global_section)
- for g in G:
- global_options[g] = config.get(global_section, g)
-
- args_section = '%s_arguments' % name
- args_options = {}
- if args_section in config.sections():
- A = config.options(args_section)
- for a in A:
- args_options[a] = config.get(args_section, a)
-
- newconf = ConfigParser.ConfigParser()
- newconf.add_section('globals')
- for k in global_options.keys():
- newconf.set('globals', k, global_options[k])
- newconf.add_section('arguments')
- for k in args_options.keys():
- newconf.set('arguments', k, args_options[k])
-
- filename = os.path.join(os.path.dirname(profile), '%s_profile.cfg' % name)
- with open(filename, 'wb') as f:
- newconf.write(f)
-
- return filename
-
-
-def fixup_sp_httpd(httpdir):
- location = """
-
-Alias /sp ${HTTPDIR}/sp
-
-<Directory ${HTTPDIR}/sp>
- Require all granted
-</Directory>
-"""
- index = """WORKS!"""
-
- t = Template(location)
- text = t.substitute({'HTTPDIR': httpdir})
- with open(httpdir + '/conf.d/ipsilon-saml.conf', 'a') as f:
- f.write(text)
-
- os.mkdir(httpdir + '/sp')
- with open(httpdir + '/sp/index.html', 'w') as f:
- f.write(index)
-
-