<s> import base64 <EOL> from functionaltests . cli . base import CmdLineTestCase <EOL> from functionaltests . cli . v1 . behaviors . secret_behaviors import SecretBehaviors <EOL> from functionaltests . common import keys <EOL> from functionaltests import utils <EOL> from testtools import testcase <EOL> @ utils . parameterized_test_case <EOL> class SecretTestCase ( CmdLineTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SecretTestCase , self ) . setUp ( ) <EOL> self . secret_behaviors = SecretBehaviors ( ) <EOL> self . expected_payload = "<STR_LIT>" <EOL> self . payload_content_type = "<STR_LIT>" <EOL> def tearDown ( self ) : <EOL> super ( SecretTestCase , self ) . tearDown ( ) <EOL> self . secret_behaviors . delete_all_created_secrets ( ) <EOL> @ utils . parameterized_dataset ( { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> keys . get_private_key_pem ( ) ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> keys . get_public_key_pem ( ) ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> keys . get_certificate_pem ( ) ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , <EOL> None , <EOL> None , <EOL> ( b'<STR_LIT>' ) ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , <EOL> None , <EOL> None , <EOL> keys . get_passphrase_txt ( ) ] , <EOL> } ) <EOL> @ testcase . attr ( '<STR_LIT>' ) <EOL> def test_secret_store_with_secret_type ( self , secret_type , algorithm , <EOL> bit_length , secret ) : <EOL> payload = base64 . b64encode ( secret ) <EOL> secret_argv = [ '<STR_LIT>' , secret_type ] <EOL> if algorithm : <EOL> secret_argv . extend ( [ '<STR_LIT>' , algorithm ] ) <EOL> if bit_length : <EOL> secret_argv . extend ( [ '<STR_LIT>' , bit_length ] ) <EOL> secret_href = self . secret_behaviors . store_secret ( payload , secret_argv ) <EOL> self . assertIsNotNone ( secret_href ) <EOL> secret = self . secret_behaviors . get_secret ( secret_href ) <EOL> self . assertEqual ( secret_href , secret [ '<STR_LIT>' ] ) <EOL> @ testcase . attr ( '<STR_LIT>' ) <EOL> def test_secret_store ( self ) : <EOL> secret_href = self . secret_behaviors . store_secret ( ) <EOL> self . assertIsNotNone ( secret_href ) <EOL> secret = self . secret_behaviors . get_secret ( secret_href ) <EOL> self . assertEqual ( secret_href , secret [ '<STR_LIT>' ] ) <EOL> @ testcase . attr ( '<STR_LIT>' ) <EOL> def test_secret_update ( self ) : <EOL> secret_href = self . secret_behaviors . store_secret ( <EOL> payload = None ) <EOL> payload = '<STR_LIT>' <EOL> self . assertIsNotNone ( secret_href ) <EOL> self . secret_behaviors . update_secret ( secret_href , <EOL> payload ) <EOL> payload_update = self . secret_behaviors . get_secret_payload ( secret_href ) <EOL> self . assertEqual ( payload , payload_update ) <EOL> @ testcase . attr ( '<STR_LIT>' ) <EOL> def test_secret_list ( self ) : <EOL> secrets_to_create = <NUM_LIT:10> <EOL> for _ in range ( secrets_to_create ) : <EOL> self . secret_behaviors . store_secret ( ) <EOL> secret_list = self . secret_behaviors . list_secrets ( ) <EOL> self . assertGreaterEqual ( len ( secret_list ) , secrets_to_create ) <EOL> @ testcase . attr ( '<STR_LIT>' ) <EOL> def test_secret_delete ( self ) : <EOL> secret_href = self . secret_behaviors . store_secret ( ) <EOL> self . secret_behaviors . delete_secret ( secret_href ) <EOL> secret = self . secret_behaviors . get_secret ( secret_href ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( secret ) ) <EOL> @ testcase . attr ( '<STR_LIT>' ) <EOL> def test_secret_get ( self ) : <EOL> secret_href = self . secret_behaviors . store_secret ( ) <EOL> secret = self . secret_behaviors . get_secret ( secret_href ) <EOL> self . assertIsNotNone ( secret ) <EOL> @ testcase . attr ( '<STR_LIT>' ) <EOL> def test_secret_get_payload ( self ) : <EOL> secret_href = self . secret_behaviors . store_secret ( <EOL> payload = self . expected_payload ) <EOL> payload = self . secret_behaviors . get_secret_payload ( secret_href ) <EOL> self . assertEqual ( payload , self . expected_payload ) <EOL> @ testcase . attr ( '<STR_LIT>' ) <EOL> def test_secret_get_raw_payload ( self ) : <EOL> secret_href = self . secret_behaviors . store_secret ( <EOL> payload = self . expected_payload ) <EOL> payload = self . secret_behaviors . get_secret_payload ( secret_href , <EOL> raw = True ) <EOL> self . assertEqual ( payload , self . expected_payload ) </s>
