def runCustomTest(self): if self.expected is DiscoveryFailure: self.failUnlessRaises(DiscoveryFailure, discover, self.input_url) else: result = discover(self.input_url) self.failUnlessEqual(self.input_url, result.request_uri) msg = 'Identity URL mismatch: actual = %r, expected = %r' % ( result.normalized_uri, self.expected.normalized_uri) self.failUnlessEqual( self.expected.normalized_uri, result.normalized_uri, msg) msg = 'Content mismatch: actual = %r, expected = %r' % ( result.response_text, self.expected.response_text) self.failUnlessEqual( self.expected.response_text, result.response_text, msg) expected_keys = self.expected.__dict__.keys() expected_keys.sort() actual_keys = result.__dict__.keys() actual_keys.sort() self.failUnlessEqual(actual_keys, expected_keys) for k, exp_v in self.expected.__dict__.items(): act_v = result.__dict__.get(k) assert act_v == exp_v, (k, exp_v, act_v)
def runCustomTest(self): if self.expected is DiscoveryFailure: self.failUnlessRaises(DiscoveryFailure, discover, self.input_url) else: result = discover(self.input_url) self.failUnlessEqual(self.input_url, result.request_uri) msg = "Identity URL mismatch: actual = %r, expected = %r" % ( result.normalized_uri, self.expected.normalized_uri, ) self.failUnlessEqual(self.expected.normalized_uri, result.normalized_uri, msg) msg = "Content mismatch: actual = %r, expected = %r" % (result.response_text, self.expected.response_text) self.failUnlessEqual(self.expected.response_text, result.response_text, msg) expected_keys = dir(self.expected) expected_keys.sort() actual_keys = dir(result) actual_keys.sort() self.failUnlessEqual(actual_keys, expected_keys) for k in dir(self.expected): if k.startswith("__") and k.endswith("__"): continue exp_v = getattr(self.expected, k) if isinstance(exp_v, types.MethodType): continue act_v = getattr(result, k) assert act_v == exp_v, (k, exp_v, act_v)
def getServiceEndpoints(input_url, flt=None): """Perform the Yadis protocol on the input URL and return an iterable of resulting endpoint objects. @param flt: A filter object or something that is convertable to a filter object (using mkFilter) that will be used to generate endpoint objects. This defaults to generating BasicEndpoint objects. @param input_url: The URL on which to perform the Yadis protocol @return: The normalized identity URL and an iterable of endpoint objects generated by the filter function. @rtype: (six.text_type, [endpoint]) @raises DiscoveryFailure: when Yadis fails to obtain an XRDS document. """ result = discover(input_url) try: endpoints = applyFilter(result.normalized_uri, result.response_text, flt) except XRDSError as err: raise DiscoveryFailure(six.text_type(err), None) return (result.normalized_uri, endpoints)
def runCustomTest(self): if self.expected is DiscoveryFailure: self.assertRaises(DiscoveryFailure, discover, self.input_url) else: result = discover(self.input_url) self.assertEqual(self.input_url, result.request_uri) msg = 'Identity URL mismatch: actual = %r, expected = %r' % ( result.normalized_uri, self.expected.normalized_uri) self.assertEqual(self.expected.normalized_uri, result.normalized_uri, msg) msg = 'Content mismatch: actual = %r, expected = %r' % ( result.response_text, self.expected.response_text) self.assertEqual(self.expected.response_text, result.response_text, msg) expected_keys = dir(self.expected) expected_keys.sort() actual_keys = dir(result) actual_keys.sort() self.assertEqual(actual_keys, expected_keys) for k in dir(self.expected): if k.startswith('__') and k.endswith('__'): continue exp_v = getattr(self.expected, k) if isinstance(exp_v, types.MethodType): continue act_v = getattr(result, k) assert act_v == exp_v, (k, exp_v, act_v)
def test(self): for success, input_name, id_name, result_name in discoverdata.testlist: input_url, expected = discoverdata.generateResult( self.base_url, input_name, id_name, result_name, success) if expected is DiscoveryFailure: self.assertRaises(DiscoveryFailure, discover, input_url) else: result = discover(input_url) self.assertEqual(result.request_uri, input_url) msg = 'Identity URL mismatch: actual = %r, expected = %r' % ( result.normalized_uri, expected.normalized_uri) self.assertEqual(result.normalized_uri, expected.normalized_uri, msg) msg = 'Content mismatch: actual = %r, expected = %r' % ( result.response_text, expected.response_text) self.assertEqual(result.response_text, expected.response_text, msg) expected_keys = sorted(dir(expected)) actual_keys = sorted(dir(result)) self.assertEqual(actual_keys, expected_keys) for k in dir(expected): if k.startswith('__') and k.endswith('__'): continue exp_v = getattr(expected, k) if isinstance(exp_v, types.MethodType): continue act_v = getattr(result, k) assert act_v == exp_v, (k, exp_v, act_v)
def getServiceEndpoints(input_url, flt=None): """Perform the Yadis protocol on the input URL and return an iterable of resulting endpoint objects. @param flt: A filter object or something that is convertable to a filter object (using mkFilter) that will be used to generate endpoint objects. This defaults to generating BasicEndpoint objects. @param input_url: The URL on which to perform the Yadis protocol @return: The normalized identity URL and an iterable of endpoint objects generated by the filter function. @rtype: (str, [endpoint]) @raises DiscoveryFailure: when Yadis fails to obtain an XRDS document. """ result = discover(input_url) try: endpoints = applyFilter(result.normalized_uri, result.response_text, flt) except XRDSError as err: raise DiscoveryFailure(str(err), None) return (result.normalized_uri, endpoints)
def doLookup(openid, cargs): fail = 'notfound' try: discoverresult = discover.discover(openid, cargs) except: print "ConnectionError: failed to lookup %s" % (openid) raise sys.exit(-1) root = etree.XML(discoverresult.response_text) gotcha = 0 s_url = 'https://esg-idx.demonet.local/esgf-idp/saml/soap/secure/attributeService.htm' try: s = ats.AttributeService(s_url, QUERY_ISSUER) except: print fail raise sys.exit(-1) try: r = s.send_request(openid, [ 'CORDEX_Commercial', 'CORDEX_Research', 'CMIP5 Research', 'CMIP5 Commercial', 'ext_pub' ], cafile='esgf-ca-bundle.crt') #r=s.send_request(openid,['CORDEX_Commercial','CORDEX_Research','CMIP5 Research','CMIP5 Commercial','ext_pub']) except: print fail raise sys.exit(-1) res = r.get_attributes() if len(res) == 0: print "Not a member" sys.exit(-1) print res
def getServices(profile_url): """ Returns a dictionary of services provided by the XRDS file that is discovered at the URL that was passed in. """ dis = discover.discover(profile_url) # identi.ca doesn't implement XRDS correctly http://xrds-simple.net/core/1.0/ # This is a hack until laconi.ca fixes http://laconi.ca/trac/ticket/696 # Either that or the pydataportability needs to accept both $xrd* and $XRD* response = StringIO.StringIO(dis.response_text.replace("$xrd*", "$XRD*")) xrds_services = {} if dis.isXRDS(): xrds = XRDSParser(response) for service in xrds.services: xrds_services[service.type] = service if len(xrds_services) < 1: # TODO Error XRDS contained no services return {} if not xrdsContainsServices(xrds_services, [OAUTH_REQUEST, OAUTH_AUTHORIZE, OAUTH_ACCESS]): # TODO Error Not all the OAuth services were present in the XRDS return {} if not xrdsContainsServices(xrds_services, [OMB_POST_NOTICE, OMB_UPDATE_PROFILE]): # TDOD Error Not all the OMB services were present in the XRDS return {} return xrds_services else: # TODO Not and XRDS return {}
def getServiceEndpoints(input_url, flt=None): """Perform the Yadis protocol on the input URL and return an iterable of resulting endpoint objects. @param flt: A filter object or something that is convertable to a filter object (using mkFilter) that will be used to generate endpoint objects. This defaults to generating BasicEndpoint objects. @param input_url: The URL on which to perform the Yadis protocol @return: The normalized identity URL and an iterable of endpoint objects generated by the filter function. @rtype: (str, [endpoint]) """ result = discover(input_url) endpoints = applyFilter(result.normalized_uri, result.response_text, flt) return (result.normalized_uri, endpoints)
def doLookup(openid, cargs): fail = 'notfound' try: discoverresult = discover.discover(openid, cargs) except: print "ConnectionError: failed to lookup %s" % (openid) return root = etree.XML(discoverresult.response_text) gotcha = 0 s_url = None for element in root.iter("*"): if gotcha == 1: s_url = element.text break if element.text == 'urn:esg:security:attribute-service': gotcha = 1 continue if s_url == None: print fail raise sys.exit(-1) try: s = ats.AttributeService(s_url, QUERY_ISSUER) except: print fail raise sys.exit(-1) try: r = s.send_request(openid, [ 'urn:esg:first:name', 'urn:esg:last:name', 'urn:esg:email:address' ]) except: print fail raise sys.exit(-1) res = r.get_attributes() fn = res['urn:esg:first:name'] ln = res['urn:esg:last:name'] emailid = res['urn:esg:email:address'] print "%s: %s %s (%s)" % (openid, fn, ln, emailid)
def doLookup(openid,cargs): fail='notfound' try: discoverresult=discover.discover(openid,cargs) except: print "ConnectionError: failed to lookup %s"%(openid) return root=etree.XML(discoverresult.response_text) gotcha=0 s_url=None for element in root.iter("*"): if gotcha == 1: s_url=element.text break if element.text == 'urn:esg:security:attribute-service': gotcha=1 continue if s_url == None: print fail raise sys.exit(-1) try: s=ats.AttributeService(s_url,QUERY_ISSUER) except: print fail raise sys.exit(-1) try: r=s.send_request(openid,['urn:esg:first:name','urn:esg:last:name','urn:esg:email:address']) except: print fail raise sys.exit(-1) res=r.get_attributes() fn=res['urn:esg:first:name'] ln=res['urn:esg:last:name'] emailid=res['urn:esg:email:address'] print "%s: %s %s (%s)"%(openid,fn,ln,emailid)