def test_openid_login(self): openid_identifier = 'http://unittest.myopenid.com/' openid_password = '******' OPENID_LOGIN_URL = 'https://django-rpx-test.rpxnow.com/openid/start' #RPX wants to send user to POST to this token_url after login. But since #we can intercept the token value from the responses, we can craft our own #POST to the local app. Therefore, we can just set a dummy token_url. args = { 'token_url': 'http://example.com/', 'openid_identifier': openid_identifier, #These two are required by RPX: 'callback': 'RPXNOW._xdCallbacks[0]', 'callbackScheme': 'https', } OPENID_LOGIN_URL += '?' + urlencode(args) #print OPENID_LOGIN_URL #Visit the login url to be redirected to the OpenID provider's site #for login. In our case, we are using myopenid.com. twill.go(OPENID_LOGIN_URL) #If we are already logged in through myopenid, then RPX will redirect #through the myopenid site back to RPX. So we check that here: try: twill.url('https://www.myopenid.com/signin_password.+') #Enter our password and submit the form on the myopenid.com website. twill.formvalue(1, 'password', openid_password) twill.submit() except TwillAssertionError: twill.url('https://django-rpx-test.rpxnow.com/openid/finish.+') #Pull out the redirect url contents = twill.show() #The URL is part of javascript in <head>, but it's heavily escaped. We #remove all of the '\' characters. contents = contents.replace('\\', '') m = re.search(r'redirectUrl":"(.+?)"', contents) self.assertTrue(type(m.group(1)) is str) redirect_url = m.group(1) #Visiting the redirect url will result in a page with form with the #token in a hidden input field. If we wait too long, the redirect url #expires and we get a blank page. twill.go(redirect_url) twill.code(200) contents = twill.show() #Pull out the token value soup = BeautifulSoup(contents) token = soup.find('input', id='token') token = token['value'] #Verify that the token is a hash self.assertTrue(len(token) == 40) #(OR, we can replace the action URL in our form to point to local.) return token
def test_openid_login(self): openid_identifier = 'http://unittest.myopenid.com/' openid_password = '******' OPENID_LOGIN_URL = 'https://django-rpx-test.rpxnow.com/openid/start' #RPX wants to send user to POST to this token_url after login. But since #we can intercept the token value from the responses, we can craft our own #POST to the local app. Therefore, we can just set a dummy token_url. args = { 'token_url':'http://example.com/', 'openid_identifier': openid_identifier, #These two are required by RPX: 'callback': 'RPXNOW._xdCallbacks[0]', 'callbackScheme': 'https', } OPENID_LOGIN_URL += '?' + urlencode(args) #print OPENID_LOGIN_URL #Visit the login url to be redirected to the OpenID provider's site #for login. In our case, we are using myopenid.com. twill.go(OPENID_LOGIN_URL) #If we are already logged in through myopenid, then RPX will redirect #through the myopenid site back to RPX. So we check that here: try: twill.url('https://www.myopenid.com/signin_password.+') #Enter our password and submit the form on the myopenid.com website. twill.formvalue(1, 'password', openid_password) twill.submit() except TwillAssertionError: twill.url('https://django-rpx-test.rpxnow.com/openid/finish.+') #Pull out the redirect url contents = twill.show() #The URL is part of javascript in <head>, but it's heavily escaped. We #remove all of the '\' characters. contents = contents.replace('\\', '') m = re.search(r'redirectUrl":"(.+?)"', contents) self.assertTrue(type(m.group(1)) is str) redirect_url = m.group(1) #Visiting the redirect url will result in a page with form with the #token in a hidden input field. If we wait too long, the redirect url #expires and we get a blank page. twill.go(redirect_url) twill.code(200) contents = twill.show() #Pull out the token value soup = BeautifulSoup(contents) token = soup.find('input', id = 'token') token = token['value'] #Verify that the token is a hash self.assertTrue(len(token) == 40) #(OR, we can replace the action URL in our form to point to local.) return token
def test_load(self): make_ballot('ugsenior', **ugsenior) twill.go('/ballot/?%s' % self.webauth_querystring('ugsenior')) twill.code(200) twill.find('Thom and Stephanie') twill.find('Caddylack') twill.find('G-MRDA') twill.find('Peacock and Bakke') twill.find('The No-Rain Campaign') twill.find('Cardona and Wharton') twill.find('Sastry') twill.find('Siegel') twill.find('Jang') twill.find('Walzebuck') twill.find('Saeid')