<s> from base64 import b64encode , b64decode <EOL> from unittest import TestCase <EOL> from onepassword . encryption_key import SaltyString , EncryptionKey <EOL> class SaltyStringTest ( TestCase ) : <EOL> def test_unsalted_data ( self ) : <EOL> unsalted = SaltyString ( b64encode ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( "<STR_LIT:\x00>" * <NUM_LIT:16> , unsalted . salt ) <EOL> self . assertEquals ( "<STR_LIT>" , unsalted . data ) <EOL> def test_salted_data ( self ) : <EOL> salted = SaltyString ( b64encode ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( "<STR_LIT>" , salted . salt ) <EOL> self . assertEquals ( "<STR_LIT>" , salted . data ) <EOL> class EncryptionKeyTest ( TestCase ) : <EOL> def test_identifier ( self ) : <EOL> key = EncryptionKey ( data = "<STR_LIT>" , identifier = "<STR_LIT>" ) <EOL> self . assertEquals ( "<STR_LIT>" , key . identifier ) <EOL> def test_level ( self ) : <EOL> key = EncryptionKey ( data = "<STR_LIT>" , level = "<STR_LIT>" ) <EOL> self . assertEquals ( "<STR_LIT>" , key . level ) <EOL> def test_iterations_with_string ( self ) : <EOL> key = EncryptionKey ( data = "<STR_LIT>" , iterations = "<STR_LIT>" ) <EOL> self . assertEquals ( <NUM_LIT> , key . iterations ) <EOL> def test_iterations_with_number ( self ) : <EOL> key = EncryptionKey ( data = "<STR_LIT>" , iterations = <NUM_LIT> ) <EOL> self . assertEquals ( <NUM_LIT> , key . iterations ) <EOL> def test_iterations_default ( self ) : <EOL> key = EncryptionKey ( data = "<STR_LIT>" ) <EOL> self . assertEquals ( <NUM_LIT:1000> , key . iterations ) <EOL> def test_iterations_minimum ( self ) : <EOL> key = EncryptionKey ( data = "<STR_LIT>" , iterations = <NUM_LIT> ) <EOL> self . assertEquals ( <NUM_LIT:1000> , key . iterations ) <EOL> def test_unlocking_with_correct_password ( self ) : <EOL> key = EncryptionKey ( ** self . example_data ) <EOL> unlock_result = key . unlock ( password = "<STR_LIT>" ) <EOL> self . assertTrue ( unlock_result ) <EOL> def test_unlocking_with_incorrect_password ( self ) : <EOL> key = EncryptionKey ( ** self . example_data ) <EOL> unlock_result = key . unlock ( password = "<STR_LIT>" ) <EOL> self . assertFalse ( unlock_result ) <EOL> @ property <EOL> def example_data ( self ) : <EOL> return { <EOL> u'<STR_LIT>' : u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:data>' : u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' , <EOL> u'<STR_LIT>' : <NUM_LIT> , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> } </s>
