
    Ʋa"                         d Z ddlZddlZddlZddlmZ eeu reZ	neZ	ddl
mZmZ ddlmZmZmZmZ  G d dej$                        Z G d d	ej$                        Z G d
 de      Z G d de      Zy)z'Tests for the credential store classes.    N)	b64decode)fake_keyringInMemoryKeyring)AccessTokenCredentialsKeyringCredentialStoreUnencryptedFileCredentialStorec                       e Zd ZdZd Zd Zy)TestAccessTokenz Tests for the AccessToken class.c                     t        j                  d      }| j                  d|j                         | j                  d|j                         | j                  |j                         y )Nz;oauth_token_secret=secret%3Dpassword&oauth_token=lock%26keylock&keysecret=password)r   from_stringassertEqualkeysecretassertIsNonecontextselfaccess_tokens     J/usr/lib/python3/dist-packages/launchpadlib/tests/test_credential_store.pytest_from_stringz TestAccessToken.test_from_string/   sX    "..I
 	\%5%56*L,?,?@,../    c                     t        j                  d      }| j                  d|j                         | j                  d|j                         | j                  d|j
                         y )NzNoauth_token_secret=secret%3Dpassword&oauth_token=lock%26key&lp.context=firefoxr   r   firefox)r   r   r   r   r   r   r   s     r   test_from_string_with_contextz-TestAccessToken.test_from_string_with_context7   s\    "..!
 	\%5%56*L,?,?@L$8$89r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   ,   s    *0:r   r   c                       e Zd Zd Zy)CredentialStoreTestCasec                 2    t        ddt        |d            S )z(Helper method to make a fake credential.zapp namezconsumer_secret:42zaccess_secret:168)consumer_secretr   )r   r   )r   consumer_keys     r   make_credentialz'CredentialStoreTestCase.make_credentialB   s     0$\3FG
 	
r   N)r   r   r    r(   r"   r   r   r$   r$   A   s    
r   r$   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)"TestUnencryptedFileCredentialStorez3Tests for the UnencryptedFileCredentialStore class.c                 p    t        j                         \  }| _        t        | j                        | _        y N)tempfilemkstempfilenamer	   store)r   ignores     r   setUpz(TestUnencryptedFileCredentialStore.setUpN   s'     ( 0 0 23DMMB
r   c                     t         j                  j                  | j                        r t        j                  | j                         y y r,   )ospathexistsr/   remover   s    r   tearDownz+TestUnencryptedFileCredentialStore.tearDownR   s+    77>>$--(IIdmm$ )r   c                    | j                  d      }| j                  j                  |d       | j                  j                  d      }| j	                  |j
                  j                  |j
                  j                         y Nconsumer key
unique keyr(   r0   saveloadr   consumerr   r   
credentialcredential2s      r   test_save_and_loadz5TestUnencryptedFileCredentialStore.test_save_and_loadV   s^    )).9



L1jjool3,,00+2F2F2J2JKr   c                    | j                  d      }| j                  j                  |d       | j                  j                  d      }| j	                  |j
                  j                  |j
                  j                         y )Nr<   zsome keyzsome other keyr>   rB   s      r   test_unique_id_doesnt_matterz?TestUnencryptedFileCredentialStore.test_unique_id_doesnt_matter]   sa     )).9



J/jjoo&67,,00+2F2F2J2JKr   c                 b   | j                  d      }| j                  d      }| j                  j                  |d       | j                  j                  |d       | j                  j                  d      }| j	                  |j
                  j                  |j
                  j                         y )Nr<   consumer key2zunique key 1zunique key 2r>   r   credential1rD   loadeds       r   &test_file_only_contains_one_credentialzITestUnencryptedFileCredentialStore.test_file_only_contains_one_credentiale   s    
 **>:**?;

^4

