Commit d14b24b0 authored by ale's avatar ale

add tests for vpn_app; fix error in to_pkcs12()

parent 1adf6ab2
import tempfile
import shutil
import unittest
from flask import session
from autovpn import vpn_app
class VpnAppTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.config = {
'DEBUG': 'true',
'SECRET_KEY': 'somesecret',
'VPN_CA_ROOT': self.tmpdir,
'VPN_CA_SUBJECT': {'CN': 'test CA', 'O': 'test'},
'VPN_CA_BITS': 1024,
'VPN_SITE_URL': 'http://localhost:4000/',
'FOOTER': '''
<p class="footer">
built by <a href=""></a>
'AUTH_FUNCTION': lambda x, y: (x and y and x == y),
} = vpn_app.make_app(self.config)
def tearDown(self):
def test_login_ok(self):
with as c:
rv = c.get('/login')
csrf = session['_csrf']
rv ='/login', data={
'_csrf': csrf,
'username': 'admin',
'password': 'admin'},
self.assertTrue('download of the ZIP file' in
def test_login_fail(self):
with as c:
rv = c.get('/login')
csrf = session['_csrf']
rv ='/login', data={
'_csrf': csrf,
'username': 'user',
'password': 'wrong password'},
self.assertTrue('Authentication failed' in
def test_cert_dl(self):
with as c:
with c.session_transaction() as sess:
sess['dl_ok'] = True
sess['_csrf'] = 'csrf'
sess['logged_in'] = True
rv = c.get('/newcertdl?_csrf=csrf')
self.assertEquals('200 OK', rv.status)
self.assertEquals('application/zip', rv.content_type)
......@@ -139,7 +139,7 @@ def to_pkcs12(crt_pem, key_pem, ca_pem):
for name, content in [
('crt.pem', crt_pem), ('key.pem', key_pem), ('ca.pem', ca_pem)]:
with open(os.path.join(tmpdir, name)) as fd:
with open(os.path.join(tmpdir, name), 'w') as fd:
pipe = subprocess.Popen(
['openssl', 'pkcs12', '-export', '-password', 'pass:',
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment