Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit bea12cf

Browse files
committed
Add client test mocks for SOAP endpoints
1 parent 6961846 commit bea12cf

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

test/client.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
from datetime import datetime, timedelta
4+
import json
45
import time
56
import re
67
import unittest
@@ -18,6 +19,7 @@ class Data:
1819
"""
1920

2021
userId = "fred.2"
22+
secToken = "t={}&p=".format("s" * 1048)
2123
skypeToken = "s" * 424
2224
regToken = "r" * 886
2325
tokenExpiry = datetime.now() + timedelta(days=1)
@@ -47,19 +49,44 @@ def registerMocks(regTokenRedirect=False, guest=False):
4749
regTokenRedirect (bool): whether to emulate the 'user is on another cloud' host redirect
4850
guest (bool): whether to emulate a guest account
4951
"""
50-
# Retrieve the login form.
52+
# Live login: retrieve the login form.
5153
responses.add(responses.GET, "{0}/oauth/microsoft".format(SkypeConnection.API_LOGIN), status=200,
5254
adding_headers=HTTPHeaderDict((("Set-Cookie", "MSPRequ=MSPRequ"),
5355
("Set-Cookie", "MSPOK=MSPOK"))), content_type="text/html",
5456
body="""<html><body><input name="PPFT" value="ppftvalue"></body></html>""")
55-
# Submit username/password to form.
57+
# Live login: submit username/password to form.
5658
responses.add(responses.POST, "{0}/ppsecure/post.srf".format(SkypeConnection.API_MSACC),
5759
status=200, content_type="text/html",
5860
body="""<html><body><input id="t" value="tvalue"></body></html>""")
5961
responses.add(responses.POST, "{0}/microsoft".format(SkypeConnection.API_LOGIN),
6062
status=200, content_type="text/html",
6163
body="""<html><body><input name="skypetoken" value="{0}">
6264
<input name="expires_in" value="86400"></body></html>""".format(Data.skypeToken))
65+
# SOAP login: submit username/password.
66+
secTokenBody = """<?xml version="1.0" encoding="utf-8" ?>
67+
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
68+
<S:Body>
69+
<wst:RequestSecurityTokenResponseCollection
70+
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"
71+
xmlns:wst="http://schemas.xmlsoap.org/ws/2004/04/trust"
72+
xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext"
73+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
74+
xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"
75+
xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy"
76+
xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault">
77+
<wst:RequestSecurityTokenResponse>
78+
<wst:RequestedSecurityToken>
79+
<wsse:BinarySecurityToken Id="Compact0">{}</wsse:BinarySecurityToken>
80+
</wst:RequestedSecurityToken>
81+
</wst:RequestSecurityTokenResponse>
82+
</wst:RequestSecurityTokenResponseCollection>
83+
</S:Body>
84+
</S:Envelope>""".format(Data.secToken)
85+
responses.add(responses.POST, "{0}/RST.srf".format(SkypeConnection.API_MSACC),
86+
status=200, content_type="text/xml", body=secTokenBody)
87+
# SOAP login: exchange edge token.
88+
responses.add(responses.POST, SkypeConnection.API_EDGE, status=200, content_type="application/json",
89+
body=json.dumps({"skypetoken": Data.skypeToken, "expiresIn": 86400}))
6390
# Request registration token.
6491
expiry = int(time.mktime((datetime.now() + timedelta(days=1)).timetuple()))
6592
msgsHost = Data.msgsHost if regTokenRedirect else SkypeConnection.API_MSGSHOST

0 commit comments

Comments
 (0)