1
1
#!/usr/bin/env python
2
2
3
3
from datetime import datetime , timedelta
4
+ import json
4
5
import time
5
6
import re
6
7
import unittest
@@ -18,6 +19,7 @@ class Data:
18
19
"""
19
20
20
21
userId = "fred.2"
22
+ secToken = "t={}&p=" .format ("s" * 1048 )
21
23
skypeToken = "s" * 424
22
24
regToken = "r" * 886
23
25
tokenExpiry = datetime .now () + timedelta (days = 1 )
@@ -47,19 +49,44 @@ def registerMocks(regTokenRedirect=False, guest=False):
47
49
regTokenRedirect (bool): whether to emulate the 'user is on another cloud' host redirect
48
50
guest (bool): whether to emulate a guest account
49
51
"""
50
- # Retrieve the login form.
52
+ # Live login: retrieve the login form.
51
53
responses .add (responses .GET , "{0}/oauth/microsoft" .format (SkypeConnection .API_LOGIN ), status = 200 ,
52
54
adding_headers = HTTPHeaderDict ((("Set-Cookie" , "MSPRequ=MSPRequ" ),
53
55
("Set-Cookie" , "MSPOK=MSPOK" ))), content_type = "text/html" ,
54
56
body = """<html><body><input name="PPFT" value="ppftvalue"></body></html>""" )
55
- # Submit username/password to form.
57
+ # Live login: submit username/password to form.
56
58
responses .add (responses .POST , "{0}/ppsecure/post.srf" .format (SkypeConnection .API_MSACC ),
57
59
status = 200 , content_type = "text/html" ,
58
60
body = """<html><body><input id="t" value="tvalue"></body></html>""" )
59
61
responses .add (responses .POST , "{0}/microsoft" .format (SkypeConnection .API_LOGIN ),
60
62
status = 200 , content_type = "text/html" ,
61
63
body = """<html><body><input name="skypetoken" value="{0}">
62
64
<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 }))
63
90
# Request registration token.
64
91
expiry = int (time .mktime ((datetime .now () + timedelta (days = 1 )).timetuple ()))
65
92
msgsHost = Data .msgsHost if regTokenRedirect else SkypeConnection .API_MSGSHOST
0 commit comments