
    )JfjO                        d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlZd d	lmZ d d
lmZ d dlmZmZ d dlmZ d dlmZ d dlmZ d dlm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z&  G d de&          Z'd Z(d Z)d Z*d Z+dS )    N)get_user_model)AnonymousUser)MessageMiddleware)SessionMiddleware)RequestFactory)override_settings)reverse)app_settings)EmailAddress)
user_emailuser_username)context)	providers)complete_social_login)SocialAccount	SocialAppSocialLogin)signup)TestCasec            	           e Zd Z fdZ eddej        j                  d             Z eddddd          d             Z	 eddd	dd          d
             Z
 eddd	dd          d             Z edg ddddd          d             Zd Z edddd	dd	          d             Z edddd	dd	          d             Z ed	dddd	dd	          d             Z edddddd	          d             Z xZS )SignupTestsc                    t                                                       t          j                                        D ]}|j        dk    rt          j                            |j        |j        ddd          }t          j
        j        r9ddlm} |j                                        }|j                            |           d S )Nopenid_connectapp123id123dummy)providername	client_idkeysecretr   )Site)supersetUpr   registryget_class_listidr   objectscreateallauthr
   SITES_ENABLEDdjango.contrib.sites.modelsr"   get_currentsitesadd)selfr   appr"   site	__class__s        j/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/allauth/socialaccount/tests/test_signup.pyr$   zSignupTests.setUp   s    !*99;; 	$ 	$H{...#**![$ +  C #1 $<<<<<<|//11	d###	$ 	$    TN)SOCIALACCOUNT_AUTO_SIGNUPACCOUNT_SIGNUP_FORM_CLASSACCOUNT_EMAIL_VERIFICATIONc                    t                      }|                    d          }t                      |_        t	          d                               |           t          d                               |           t                      } |            }t          |t          j
        d           t          |t          j        d           t          dd          }t          ||	          }t          j        |          5  t!          ||           d d d            n# 1 swxY w Y    |j        j        di t          j
        di}|                     t          j                            ||j        
                                                     |                     t,          j                            |t/          |                                                               d S )Nz/accounts/login/callback/c                     d S N requests    r4   <lambda>z8SignupTests.test_email_address_created.<locals>.<lambda>2       $ r5   c                     d S r;   r<   r=   s    r4   r?   z8SignupTests.test_email_address_created.<locals>.<lambda>3   r@   r5   testtest@example.comopenidr   r   uiduseraccount)rH   rF   )rH   emailr<   )r   getr   rH   r   process_requestr   r   setattraccount_settingsUSER_MODEL_USERNAME_FIELDUSER_MODEL_EMAIL_FIELDr   r   r   request_contextr   r(   
assertTruefilterrF   existsr   r   r0   factoryr>   UserrH   rI   sociallogins          r4   test_email_address_createdz&SignupTests.test_email_address_created)   s    !""++9::$..//??HHH..//??HHHtvv&@&III&=?QRRRu===!tW===$W-- 	8 	8!';777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8  t|WW#3#Mv"VWW!((d(DDKKMM	
 	
 	
 	 ''TD9I9I'JJQQSS	
 	
 	
 	
 	
   DD"%D"rJ   )ACCOUNT_EMAIL_REQUIREDACCOUNT_UNIQUE_EMAILACCOUNT_USERNAME_REQUIREDACCOUNT_AUTHENTICATION_METHODr6   c                    |                      dd          \  }}|                     |d         t          d                     d|_        ddd|_        t          j        |          5  t          |          }d	d	d	           n# 1 swxY w Y   |                     |d         d
            t                      j	        j
        di t          j        di}|                     t          |          d           d	S )z%Test clash on both username and emailrB   rC   locationsocialaccount_signupPOSTotherother@example.comusernamerJ   N/accounts/profile/r<   )_email_address_clashassertEqualr	   methodrb   r   rQ   r   r   r(   rK   rN   rP   r   r0   r>   resprH   s       r4   *test_email_address_clash_username_requiredz6SignupTests.test_email_address_clash_username_requiredG   sA    11&:LMMj)73I+J+JKKK  $+6IJJ$W-- 	# 	#'??D	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#j)+?@@@+~'+ 
 
68KL
 
 	t,,g66666s   (BBBFc                    |                      dd          \  }}|                     |d         t          d                     d|_        ddi|_        t          j        |          5  t          |          }ddd           n# 1 swxY w Y   |                     |d         d	            t                      j	        j
        d
