o Ʋa"@sdZddlZddlZddlZddlmZeeureZ neZ ddl m Z m Z ddl mZmZmZmZGdddejZGdd d ejZGd d d eZGd d d eZdS)z'Tests for the credential store classes.N) b64decode) fake_keyringInMemoryKeyring) AccessToken CredentialsKeyringCredentialStoreUnencryptedFileCredentialStorec@s eZdZdZddZddZdS)TestAccessTokenz Tests for the AccessToken class.cCs6td}|d|j|d|j||jdS)Nz;oauth_token_secret=secret%3Dpassword&oauth_token=lock%26keylock&keysecret=password)r from_string assertEqualkeysecret assertIsNonecontextself access_tokenrJ/usr/lib/python3/dist-packages/launchpadlib/tests/test_credential_store.pytest_from_string/s z TestAccessToken.test_from_stringcCs8td}|d|j|d|j|d|jdS)NzNoauth_token_secret=secret%3Dpassword&oauth_token=lock%26key&lp.context=firefoxr r firefox)rr r rrrrrrrtest_from_string_with_context7s z-TestAccessToken.test_from_string_with_contextN)__name__ __module__ __qualname____doc__rrrrrrr ,s r c@eZdZddZdS)CredentialStoreTestCasecCstddt|ddS)z(Helper method to make a fake credential.zapp namezconsumer_secret:42zaccess_secret:168)consumer_secretr)rr)r consumer_keyrrrmake_credentialBs z'CredentialStoreTestCase.make_credentialN)rrrr"rrrrrA rc@s8eZdZdZddZddZddZdd Zd d Zd S) "TestUnencryptedFileCredentialStorez3Tests for the UnencryptedFileCredentialStore class.cCst\}|_t|j|_dSN)tempfilemkstempfilenamerstore)rignorerrrsetUpNsz(TestUnencryptedFileCredentialStore.setUpcCs"tj|jrt|jdSdSr%)ospathexistsr(removerrrrtearDownRsz+TestUnencryptedFileCredentialStore.tearDowncCs<|d}|j|d|jd}||jj|jjdSN consumer key unique keyr"r)saveloadr consumerrr credential credential2rrrtest_save_and_loadVs  z5TestUnencryptedFileCredentialStore.test_save_and_loadcCs<|d}|j|d|jd}||jj|jjdS)Nr3zsome keyzsome other keyr5r9rrrtest_unique_id_doesnt_matter]s  z?TestUnencryptedFileCredentialStore.test_unique_id_doesnt_mattercCsT|d}|d}|j|d|j|d|jd}||jj|jjdS)Nr3 consumer key2z unique key 1z unique key 2r5r credential1r;loadedrrr&test_file_only_contains_one_credentiales   zITestUnencryptedFileCredentialStore.test_file_only_contains_one_credentialN) rrrrr+r1r<r=rBrrrrr$Ks r$c@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)TestKeyringCredentialStorez+Tests for the KeyringCredentialStore class.cCst|_t|_dSr%)rkeyringrr)r0rrrr+us z TestKeyringCredentialStore.setUpcCsht|j%|d}|j|d|jd}||jj|jjWddS1s-wYdSr2 rrDr"r)r6r7r r8rr9rrrr<ys   "z-TestKeyringCredentialStore.test_save_and_loadcCst|jF|d}|j|d|d}|j|d|jd}||||jj |jj |jd}||jj |jj WddS1sNwYdS)N consumer key1zkey 1r>zkey 2) rrDr"r)r6r7 assertTruer r8r)rr@r;loaded1loaded2rrrtest_lookup_by_unique_keys      "z4TestKeyringCredentialStore.test_lookup_by_unique_keycCst|j1|d}|j|d|d}|j|d|jd}||jj|jjWddS1s9wYdS)NrFz the only keyr>rEr?rrr/test_reused_unique_id_overwrites_old_credentials    "zJTestKeyringCredentialStore.test_reused_unique_id_overwrites_old_credentialcCsBt|j||jdWddS1swYdS)Nz no such key)rrDrr)r7r0rrrtest_bad_unique_id_returns_nones "z:TestKeyringCredentialStore.test_bad_unique_id_returns_nonecsGfdddt|_t|j9|d}|||j|d|jd}||||j j |j j ||j j |j j WddS1sOwYdS)NceZdZfddZZS)zWTestKeyringCredentialStore.test_keyring_returns_unicode..UnicodeInMemoryKeyringcs*t|||}t|tr|d}|S)Nzutf-8)super get_password isinstance unicode_typeencode)rserviceusernamepassword)UnicodeInMemoryKeyring __class__rrrOs   zdTestKeyringCredentialStore.test_keyring_returns_unicode..UnicodeInMemoryKeyring.get_passwordrrrrO __classcell__rrVrWrrVrVr3r4) rrDrr"rGr)r6r7r r8rrr9rrZrtest_keyring_returns_unicodes      "z7TestKeyringCredentialStore.test_keyring_returns_unicodecsGfdddt|_t|j/|d}|j|d|jd}||jj |jj ||jj |jj WddS1sEwYdS)NcrM)zXTestKeyringCredentialStore.test_nonencoded_key_handled..UnencodedInMemoryKeyringcs"t|||}t|ddS)N)rNrOr)rrSrTpw)UnencodedInMemoryKeyringrWrrrOs zeTestKeyringCredentialStore.test_nonencoded_key_handled..UnencodedInMemoryKeyring.get_passwordrXrr`r[rr`r\r`r3r4) rrDrr"r)r6r7r r8rrr9rrartest_nonencoded_key_handleds    "z6TestKeyringCredentialStore.test_nonencoded_key_handledcCsvGdddt}||_t|j |d}|j|d|jd}||WddS1s4wYdS)Nc@r)zWTestKeyringCredentialStore.test_corrupted_key_handled..CorruptedInMemoryKeyringcSsdS)Nbadr)rrSrTrrrrOszdTestKeyringCredentialStore.test_corrupted_key_handled..CorruptedInMemoryKeyring.get_passwordN)rrrrOrrrrCorruptedInMemoryKeyringr#rdr3r4)rrDrr"r)r6r7r)rrdr:r;rrrtest_corrupted_key_handleds    "z5TestKeyringCredentialStore.test_corrupted_key_handledN) rrrrr+r<rJrKrLr]rbrerrrrrCrs rC)rr,r&unittestbase64rbytesstrunicoderQlaunchpadlib.testing.helpersrrlaunchpadlib.credentialsrrrrTestCaser rr$rCrrrrs  '