@@ -1465,195 +1465,5 @@ class TestOpenID2SHA256(TestDiffieHellmanResponseParameters, unittest.TestCase):
14651465else :
14661466 warnings .warn ("Not running SHA256 association session tests." )
14671467
1468- class ErrorRaisingConsumer (GenericConsumer ):
1469- return_messages = []
1470-
1471- def _requestAssociation (self , endpoint , assoc_type , session_type ):
1472- m = self .return_messages .pop (0 )
1473- if isinstance (m , Message ):
1474- raise ServerError (m )
1475- else :
1476- return m
1477-
1478- class TestOpenID2SessionNegotiation (unittest .TestCase , CatchLogs ):
1479- def setUp (self ):
1480- CatchLogs .setUp (self )
1481- self .consumer = ErrorRaisingConsumer (store = None )
1482-
1483- self .endpoint = OpenIDServiceEndpoint ()
1484- self .endpoint .type_uris = [OPENID2_NS ]
1485- self .endpoint .server_url = 'bogus'
1486-
1487- def testBadResponse (self ):
1488- self .consumer .return_messages = [Message (self .endpoint .preferredNamespace ())]
1489- self .assertEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1490- self .failUnlessLogMatches ('Server error when requesting an association' )
1491-
1492- def testEmptyAssocType (self ):
1493- msg = Message (self .endpoint .preferredNamespace ())
1494- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1495- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1496- msg .setArg (OPENID_NS , 'assoc_type' , None )
1497- msg .setArg (OPENID_NS , 'session_type' , 'new-session-type' )
1498-
1499- self .consumer .return_messages = [msg ]
1500- self .assertEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1501-
1502- self .failUnlessLogMatches ('Unsupported association type' ,
1503- 'Server responded with unsupported association ' +
1504- 'session but did not supply a fallback.' )
1505-
1506- def testEmptySessionType (self ):
1507- msg = Message (self .endpoint .preferredNamespace ())
1508- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1509- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1510- msg .setArg (OPENID_NS , 'assoc_type' , 'new-assoc-type' )
1511- msg .setArg (OPENID_NS , 'session_type' , None )
1512-
1513- self .consumer .return_messages = [msg ]
1514- self .assertEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1515-
1516- self .failUnlessLogMatches ('Unsupported association type' ,
1517- 'Server responded with unsupported association ' +
1518- 'session but did not supply a fallback.' )
1519-
1520- def testNotAllowed (self ):
1521- allowed_types = [
1522- ('assoc_bogus' , 'session_bogus' ),
1523- ]
1524-
1525- negotiator = association .SessionNegotiator (allowed_types )
1526- self .consumer .negotiator = negotiator
1527-
1528- msg = Message (self .endpoint .preferredNamespace ())
1529- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1530- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1531- msg .setArg (OPENID_NS , 'assoc_type' , 'not-allowed' )
1532- msg .setArg (OPENID_NS , 'session_type' , 'not-allowed' )
1533-
1534- self .consumer .return_messages = [msg ]
1535- self .assertEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1536-
1537- self .failUnlessLogMatches ('Unsupported association type' ,
1538- 'Server sent unsupported session/association type:' )
1539-
1540- def testUnsupportedWithRetry (self ):
1541- msg = Message (self .endpoint .preferredNamespace ())
1542- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1543- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1544- msg .setArg (OPENID_NS , 'assoc_type' , 'HMAC-SHA1' )
1545- msg .setArg (OPENID_NS , 'session_type' , 'DH-SHA1' )
1546-
1547- assoc = association .Association (
1548- 'handle' , 'secret' , 'issued' , 10000 , 'HMAC-SHA1' )
1549-
1550- self .consumer .return_messages = [msg , assoc ]
1551- self .assertTrue (self .consumer ._negotiateAssociation (self .endpoint ) is assoc )
1552-
1553- self .failUnlessLogMatches ('Unsupported association type' )
1554-
1555- def testUnsupportedWithRetryAndFail (self ):
1556- msg = Message (self .endpoint .preferredNamespace ())
1557- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1558- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1559- msg .setArg (OPENID_NS , 'assoc_type' , 'HMAC-SHA1' )
1560- msg .setArg (OPENID_NS , 'session_type' , 'DH-SHA1' )
1561-
1562- self .consumer .return_messages = [msg ,
1563- Message (self .endpoint .preferredNamespace ())]
1564-
1565- self .failUnlessEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1566-
1567- self .failUnlessLogMatches ('Unsupported association type' ,
1568- 'Server %s refused' % (self .endpoint .server_url ))
1569-
1570- def testValid (self ):
1571- assoc = association .Association (
1572- 'handle' , 'secret' , 'issued' , 10000 , 'HMAC-SHA1' )
1573-
1574- self .consumer .return_messages = [assoc ]
1575- self .assertTrue (self .consumer ._negotiateAssociation (self .endpoint ) is assoc )
1576- self .failUnlessLogEmpty ()
1577-
1578- class TestOpenID1SessionNegotiation (unittest .TestCase , CatchLogs ):
1579- def setUp (self ):
1580- CatchLogs .setUp (self )
1581- self .consumer = ErrorRaisingConsumer (store = None )
1582-
1583- self .endpoint = OpenIDServiceEndpoint ()
1584- self .endpoint .type_uris = [OPENID1_NS ]
1585- self .endpoint .server_url = 'bogus'
1586-
1587- def testBadResponse (self ):
1588- self .consumer .return_messages = [Message (self .endpoint .preferredNamespace ())]
1589- self .assertEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1590- self .failUnlessLogMatches ('Server error when requesting an association' )
1591-
1592- def testEmptyAssocType (self ):
1593- msg = Message (self .endpoint .preferredNamespace ())
1594- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1595- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1596- msg .setArg (OPENID_NS , 'assoc_type' , None )
1597- msg .setArg (OPENID_NS , 'session_type' , 'new-session-type' )
1598-
1599- self .consumer .return_messages = [msg ]
1600- self .assertEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1601-
1602- self .failUnlessLogMatches ('Server error when requesting an association' )
1603-
1604- def testEmptySessionType (self ):
1605- msg = Message (self .endpoint .preferredNamespace ())
1606- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1607- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1608- msg .setArg (OPENID_NS , 'assoc_type' , 'new-assoc-type' )
1609- msg .setArg (OPENID_NS , 'session_type' , None )
1610-
1611- self .consumer .return_messages = [msg ]
1612- self .assertEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1613-
1614- self .failUnlessLogMatches ('Server error when requesting an association' )
1615-
1616- def testNotAllowed (self ):
1617- allowed_types = [
1618- ('assoc_bogus' , 'session_bogus' ),
1619- ]
1620-
1621- negotiator = association .SessionNegotiator (allowed_types )
1622- self .consumer .negotiator = negotiator
1623-
1624- msg = Message (self .endpoint .preferredNamespace ())
1625- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1626- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1627- msg .setArg (OPENID_NS , 'assoc_type' , 'not-allowed' )
1628- msg .setArg (OPENID_NS , 'session_type' , 'not-allowed' )
1629-
1630- self .consumer .return_messages = [msg ]
1631- self .assertEqual (self .consumer ._negotiateAssociation (self .endpoint ), None )
1632-
1633- self .failUnlessLogMatches ('Server error when requesting an association' )
1634-
1635- def testUnsupportedWithRetry (self ):
1636- msg = Message (self .endpoint .preferredNamespace ())
1637- msg .setArg (OPENID_NS , 'error' , 'Unsupported type' )
1638- msg .setArg (OPENID_NS , 'error_code' , 'unsupported-type' )
1639- msg .setArg (OPENID_NS , 'assoc_type' , 'HMAC-SHA1' )
1640- msg .setArg (OPENID_NS , 'session_type' , 'DH-SHA1' )
1641-
1642- assoc = association .Association (
1643- 'handle' , 'secret' , 'issued' , 10000 , 'HMAC-SHA1' )
1644-
1645- self .consumer .return_messages = [msg , assoc ]
1646- self .assertTrue (self .consumer ._negotiateAssociation (self .endpoint ) is None )
1647-
1648- self .failUnlessLogMatches ('Server error when requesting an association' )
1649-
1650- def testValid (self ):
1651- assoc = association .Association (
1652- 'handle' , 'secret' , 'issued' , 10000 , 'HMAC-SHA1' )
1653-
1654- self .consumer .return_messages = [assoc ]
1655- self .assertTrue (self .consumer ._negotiateAssociation (self .endpoint ) is assoc )
1656- self .failUnlessLogEmpty ()
1657-
16581468if __name__ == '__main__' :
16591469 unittest .main ()
0 commit comments