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 | self.workdir = tempfile.mkdtemp() |
---|
14 | self.paste_conf1 = os.path.join( |
---|
15 | os.path.dirname(__file__), 'sample1.ini') |
---|
16 | |
---|
17 | def tearDown(self): |
---|
18 | shutil.rmtree(self.workdir) |
---|
19 | |
---|
20 | def test_paste_deploy_loader(self): |
---|
21 | # we can load the CAS server via paste.deploy plugin |
---|
22 | app = loadapp('config:%s' % self.paste_conf1) |
---|
23 | assert isinstance(app, CASServer) |
---|
24 | |
---|
25 | def test_paste_deploy_options(self): |
---|
26 | # we can set CAS server-related options via paste.deploy config |
---|
27 | app = loadapp('config:%s' % self.paste_conf1) |
---|
28 | assert isinstance(app, CASServer) |
---|
29 | |
---|
30 | def test_call_root(self): |
---|
31 | # the CAS protocol requires no root |
---|
32 | app = CASServer() |
---|
33 | req = Request.blank('http://localhost/') |
---|
34 | resp = app(req) |
---|
35 | assert resp.status == '404 Not Found' |
---|
36 | |
---|
37 | def test_first_time_login(self): |
---|
38 | # we can get a login page |
---|
39 | app = CASServer() |
---|
40 | req = Request.blank('http://localhost/login') |
---|
41 | resp = app(req) |
---|
42 | assert resp.status == '200 OK' |
---|
43 | |
---|
44 | def test_validate(self): |
---|
45 | # we can access a validation page |
---|
46 | app = CASServer() |
---|
47 | req = Request.blank('http://localhost/validate') |
---|
48 | resp = app(req) |
---|
49 | assert resp.status == '501 Not Implemented' |
---|
50 | |
---|
51 | def test_logout(self): |
---|
52 | # we can access a logout page |
---|
53 | app = CASServer() |
---|
54 | req = Request.blank('http://localhost/logout') |
---|
55 | resp = app(req) |
---|
56 | assert resp.status == '501 Not Implemented' |
---|
57 | |
---|
58 | def test_login_simple(self): |
---|
59 | # a simple login with no service will result in login screen |
---|
60 | # (2.1.1#service of protocol specs) |
---|
61 | app = CASServer() |
---|
62 | req = Request.blank('http://localhost/login') |
---|
63 | resp = app(req) |
---|
64 | assert resp.status == '200 OK' |
---|
65 | assert resp.content_type == 'text/html' |
---|
66 | assert b'<form ' in resp.body |
---|