<s> import re <EOL> import urllib <EOL> import urlparse <EOL> def externalauthURL ( name ) : <EOL> return "<STR_LIT>" % ( name , urllib . urlencode ( { "<STR_LIT:target>" : "<STR_LIT:/>" } ) ) <EOL> with_class = testing . expect . with_class <EOL> def isprefix ( expected , actual ) : <EOL> return actual . startswith ( expected ) <EOL> def issuffix ( expected , actual ) : <EOL> return actual . endswith ( expected ) <EOL> def expect_system_mail ( subject ) : <EOL> system_mail = mailbox . pop ( testing . mailbox . ToRecipient ( "<STR_LIT>" ) ) <EOL> testing . expect . check ( subject , system_mail . headers [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT:value>" ] ) <EOL> def start_externalauth ( name ) : <EOL> response = frontend . page ( <EOL> externalauthURL ( name ) , <EOL> disable_redirects = True , <EOL> expected_http_status = <NUM_LIT> ) <EOL> redirect_url = response . headers [ "<STR_LIT>" ] <EOL> testing . expect . check ( "<STR_LIT>" , <EOL> redirect_url , <EOL> equal = isprefix ) <EOL> parsed_url = urlparse . urlparse ( redirect_url ) <EOL> parsed_query = urlparse . parse_qs ( parsed_url . query ) <EOL> state = parsed_query . get ( "<STR_LIT:state>" , [ "<STR_LIT>" ] ) [ <NUM_LIT:0> ] <EOL> if state == "<STR_LIT>" : <EOL> testing . expect . check ( "<STR_LIT>" , <EOL> "<STR_LIT>" % parsed_url . query ) <EOL> return state <EOL> def finish_externalauth ( name , state ) : <EOL> response = frontend . page ( <EOL> "<STR_LIT>" + name , <EOL> params = { "<STR_LIT:state>" : state , <EOL> "<STR_LIT:code>" : "<STR_LIT>" } , <EOL> disable_redirects = True , <EOL> expected_http_status = <NUM_LIT> ) <EOL> return response . headers [ "<STR_LIT>" ] <EOL> NAMES = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def oauth_links ( document ) : <EOL> providers = document . findAll ( "<STR_LIT>" , attrs = with_class ( "<STR_LIT>" ) ) <EOL> names = set ( NAMES ) <EOL> expected_text = "<STR_LIT>" <EOL> for provider in providers : <EOL> testing . expect . check ( expected_text , provider . contents [ <NUM_LIT:0> ] ) <EOL> expected_text = "<STR_LIT>" <EOL> link = provider . find ( "<STR_LIT:a>" ) <EOL> words = link . string . split ( ) <EOL> testing . expect . check ( <NUM_LIT:2> , len ( words ) ) <EOL> testing . expect . check ( "<STR_LIT>" , words [ - <NUM_LIT:1> ] , equal = issuffix ) <EOL> name = words [ <NUM_LIT:0> ] . lower ( ) <EOL> if name in names : <EOL> testing . expect . check ( "<STR_LIT:/>" + externalauthURL ( name ) , link [ "<STR_LIT>" ] ) <EOL> names . remove ( name ) <EOL> else : <EOL> testing . logger . error ( "<STR_LIT>" % name ) <EOL> if names : <EOL> testing . expect . check ( "<STR_LIT>" % names , <EOL> "<STR_LIT>" ) <EOL> frontend . page ( <EOL> "<STR_LIT>" , <EOL> expect = { "<STR_LIT>" : oauth_links } ) <EOL> state = start_externalauth ( "<STR_LIT>" ) <EOL> frontend . page ( <EOL> "<STR_LIT>" , <EOL> params = { "<STR_LIT:state>" : "<STR_LIT>" , <EOL> "<STR_LIT:code>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT:message>" : testing . expect . message ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> body_equal = re . search ) } ) <EOL> expect_system_mail ( <EOL> "<STR_LIT>" ) <EOL> frontend . page ( <EOL> "<STR_LIT>" , <EOL> params = { "<STR_LIT:state>" : state , <EOL> "<STR_LIT:code>" : "<STR_LIT>" } , <EOL> expect = { "<STR_LIT:message>" : testing . expect . message ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> body_equal = re . search ) } ) <EOL> expect_system_mail ( "<STR_LIT>" ) <EOL> redirect_url = finish_externalauth ( "<STR_LIT>" , state ) <EOL> message_check = testing . expect . message ( "<STR_LIT>" , None ) <EOL> frontend . page ( <EOL> redirect_url , <EOL> expect = { "<STR_LIT:message>" : message_check } ) <EOL> instance . criticctl ( [ "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> state = start_externalauth ( "<STR_LIT>" ) <EOL> redirect_url = finish_externalauth ( "<STR_LIT>" , state ) <EOL> testing . expect . check ( "<STR_LIT:/>" , redirect_url ) <EOL> with frontend . session ( "<STR_LIT>" ) : <EOL> document_title_check = testing . expect . document_title ( <EOL> "<STR_LIT>" ) <EOL> frontend . page ( <EOL> "<STR_LIT>" , <EOL> expect = { "<STR_LIT>" : document_title_check } ) <EOL> state = start_externalauth ( "<STR_LIT>" ) <EOL> redirect_url = finish_externalauth ( "<STR_LIT>" , state ) <EOL> testing . expect . check ( "<STR_LIT>" , <EOL> redirect_url , <EOL> equal = isprefix ) <EOL> parsed_url = urlparse . urlparse ( redirect_url ) <EOL> parsed_query = urlparse . parse_qs ( parsed_url . query ) <EOL> testing . expect . check ( [ "<STR_LIT>" ] , parsed_query . get ( "<STR_LIT>" ) ) <EOL> testing . expect . check ( [ "<STR_LIT>" ] , parsed_query . get ( "<STR_LIT>" ) ) <EOL> testing . expect . check ( <NUM_LIT:1> , len ( parsed_query . get ( "<STR_LIT>" ) ) ) <EOL> testing . expect . check ( [ "<STR_LIT:/>" ] , parsed_query . get ( "<STR_LIT:target>" ) ) <EOL> testing . expect . check ( [ "<STR_LIT>" ] , parsed_query . get ( "<STR_LIT:username>" ) ) <EOL> testing . expect . check ( [ "<STR_LIT>" ] , parsed_query . get ( "<STR_LIT:email>" ) ) <EOL> testing . expect . check ( [ "<STR_LIT>" ] , parsed_query . get ( "<STR_LIT>" ) ) <EOL> token = parsed_query . get ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> frontend . operation ( <EOL> "<STR_LIT>" , <EOL> data = { "<STR_LIT:username>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : token } } , <EOL> expect = { "<STR_LIT:message>" : "<STR_LIT>" } ) <EOL> frontend . operation ( <EOL> "<STR_LIT>" , <EOL> data = { "<STR_LIT:username>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } } , <EOL> expect = { "<STR_LIT:message>" : "<STR_LIT>" } ) <EOL> frontend . operation ( <EOL> "<STR_LIT>" , <EOL> data = { "<STR_LIT:username>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : token } } ) <EOL> instance . registeruser ( "<STR_LIT>" ) <EOL> with frontend . session ( "<STR_LIT>" ) : <EOL> def email_not_unverified ( document ) : <EOL> address = document . find ( attrs = with_class ( "<STR_LIT:address>" ) ) <EOL> if address . find ( attrs = with_class ( "<STR_LIT>" ) ) : <EOL> testing . expect . check ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> document_title_check = testing . expect . document_title ( <EOL> "<STR_LIT>" ) <EOL> frontend . page ( <EOL> "<STR_LIT>" , <EOL> expect = { "<STR_LIT>" : document_title_check , <EOL> "<STR_LIT>" : email_not_unverified } ) <EOL> expect_system_mail ( "<STR_LIT>" ) <EOL> state = start_externalauth ( "<STR_LIT>" ) <EOL> redirect_url = finish_externalauth ( "<STR_LIT>" , state ) <EOL> instance . registeruser ( "<STR_LIT>" ) <EOL> with frontend . session ( "<STR_LIT>" ) : <EOL> document_title_check = testing . expect . document_title ( <EOL> "<STR_LIT>" ) <EOL> frontend . page ( <EOL> "<STR_LIT>" , <EOL> expect = { "<STR_LIT>" : document_title_check , <EOL> "<STR_LIT>" : email_not_unverified } ) <EOL> expect_system_mail ( "<STR_LIT>" ) <EOL> state = start_externalauth ( "<STR_LIT>" ) <EOL> redirect_url = finish_externalauth ( "<STR_LIT>" , state ) <EOL> testing . expect . check ( "<STR_LIT>" , <EOL> redirect_url , <EOL> equal = isprefix ) <EOL> parsed_url = urlparse . urlparse ( redirect_url ) <EOL> parsed_query = urlparse . parse_qs ( parsed_url . query ) <EOL> token = parsed_query . get ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> frontend . operation ( <EOL> "<STR_LIT>" , <EOL> data = { "<STR_LIT:username>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : token } } ) <EOL> instance . registeruser ( "<STR_LIT>" ) <EOL> with frontend . session ( "<STR_LIT>" ) : <EOL> def email_unverified ( document ) : <EOL> address = document . find ( attrs = with_class ( "<STR_LIT:address>" ) ) <EOL> if not address . find ( attrs = with_class ( "<STR_LIT>" ) ) : <EOL> testing . expect . check ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> document_title_check = testing . expect . document_title ( <EOL> "<STR_LIT>" ) <EOL> frontend . page ( <EOL> "<STR_LIT>" , <EOL> expect = { "<STR_LIT>" : document_title_check , <EOL> "<STR_LIT>" : email_unverified } ) <EOL> expect_system_mail ( "<STR_LIT>" ) <EOL> subject = r"<STR_LIT>" <EOL> mailbox . pop ( accept = [ testing . mailbox . ToRecipient ( "<STR_LIT>" ) , <EOL> testing . mailbox . WithSubject ( subject ) ] ) </s>
