1
from ocsmanager.tests import *
2
import paste.httpexceptions as httpexceptions
3
from xml.etree import ElementTree as ET
5
class TestAuthenticateController(TestController):
8
""" Test token function with XML payload using valid username. """
9
response = self.app.post(url(controller='authenticate', action='token'),
10
params={'payload':'<!DOCTYPE ocsmanager><xml><login>jkerihuel</login></xml>'})
11
xmlData = ET.XML(response.body)
12
assert xmlData is not None, "expected valid XML to be returned"
14
tokens = xmlData.findall("token")
15
assert tokens is not None, "No token received"
16
assert len(tokens) == 2, "2 tokens expected got %d" % len(tokens)
19
assert "type" in token.attrib, 'no type option specified: %s' % token.attrib
20
assert token.text is not None, 'no text value for token type=%s' % token.attrib['type']
21
if "type" in token.attrib:
22
if token.attrib["type"] == "session": number += 1
23
if token.attrib["type"] == "salt" : number += 1
24
assert number == 2, "Invalid token types: got %d on 2" % number
26
salt = xmlData.find("salt")
27
assert salt is not None, "No salt received"
29
def test_token_no_login(self):
30
""" Test token function with XML payload without username. """
31
response = self.app.post(url(controller='authenticate', action='token'),
32
params={'payload':'<!DOCTYPE ocsmanager><xml><login></login></xml>'})
33
xmlData = ET.XML(response.body)
34
assert xmlData is not None, "expected valid XML to be returned"
35
error = xmlData.find('error')
36
assert error is not None
37
code = error.attrib['code']
38
assert code == '417', "Invalid error code %s, expected 417" % code
40
def test_token_no_payload(self):
41
""" Test token with no payload. Expect error XML with code 417."""
42
response = self.app.post(url(controller='authenticate', action='token'),
44
xmlData = ET.XML(response.body)
45
assert xmlData is not None, "expected valid XML to be returned"
46
error = xmlData.find('error')
47
assert error is not None
48
code = error.attrib['code']
49
assert code == '417', "Invalid error code %s, expected 417" % code