1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
import unittest |
4
|
|
|
|
5
|
|
|
from crabpy.wsse import UsernameDigestToken |
6
|
|
|
|
7
|
|
|
from base64 import b64encode |
8
|
|
|
|
9
|
|
|
from suds.wsse import wssens |
10
|
|
|
|
11
|
|
|
from suds.sax.element import Element |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class UsernameDigestTokenTests(unittest.TestCase): |
15
|
|
|
|
16
|
|
|
def setUp(self): |
17
|
|
|
self.token = UsernameDigestToken('myself', 'mypassword') |
18
|
|
|
|
19
|
|
|
def tearDown(self): |
20
|
|
|
self.token = None |
21
|
|
|
|
22
|
|
|
def test_simple(self): |
23
|
|
|
self.assertIsInstance(self.token, UsernameDigestToken) |
24
|
|
|
xml = self.token.xml() |
25
|
|
|
self.assertIsInstance(xml, Element) |
26
|
|
|
self.assertIsInstance(xml.getChild('Username', ns=wssens), Element) |
27
|
|
|
self.assertIsInstance(xml.getChild('Password', ns=wssens), Element) |
28
|
|
|
self.assertIsInstance(xml.getChild('Nonce', ns=wssens), Element) |
29
|
|
|
|
30
|
|
|
def test_set_custom_nonce(self): |
31
|
|
|
self.assertIsInstance(self.token, UsernameDigestToken) |
32
|
|
|
self.token.setnonce('NONCE'.encode('utf-8')) |
33
|
|
|
xml = self.token.xml() |
34
|
|
|
self.assertIsInstance(xml, Element) |
35
|
|
|
self.assertIsInstance(xml.getChild('Username', ns=wssens), Element) |
36
|
|
|
self.assertIsInstance(xml.getChild('Password', ns=wssens), Element) |
37
|
|
|
self.assertIsInstance(xml.getChild('Nonce', ns=wssens), Element) |
38
|
|
|
self.assertEquals( |
39
|
|
|
xml.getChild('Nonce', ns=wssens).getText(), |
40
|
|
|
b64encode('NONCE'.encode('utf-8')).decode('utf-8') |
41
|
|
|
) |
42
|
|
|
|