1 | import os |
---|
2 | import shutil |
---|
3 | import tempfile |
---|
4 | import unittest |
---|
5 | from paste.deploy import loadapp |
---|
6 | from webob import Request |
---|
7 | from waeup.cas.server import CASServer |
---|
8 | |
---|
9 | |
---|
10 | class CASServerTests(unittest.TestCase): |
---|
11 | |
---|
12 | def setUp(self): |
---|
13 | # Create a new location where tempfiles are created. This way |
---|
14 | # also temporary dirs of local CASServers can be removed on |
---|
15 | # tear-down. |
---|
16 | self._new_tmpdir = tempfile.mkdtemp() |
---|
17 | self._old_tmpdir = tempfile.tempdir |
---|
18 | tempfile.tempdir = self._new_tmpdir |
---|
19 | self.workdir = os.path.join(self._new_tmpdir, 'home') |
---|
20 | self.db_path = os.path.join(self.workdir, 'mycas.db') |
---|
21 | self.paste_conf1 = os.path.join( |
---|
22 | os.path.dirname(__file__), 'sample1.ini') |
---|
23 | |
---|
24 | def tearDown(self): |
---|
25 | # remove local tempfile and reset old tempdir setting |
---|
26 | if os.path.isdir(self._new_tmpdir): |
---|
27 | shutil.rmtree(self._new_tmpdir) |
---|
28 | tempfile.tempdir = self._old_tmpdir |
---|
29 | |
---|
30 | def test_paste_deploy_loader(self): |
---|
31 | # we can load the CAS server via paste.deploy plugin |
---|
32 | app = loadapp('config:%s' % self.paste_conf1) |
---|
33 | assert isinstance(app, CASServer) |
---|
34 | |
---|
35 | def test_paste_deploy_options(self): |
---|
36 | # we can set CAS server-related options via paste.deploy config |
---|
37 | app = loadapp('config:%s' % self.paste_conf1) |
---|
38 | assert isinstance(app, CASServer) |
---|
39 | |
---|
40 | def test_call_root(self): |
---|
41 | # the CAS protocol requires no root |
---|
42 | app = CASServer() |
---|
43 | req = Request.blank('http://localhost/') |
---|
44 | resp = app(req) |
---|
45 | assert resp.status == '404 Not Found' |
---|
46 | |
---|
47 | def test_first_time_login(self): |
---|
48 | # we can get a login page |
---|
49 | app = CASServer() |
---|
50 | req = Request.blank('http://localhost/login') |
---|
51 | resp = app(req) |
---|
52 | assert resp.status == '200 OK' |
---|
53 | |
---|
54 | def test_validate(self): |
---|
55 | # we can access a validation page |
---|
56 | app = CASServer() |
---|
57 | req = Request.blank('http://localhost/validate') |
---|
58 | resp = app(req) |
---|
59 | assert resp.status == '501 Not Implemented' |
---|
60 | |
---|
61 | def test_logout(self): |
---|
62 | # we can access a logout page |
---|
63 | app = CASServer() |
---|
64 | req = Request.blank('http://localhost/logout') |
---|
65 | resp = app(req) |
---|
66 | assert resp.status == '501 Not Implemented' |
---|
67 | |
---|
68 | def test_login_simple(self): |
---|
69 | # a simple login with no service will result in login screen |
---|
70 | # (2.1.1#service of protocol specs) |
---|
71 | app = CASServer() |
---|
72 | req = Request.blank('http://localhost/login') |
---|
73 | resp = app(req) |
---|
74 | assert resp.status == '200 OK' |
---|
75 | assert resp.content_type == 'text/html' |
---|
76 | assert b'<form ' in resp.body |
---|