def test_replace_username_token_elem_missing_type(): """ Tests whether the expected exception is being raized while replacing the username token which doesn't have the 'Type' attribute. """ wsse = WSSE() soap = etree.fromstring(get_data(True)) # _replace_username_token_elem # Scenario 1) Everything goes well, SOAP's correct and contains the expected # element. wsse_password = wsse_password_xpath(soap) old_elem, attr = wsse._replace_username_token_elem(soap, wsse_password, 'Type') eq_(old_elem, raw_password) # Scenario 2) SOAP message doesn't have the expected element. soap_invalid = etree.fromstring(get_data(False)) foobar = etree.XPath('//foo')(soap_invalid) try: wsse._replace_username_token_elem(soap_invalid, foobar, 'bar') except SecurityException, e: eq_( e.description, "Element [/soapenv:Envelope/soapenv:Header/wsse:Security/wsse:UsernameToken] doesn't exist" )
def test_replace_username_token_elem_ok(): """ Tests whether replacing the username token works fine. """ wsse = WSSE() soap = etree.fromstring(get_data()) wsse_password = wsse_password_xpath(soap) old_elem, attr = wsse._replace_username_token_elem(soap, wsse_password, 'Type') eq_(old_elem, raw_password)
def test_replace_username_token_elem_missing_type(): """ Tests whether the expected exception is being raized while replacing the username token which doesn't have the 'Type' attribute. """ wsse = WSSE() soap = etree.fromstring(get_data(True)) # _replace_username_token_elem # Scenario 1) Everything goes well, SOAP's correct and contains the expected # element. wsse_password = wsse_password_xpath(soap) old_elem, attr = wsse._replace_username_token_elem(soap, wsse_password, 'Type') eq_(old_elem, raw_password) # Scenario 2) SOAP message doesn't have the expected element. soap_invalid = etree.fromstring(get_data(False)) foobar = etree.XPath('//foo')(soap_invalid) try: wsse._replace_username_token_elem(soap_invalid, foobar, 'bar') except SecurityException, e: eq_(e.description, "Element [/soapenv:Envelope/soapenv:Header/wsse:Security/wsse:UsernameToken] doesn't exist")