def test_decode_two_part_short_client_token_uses_adobe_base64_encoding(self): # The base64 encoding of this signature has a plus sign in it. signature = 'LbU}66%\\-4zt>R>_)\n2Q' encoded_signature = AuthdataUtility.adobe_base64_encode(signature) # We replace the plus sign with a colon. assert ':' in encoded_signature assert '+' not in encoded_signature # Make sure that decode_two_part_short_client_token properly # reverses that change when decoding the 'password'. class MockAuthdataUtility(AuthdataUtility): def _decode_short_client_token(self, token, supposed_signature): eq_(supposed_signature, signature) self.test_code_ran = True utility = MockAuthdataUtility( vendor_id = "The Vendor ID", library_uri = "http://your-library.org/", library_short_name = "you", secret = "Your library secret", ) utility.test_code_ran = False utility.decode_two_part_short_client_token( "username", encoded_signature ) # The code in _decode_short_client_token ran. Since there was no # test failure, it ran successfully. eq_(True, utility.test_code_ran)
def test_adobe_base64_encode_decode(self): """Test our special variant of base64 encoding designed to avoid triggering an Adobe bug. """ value = "!\tFN6~'Es52?X!#)Z*_S" encoded = AuthdataUtility.adobe_base64_encode(value) eq_('IQlGTjZ:J0VzNTI;WCEjKVoqX1M@', encoded) # This is like normal base64 encoding, but with a colon # replacing the plus character, a semicolon replacing the # slash, an at sign replacing the equal sign and the final # newline stripped. eq_( encoded.replace(":", "+").replace(";", "/").replace("@", "=") + "\n", base64.encodestring(value)) # We can reverse the encoding to get the original value. eq_(value, AuthdataUtility.adobe_base64_decode(encoded))