~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to mapiproxy/services/ocsmanager/ocsmanager/tests/functional/test_authenticate.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from ocsmanager.tests import *
 
2
import paste.httpexceptions as httpexceptions
 
3
from xml.etree import ElementTree as ET
 
4
 
 
5
class TestAuthenticateController(TestController):
 
6
 
 
7
    def test_token(self):
 
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"
 
13
 
 
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)
 
17
        number = 0
 
18
        for token in 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
 
25
 
 
26
        salt = xmlData.find("salt")
 
27
        assert salt is not None, "No salt received"
 
28
 
 
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
 
39
 
 
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'), 
 
43
                                 params='')
 
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
 
50