Package ndg :: Package saml :: Package test :: Package binding :: Package soap :: Module test_attributeservice_paster
[hide private]

Source Code for Module ndg.saml.test.binding.soap.test_attributeservice_paster

  1  """SAML SOAP Binding Query/Response Interface with service hosted in 
  2  Paste paster web server 
  3   
  4  NERC DataGrid Project 
  5  """ 
  6  __author__ = "P J Kershaw" 
  7  __date__ = "01/07/10" 
  8  __copyright__ = "(C) 2010 Science and Technology Facilities Council" 
  9  __license__ = "http://www.apache.org/licenses/LICENSE-2.0" 
 10  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
 11  __revision__ = '$Id$' 
 12  import logging 
 13  logging.basicConfig(level=logging.DEBUG) 
 14   
 15  import unittest 
 16  from os import path 
 17  from ndg.saml import importElementTree 
 18  ElementTree = importElementTree() 
 19   
 20  from ndg.soap.utils.etree import prettyPrint 
 21   
 22  from ndg.saml.saml2.core import Attribute, StatusCode 
 23  from ndg.saml.xml.etree import ResponseElementTree 
 24  from ndg.saml.saml2.binding.soap.client.attributequery import \ 
 25      AttributeQuerySslSOAPBinding 
 26  from ndg.saml.test.binding.soap import WithPasterBaseTestCase     
 27       
 28       
29 -class SamlSslSoapBindingTestCase(WithPasterBaseTestCase):
30 """Test SAML SOAP Binding with SSL""" 31 SERVICE_URI = 'https://localhost:5443/attributeauthority' 32 SUBJECT = "https://openid.localhost/philip.kershaw" 33 SUBJECT_FORMAT = "urn:ndg:saml:openid" 34 CONFIG_FILENAME = 'attribute-interface.ini' 35 36 CLIENT_CERT_FILEPATH = path.join(WithPasterBaseTestCase.THIS_DIR, 37 'test.crt') 38 CLIENT_PRIKEY_FILEPATH = path.join(WithPasterBaseTestCase.THIS_DIR, 39 'test.key') 40 CLIENT_CACERT_DIR = path.join(WithPasterBaseTestCase.THIS_DIR, 'ca') 41 VALID_DNS = [ 42 '/O=NDG/OU=Security/CN=localhost', 43 ] 44
45 - def __init__(self, *arg, **kw):
46 kw['withSSL'] = True 47 super(SamlSslSoapBindingTestCase, self).__init__(*arg, **kw)
48
49 - def test01M2CryptoInstalled(self):
50 # Force error for M2Crypto not present 51 _support = AttributeQuerySslSOAPBinding.SSL_CONTEXT_PROXY_SUPPORT 52 AttributeQuerySslSOAPBinding.SSL_CONTEXT_PROXY_SUPPORT = False 53 try: 54 self.assertRaises(ImportError, AttributeQuerySslSOAPBinding) 55 finally: 56 AttributeQuerySslSOAPBinding.SSL_CONTEXT_PROXY_SUPPORT = _support 57 58 # Try again to really test all is well 59 try: 60 AttributeQuerySslSOAPBinding() 61 except ImportError, e: 62 self.fail('Import error with AttributeQuerySslSoapBinding: %s' % e)
63
64 - def test02SendQuery(self):
65 attributeQuery = AttributeQuerySslSOAPBinding() 66 67 attributeQuery.subjectIdFormat = self.__class__.SUBJECT_FORMAT 68 attributeQuery.clockSkewTolerance = 2. 69 attributeQuery.issuerName = '/O=Site A/CN=Authorisation Service' 70 71 query = attributeQuery.makeQuery() 72 attributeQuery.setQuerySubjectId(query, self.__class__.SUBJECT) 73 74 attribute = Attribute() 75 attribute.name = 'urn:ndg:saml:emailaddress' 76 attribute.friendlyName = 'emailAddress' 77 attribute.nameFormat = 'http://www.w3.org/2001/XMLSchema' 78 79 query.attributes.append(attribute) 80 81 attributeQuery.sslCACertDir = self.__class__.CLIENT_CACERT_DIR 82 attributeQuery.sslCertFilePath = self.__class__.CLIENT_CERT_FILEPATH 83 attributeQuery.sslPriKeyFilePath = self.__class__.CLIENT_PRIKEY_FILEPATH 84 attributeQuery.sslValidDNs = self.__class__.VALID_DNS 85 86 response = attributeQuery.send(query, uri=self.__class__.SERVICE_URI) 87 88 # Convert back to ElementTree instance read for string output 89 samlResponseElem = ResponseElementTree.toXML(response) 90 91 print("SAML Response ...") 92 print(ElementTree.tostring(samlResponseElem)) 93 print("Pretty print SAML Response ...") 94 print(prettyPrint(samlResponseElem)) 95 96 self.assert_(response.status.statusCode.value==StatusCode.SUCCESS_URI)
97 98 99 if __name__ == "__main__": 100 unittest.main() 101