i t          j        di}|                     t          |          d           dS )z)Test clash while username is not requiredrB   rC   r`   ra   rb   rJ   rd   Nrg   r<   )rh   ri   r	   rj   rb   r   rQ   r   r   r(   rK   rN   rP   assertNotEqualr   rk   s       r4   .test_email_address_clash_username_not_requiredz:SignupTests.test_email_address_clash_username_not_required^   s>    11&:LMMj)73I+J+JKKK  !45$W-- 	# 	#'??D	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#j)+?@@@+~'+ 
 
68KL
 
 	M$//88888s   'BB
Bc                 
   |                      dd          \  }}|                     |d         d            t                      j        j        di t
          j        di}|                     t          |          d           d S )NrB   rd   r`   rg   r<   )	rh   ri   r   r(   rK   rN   rP   ro   r   rk   s       r4   -test_email_address_clash_username_auto_signupz9SignupTests.test_email_address_clash_username_auto_signupu   s     11&:MNNj)+?@@@+~'+ 
 
68KL
 
 	M$//88888r5   )rf   	username1	username2)r[   ACCOUNT_USERNAME_BLACKLISTr\   r]   r^   r6   c                    t                      }|                    d          }t                      |_        t	          d                               |           t          d                               |           t                      } |            }t          |t          j
        d           t          |t          j        d           t          dd          }t          ||	          }t          j        |          5  t!          ||           d d d            n# 1 swxY w Y   |                     |j        j        t          j                   d S )
N!/accounts/twitter/login/callback/c                     d S r;   r<   r=   s    r4   r?   zASignupTests.test_populate_username_in_blacklist.<locals>.<lambda>   r@   r5   c                     d S r;   r<   r=   s    r4   r?   zASignupTests.test_populate_username_in_blacklist.<locals>.<lambda>   r@   r5   rf   zusername@example.comtwitterr   rE   rG   )r   rK   r   rH   r   rL   r   r   rM   rN   rO   rP   r   r   r   rQ   r   assertNotInrf   USERNAME_BLACKLISTrU   s          r4   #test_populate_username_in_blacklistz/SignupTests.test_populate_username_in_blacklist   sy    !""++ABB$..//??HHH..//??HHHtvv&@*MMM3"	
 	
 	
  >>>!tW===$W-- 	8 	8!';777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	.0@0STTTTTrZ   c                    t                      } |            }t          |d           d}t          ||           |                                 t          j                            ||dd           t          dd          } |            }t          ||           t          ||           t          ||          }t                      }	|	
                    d	          }
t                      |
_        t          d
                               |
           t          d                               |
           t!          j        |
          5  t%          |