^40,,k.B.B.F.FGr   N)	r   r   r    r!   r2   r9   rE   rG   rM   r"   r   r   r*   r*   K   s"    =C%LL
Hr   r*   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestKeyringCredentialStorez+Tests for the KeyringCredentialStore class.c                 @    t               | _        t               | _        y r,   )r   keyringr   r0   r8   s    r   r2   z TestKeyringCredentialStore.setUpu   s    &(+-
r   c                 \   t        | j                        5  | j                  d      }| j                  j	                  |d       | j                  j                  d      }| j                  |j                  j                  |j                  j                         d d d        y # 1 sw Y   y xY wr;   	r   rQ   r(   r0   r?   r@   r   rA   r   rB   s      r   rE   z-TestKeyringCredentialStore.test_save_and_loady   s    $,,' 	P--n=JJJOOJ5**//,7KZ0044k6J6J6N6NO		P 	P 	Ps   BB""B+c                    t        | j                        5  | j                  d      }| j                  j	                  |d       | j                  d      }| j                  j	                  |d       | j                  j                  d      }| j                  |       | j                  |j                  j                  |j                  j                         | j                  j                  d      }| j                  |j                  j                  |j                  j                         d d d        y # 1 sw Y   y xY w)Nconsumer key1zkey 1rI   zkey 2)
r   rQ   r(   r0   r?   r@   
assertTruer   rA   r   )r   rK   rD   loaded1loaded2s        r   test_lookup_by_unique_keyz4TestKeyringCredentialStore.test_lookup_by_unique_key   s     $,,' 	M..?KJJOOK1..?KJJOOK1jjoog.GOOG$[1155w7G7G7K7KLjjoog.G[1155w7G7G7K7KL	M 	M 	Ms   DD55D>c                    t        | j                        5  | j                  d      }| j                  j	                  |d       | j                  d      }| j                  j	                  |d       | j                  j                  d      }| j                  |j                  j                  |j                  j                         d d d        y # 1 sw Y   y xY w)NrU   zthe only keyrI   rS   rJ   s       r   /test_reused_unique_id_overwrites_old_credentialzJTestKeyringCredentialStore.test_reused_unique_id_overwrites_old_credential   s     $,,' 	L..?KJJOOK8..?KJJOOK8ZZ__^4F[1155v7J7JK	L 	L 	Ls   B0CCc                     t        | j                        5  | j                  | j                  j	                  d             d d d        y # 1 sw Y   y xY w)Nzno such key)r   rQ   r   r0   r@   r8   s    r   test_bad_unique_id_returns_nonez:TestKeyringCredentialStore.test_bad_unique_id_returns_none   s@     $,,' 	>djjoom<=	> 	> 	>s   +A

Ac                 P    G fddt                       | _        t        | j                        5  | j                  d      }| j	                  |       | j
                  j                  |d       | j
                  j                  d      }| j	                  |       | j                  |j                  j                  |j                  j                         | j                  |j                  j                  |j                  j                         d d d        y # 1 sw Y   y xY w)Nc                   "     e Zd Z fdZ xZS )WTestKeyringCredentialStore.test_keyring_returns_unicode.<locals>.UnicodeInMemoryKeyringc                 j    t         |   ||      }t        |t              r|j	                  d      }|S )Nzutf-8)superget_password
isinstanceunicode_typeencode)r   serviceusernamepasswordUnicodeInMemoryKeyring	__class__s       r   rc   zdTestKeyringCredentialStore.test_keyring_returns_unicode.<locals>.UnicodeInMemoryKeyring.get_password   s9     !7KX h5'w7Hr   r   r   r    rc   __classcell__)rk   rj   s   @r   rj   r`      s       r   rj   r<   r=   )r   rQ   r   r(   rV   r0   r?   r@   r   rA   r   r   )r   rC   rD   rj   s      @r   test_keyring_returns_unicodez7TestKeyringCredentialStore.test_keyring_returns_unicode   s    	 _ 	  ./$,,' 
	--n=JOOJ'JJOOJ5**//,7KOOK(Z0044k6J6J6N6NO##**K,@,@,G,G
	 
	 
	s   CDD%c                     G fddt                       | _        t        | j                        5  | j                  d      }| j                  j                  |d       | j                  j                  d      }| j                  |j                  j                  |j                  j                         | j                  |j                  j                  |j                  j                         d d d        y # 1 sw Y   y xY w)Nc                   "     e Zd Z fdZ xZS )XTestKeyringCredentialStore.test_nonencoded_key_handled.<locals>.UnencodedInMemoryKeyringc                 @    t         |   ||      }t        |dd        S )N   )rb   rc   r   )r   rg   rh   pwUnencodedInMemoryKeyringrk   s       r   rc   zeTestKeyringCredentialStore.test_nonencoded_key_handled.<locals>.UnencodedInMemoryKeyring.get_password   s-    3TGX !AB((r   rl   )rk   ru   s   @r   ru   rq      s    ) )r   ru   r<   r=   )r   rQ   r   r(   r0   r?   r@   r   rA   r   r   )r   rC   rD   ru   s      @r   test_nonencoded_key_handledz6TestKeyringCredentialStore.test_nonencoded_key_handled   s    	) 	) 01$,,' 	--n=JJJOOJ5**//,7KZ0044k6J6J6N6NO##**K,@,@,G,G	 	 	s   B=C::Dc                 @    G d dt               } |       | _        t        | j                        5  | j                  d      }| j                  j                  |d       | j                  j                  d      }| j                  |       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zd Zy)WTestKeyringCredentialStore.test_corrupted_key_handled.<locals>.CorruptedInMemoryKeyringc                      y)Nbadr"   )r   rg   rh   s      r   rc   zdTestKeyringCredentialStore.test_corrupted_key_handled.<locals>.CorruptedInMemoryKeyring.get_password   s    r   N)r   r   r    rc   r"   r   r   CorruptedInMemoryKeyringry      s    r   r|   r<   r=   )r   rQ   r   r(   r0   r?   r@   r   )r   r|   rC   rD   s       r   test_corrupted_key_handledz5TestKeyringCredentialStore.test_corrupted_key_handled   s}    	 	 01$,,' 	+--n=JJJOOJ5**//,7Kk*		+ 	+ 	+s   ABBN)r   r   r    r!   r2   rE   rY   r[   r]   rn   rv   r}   r"   r   r   rO   rO   r   s0    5.PM"L>4(+r   rO   )r!   r4   r-   unittestbase64r   bytesstrunicodere   launchpadlib.testing.helpersr   r   launchpadlib.credentialsr   r   r   r	   TestCaser   r$   r*   rO   r"   r   r   <module>r      sy   " . 	   C<LL
 :h'' :*
h// 
$H)@ $HNn+!8 n+r   