def test_get_digest(): """ Checks whether computing the digest works fine. """ wsse = WSSE() # _get_digest nonce = 'NTA5OTA3YTk4Zjk5NGVhYWJhNTZkMTVkZGIzZjM2NzY=\n' digest = wsse._get_digest(raw_password, nonce, '2010-12-03T20:13:10.602Z') eq_(digest, 'OGhlMsnX6G7l859oktI6dUBfSjs=')
def get_data(header=True, username=True, nonce=True, created=True, password_digest=False, valid_password=True, valid_username=True, send_password_type=True, supported_password_type=True): if header: wsse_username = '******' wsse_password = '******' wsu_created = '<wsu:Created>{0}</wsu:Created>' wsse_nonce = '<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">{0}</wsse:Nonce>' if username: if valid_username: username = wsse_username.format(raw_username) else: username = wsse_username.format(uuid4().hex) else: username = '' if nonce: nonce_value = uuid4().hex.encode('base64') nonce = wsse_nonce.format(nonce_value) else: nonce = '' if created: created_value = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime()) created_value += '.000Z' created = wsu_created.format(created_value) else: created = '' created_value = '' if password_digest: if send_password_type: if supported_password_type: password_type = wsse_password_type_digest else: password_type = 'abcdef' else: password_type = '' wsse = WSSE() if valid_password: password_value = wsse._get_digest(raw_password, nonce_value, created_value) else: password_value = wsse._get_digest(uuid4().hex, nonce_value, created_value) else: if send_password_type: if supported_password_type: password_type = wsse_password_type_text else: password_type = 'abcdef' else: password_type = '' if valid_password: password_value = raw_password else: password_value = uuid4().hex password = wsse_password.format(password_type=password_type, password_value=password_value) return """ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> {username} {password} {created} {nonce} </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <foo> <bar>123</bar> </foo> </soapenv:Body> </soapenv:Envelope>""".format(username=username, password=password, created=created, nonce=nonce) else: return """