def test01AddCredentials(self):
        wallet = self._addCredentials()
        
        self.assert_(
            len(wallet.retrieveCredentials(self.__class__.RESOURCE_ID)) == 1)

        assertion = wallet.retrieveCredentials(self.__class__.RESOURCE_ID)[-1]
        
        print("SAML Assertion:\n%s" % 
              prettyPrint(AssertionElementTree.toXML(assertion)))
 def test01AddCredentials(self):
     wallet = self._addCredentials()
     k = self.__class__.SITEA_ATTRIBUTEAUTHORITY_URI
     self.assert_(len(wallet.retrieveCredentials(k)) == 1)
     assertions = wallet.retrieveCredentials(
                         self.__class__.SITEA_ATTRIBUTEAUTHORITY_URI)
     self.assert_(assertions)
     
     print("SAML Assertion:\n%s" % 
           prettyPrint(AssertionElementTree.toXML(assertions[0])))
Esempio n. 3
0
    def test02ParseAssertion(self):
        assertion = self._createAttributeAssertionHelper()
        
        # Create ElementTree Assertion Element
        assertionElem = AssertionElementTree.toXML(assertion)
        
        self.assert_(ElementTree.iselement(assertionElem))
        
        # Serialise to output 
        xmlOutput = prettyPrint(assertionElem)       
           
        print("\n"+"_"*80)
        print(xmlOutput)
        print("_"*80)
                
        assertionStream = StringIO()
        assertionStream.write(xmlOutput)
        assertionStream.seek(0)

        tree = ElementTree.parse(assertionStream)
        elem2 = tree.getroot()
        
        assertion2 = AssertionElementTree.fromXML(elem2)
        self.assert_(assertion2)
Esempio n. 4
0
    def test01CreateAssertion(self):
         
        assertion = self._createAttributeAssertionHelper()

        
        # Create ElementTree Assertion Element
        assertionElem = AssertionElementTree.toXML(assertion)
        
        self.assert_(ElementTree.iselement(assertionElem))
        
        # Serialise to output 
        xmlOutput = prettyPrint(assertionElem)       
        self.assert_(len(xmlOutput))
        
        print("\n"+"_"*80)
        print(xmlOutput)
        print("_"*80)
    def _createAssertion(self, timeNow=None, validityDuration=60*60*8,
                         issuerName=BaseTestCase.SITEA_SAML_ISSUER_NAME):
        if timeNow is None:
            timeNow = datetime.utcnow()
            
        timeExpires = timeNow + timedelta(seconds=validityDuration)
        assertionStr = Template(
            self.__class__.ASSERTION_STR).substitute(
                dict(
                 issuerName=issuerName,
                 timeNow=SAMLDateTime.toString(timeNow), 
                 timeExpires=SAMLDateTime.toString(timeExpires)
                )
            )

        assertionStream = StringIO()
        assertionStream.write(assertionStr)
        assertionStream.seek(0)
        assertionElem = ElementTree.parse(assertionStream).getroot()
        return AssertionElementTree.fromXML(assertionElem)
 def serialiseAssertion(self, assertion):
     """Convert SAML assertion object into a string"""
     samlAssertionElem = AssertionElementTree.toXML(assertion)
     return ElementTree.tostring(samlAssertionElem)