|          }d d d            n# 1 swxY w Y   |
|fS )NrB   rC   TrH   rJ   verifiedprimaryrz   r   rE   rG   rw   c                     d S r;   r<   r=   s    r4   r?   z2SignupTests._email_address_clash.<locals>.<lambda>   r@   r5   c                     d S r;   r<   r=   s    r4   r?   z2SignupTests._email_address_clash.<locals>.<lambda>   r@   r5   )r   r   r   saver   r(   r)   r   r   r   rK   r   rH   r   rL   r   r   rQ   r   )r0   rf   rJ   rW   exi_userexi_user_emailrI   rH   rX   rV   r>   rl   s               r4   rh   z SignupTests._email_address_clash   s   466h'''+8^,,,##$ 	$ 	
 	
 	

  >>>tvvdH%%%4!tW=== !""++ABB$..//??HHH..//??HHH$W-- 	? 	?(+>>D	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?}s   E++E/2E/	mandatory)r[   r8   r\   r]   r^   r6   c           	         | j         j        }t                      }t           |d          t	          d          t          ddd          g          }|                                |d<   |                                 | j                             t          d	                    }|j
        d
         }|                     |d                                         d           | j                             t          d	          ddi          }|                     |dd           |j                                        d         }|                     t#          |          d           |                     t
          j                            |ddd                                                     |                     t
          j                            |ddd                                                     dS )z
        Test scenario for when the user changes email at social signup. Current
        behavior is that both the unverified and verified email are added, and
        that the user is allowed to pass because he did provide a verified one.
        zverified@example.comrJ   googler   TrJ   r   r   rH   rI   email_addressessocialaccount_socialloginra   formrJ   unverified@example.orgdatarg   F)fetch_redirect_responser   r   Nclientsessionr   r   r   r   	serializer   rK   r	   r   ri   valuepostassertRedirectsr(   allr   rR   rS   rT   r0   r   rW   rX   rl   r   rH   s          r4   $test_verified_email_change_at_signupz0SignupTests.test_verified_email_change_at_signup   s    +%!2333!8444#9DRVWWW
 
 
 0;/D/D/F/F+,{w'=>>??|F#g,,..0FGGG{*++34   
 
 	T#7QVWWW|!!!$D))+ABBB '',	 (  
 fhh	
 	
 	
 	 ''.	 (  
 fhh	
 	
 	
 	
 	
r5   c           	      
   | j         j        }t                      }t           |d          t	          d          t          ddd          g          }|                                |d	<   |                                 | j                             t          d
                    }|j
        d         }|                     |d                                         d           | j                             t          d
          ddi          }|                     |t          d                     |j                                        d         }|                     t#          |          d           |                     t
          j                            |ddd                                                     |                     t
          j                            |ddd                                                     dS )z
        Test scenario for when the user changes email at social signup, while
        his provider did not provide a verified email. In that case, email
        verification will kick in. Here, both email addresses are added as
        well.
        zunverified@example.comr   r   r   FTr   r   r   ra   r   rJ   r   r   account_email_verification_sentr   r   Nr   r   s          r4   &test_unverified_email_change_at_signupz2SignupTests.test_unverified_email_change_at_signup   s    +%!4555!84442"   

 

 

 0;/D/D/F/F+,{w'=>>??|F#g,,..0HIII{*++34   
 

 	T7+L#M#MNNN|!!!$D))+CDDD ''.	 (  
 fhh	
 	
 	
 	 ''.	 (  
 fhh	
 	
 	
 	
 	
r5   )ACCOUNT_PREVENT_ENUMERATIONr[   r8   r\   r]   r^   r6   c           	      6   | j         j        }t                      }d}|j                            |          }t
          j                            ||d           t           |d          t          d          t          ddd          g          }|                                |d	<   |	                                 | j         
                    t          d
                    }|j        d         }|                     |d                                         |           | j                             t          d
          d|i          }t           j        dk    r$|                     |j        d         dd           d S |                     |ddd           d S )Nzme@example.comr   T)rJ   rH   r   r   r   r   r   r   ra   r   rJ   r   )      zzAn account already exists with this email address. Please sign in to that account first, then connect your Google account.)r   r   r   r(   r)   r   r   r   r   r   rK   r	   r   ri   r   r   djangoVERSIONassertFormError)r0   r   rW   rJ   rH   rX   rl   r   s           r4   #test_unique_email_validation_signupz/SignupTests.test_unique_email_validation_signup/  s    +% |"""//##%dT#JJJ!,---!8444#3dDQQQ
 
 
 0;/D/D/F/F+,{w'=>>??|F#g,,..666{(> ? ?wPUFVWW>V##  V$(       (	    r5   c                    | j         j        }t                      }t           |d          t	          d                    }|                                |d<   |                                 | j                             t          d                    }|j	        d         }| 
                    |d	                                         d           | j                             t          d          d
dd          }| 
                    |j        d           | 
                    |j                                        d           | 
                    t          j                                        d           | j                             t          d                    }|                     |t          d                     dS )a  
        Test scenario for when the user signs up with a social account
        and uses email address in that social account. But upon seeing the
        verification screen, they realize that email address is somehow
        unusable for them, and so backs up and enters a different email
        address (and is forced to choose a new username) while providing
        the same social account token which is owned by their first attempt.
        zme1@example.comr   facebookr   rG   r   ra   r   rJ   me1re   r   i.  r   account_loginN)r   r   r   r   r   r   r   rK   r	   r   ri   r   r   status_coder(   countr   )r0   r   rW   rX   rl   r   s         r4   #test_social_account_taken_at_signupz/SignupTests.test_social_account_taken_at_signup]  s   " +%!-...!:666
 
 
 0;/D/D/F/F+,{w'=>>??|F#g,,..0ABBB{*++#.?@@   
 
 	)3///++--q111.4466:::{w'=>>??T7?#;#;<<<<<r5   )__name__
__module____qualname__r$   r   rN   EmailVerificationMethodNONErY   rm   rp   rr   r}   rh   r   r   r   r   __classcell__)r3   s   @r4   r   r      s       $ $ $ $ $$ "&"&#3#K#P  

 
 

2 #!"&&-"&  7 7 7  #!"'&-"&  9 9 9  #!"'&-"&  9 9 9 ##I#I#I!"&&-"&  U U U.  : ##.!"'&-"'  *
 *
 *
X ##.!"'&-"'  0
 0
 0
d $)##.!"'&-"'  # # #J ##.!"&&-"'  = = = = = = =r5   r   c                 
   d|_         d|_        d|_        d|_        d|_        d|_         |d          }|                    d          }i |_        t                      |_	        t          ||          }|d         t          d          k    sJ |j        }|                                |d	<   |                                 |                    t          d          dd
i          }|d         t          d          k    sJ dS )zgTests that when the email address is missing from the sociallogin email
    verification kicks in.
    TFrJ   r   
with_email/r`   ra   r   zother@example.orgr   N)r[   r\   r]   r^   r8   r6   rK   r   r   rH   r   r	   r   r   r   )	dbsettingssociallogin_factoryr   rfrX   r>   rl   r   s	            r4   4test_email_address_required_missing_from_socialloginr     s    '+H#$(H!).H&-4H**5H')-H&%%777KffSkkGGO ??GL +66D
w'=>>>>>>nG+6+@+@+B+BG'(LLNNN;;w566BU8VWWD
w'HIIIIIIIIr5   c                 N   d|_         d|_        d|_        d|_        d|_        d|_         |            } |d          }|                    d          }	i |	_        t                      |	_	        t          |	|          }
|
d         t          d          k    sJ |j        }|                                |d	<   |                                 |                    t          d          d|j        i          }
|d
         j        dk    sJ |
d         t          d          k    sJ dS )yTests that when an already existing email is given at the social signup
    form, enumeration preventation kicks in.
    TFrJ   r   r   r   r`   ra   r   r   $[example.com] Account Already Existsr   N)r[   r\   r]   r^   r8   r6   rK   r   r   rH   r   r	   r   r   r   rJ   subjectr   r   user_factoryr   r   r   
mailoutboxrH   rX   r>   rl   r   s               r4   1test_email_address_conflict_at_social_signup_formr     s-    '+H#$(H!).H&-4H**5H')-H&<>>D%%777KffSkkGGO ??GL +66D
w'=>>>>>>nG+6+@+@+B+BG'(LLNNN;;w566$*8MNNDa= $JJJJJ
w'HIIIIIIIIr5   c                 l   d|_         d|_        d|_        d|_        d|_        d|_         |            } ||j        d          }|                    d          }	i |	_        t                      |	_
        t          |	|          }
|
d         t          d          k    sJ |d	         j        d
k    sJ dS )ztTests that when an already existing email is received from the provider,
    enumeration preventation kicks in.
    TFrJ   r   )rJ   r   r   r`   r   r   r   N)r[   r\   r]   r^   r8   r6   rJ   rK   r   r   rH   r   r	   r   )r   r   r   r   r   r   r   rH   rX   r>   rl   s              r4   .test_email_address_conflict_during_auto_signupr     s     '+H#$(H!).H&-4H**5H')-H&<>>D%%DJ4HHHKffSkkGGO ??GL +66D
w'HIIIIIIa= $JJJJJJJr5   c                    d|_         d|_        d|_        d|_        d|_        d|_        d|_         |d          } ||j        d          }|                    d          }	i |	_	        t                      |	_        t          |	|          }
|
d         t          d	          k    sJ |j	        }|                                |d
<   |                                 |                    t          d	          ddi          }
|d         j        dk    sJ |
d         |j        k    sJ t&          j                            |j                                                  dk    sJ dS )r   TFrJ   optional)email_verified)rJ   r   r   r`   ra   r   zother@email.orgr   z/[example.com] Please Confirm Your Email Addressr   r   N)r[   r\   r]   r^   r8   r6   "SOCIALACCOUNT_EMAIL_AUTHENTICATIONrJ   rK   r   r   rH   r   r	   r   r   r   r   LOGIN_REDIRECT_URLr   r(   rS   r   r   s               r4   5test_email_address_conflict_removes_conflicting_emailr     sl    '+H#$(H!).H&-4H**4H')-H&27H/<u---D%%DJuMMMKffSkkGGO ??GL +66D
w'=>>>>>>nG+6+@+@+B+BG'(LLNNN;;w566BS8TUUDa= $UUUUU
x:::::&&TZ&88>>@@AEEEEEEr5   ),r   django.contrib.authr   django.contrib.auth.modelsr   "django.contrib.messages.middlewarer   "django.contrib.sessions.middlewarer   django.test.clientr   django.test.utilsr   django.urlsr	   allauth.app_settingsr*   allauth.accountr
   rN   allauth.account.modelsr   allauth.account.utilsr   r   allauth.corer   allauth.socialaccountr   allauth.socialaccount.helpersr   allauth.socialaccount.modelsr   r   r   allauth.socialaccount.viewsr   allauth.testsr   r   r   r   r   r   r<   r5   r4   <module>r      s    . . . . . . 4 4 4 4 4 4 @ @ @ @ @ @ @ @ @ @ @ @ - - - - - - / / / / / /           < < < < < < / / / / / / ; ; ; ; ; ; ; ;             + + + + + + ? ? ? ? ? ? N N N N N N N N N N . . . . . . " " " " " "l= l= l= l= l=( l= l= l=^J J J8J J JBK K K2 F  F  F  F  Fr5   