<s> from genty import genty , genty_dataset <EOL> import hashlib <EOL> from test . framework . base_unit_test_case import BaseUnitTestCase <EOL> from app . util . secret import Secret <EOL> @ genty <EOL> class TestSecret ( BaseUnitTestCase ) : <EOL> def test_get_secret_should_return_set_secret ( self ) : <EOL> secret = '<STR_LIT>' <EOL> Secret . set ( secret ) <EOL> self . assertEqual ( secret , Secret . get ( ) ) <EOL> @ genty_dataset ( None , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_set_insecure_secrets_fails ( self , insecure_secret ) : <EOL> self . assertRaises ( RuntimeError , Secret . set , insecure_secret ) <EOL> def test_header_generates_128_character_digest ( self ) : <EOL> secret = hashlib . sha512 ( ) . hexdigest ( ) <EOL> header = Secret . header ( '<STR_LIT:message>' , secret ) <EOL> self . assertEqual ( len ( header [ Secret . DIGEST_HEADER_KEY ] ) , <NUM_LIT> ) <EOL> def test_matching_digests_should_return_true ( self ) : <EOL> secret = '<STR_LIT>' <EOL> message = '<STR_LIT>' <EOL> Secret . set ( secret ) <EOL> digest_received = Secret . _get_hex_digest ( message , secret ) <EOL> self . assertTrue ( Secret . digest_is_valid ( digest_received , message ) ) <EOL> def test_non_matching_digests_should_return_false ( self ) : <EOL> secret = '<STR_LIT>' <EOL> message = '<STR_LIT>' <EOL> Secret . set ( secret ) <EOL> digest_received = Secret . _get_hex_digest ( '<STR_LIT>' , secret ) <EOL> self . assertFalse ( Secret . digest_is_valid ( digest_received , message ) ) <EOL> def test_unspecified_digest_should_return_false ( self ) : <EOL> secret = '<STR_LIT>' <EOL> message = '<STR_LIT>' <EOL> Secret . set ( secret ) <EOL> digest_received = None <EOL> self . assertFalse ( Secret . digest_is_valid ( digest_received , message ) ) </s>
