@@ -1865,6 +1865,29 @@ def test_aes_client():
18651865
18661866 client_for_rsa .delete_object (test_bucket , 'test_multi_upload' )
18671867
1868+ def test_aes_client2 ():
1869+ """测试aes加密客户端的上传下载操作"""
1870+ aes_dir = os .path .expanduser ('~/.cos_local_aes' )
1871+ key_path = os .path .join (aes_dir , '.aes_key.pem' )
1872+ aes_provider = AESProvider (aes_key_path = key_path )
1873+ client_for_aes = CosEncryptionClient (conf , aes_provider )
1874+
1875+ content = '123456' * 1024 + '1'
1876+ client_for_aes .delete_object (test_bucket , 'test_for_aes' )
1877+ client_for_aes .put_object (test_bucket , content , 'test_for_aes' )
1878+
1879+ # 测试整个文件的md5
1880+ response = client_for_aes .get_object (test_bucket , 'test_for_aes' )
1881+ response ['Body' ].get_stream_to_file ('test_for_aes_local' )
1882+ local_file_md5 = None
1883+ content_md5 = None
1884+ with open ('test_for_aes_local' , 'rb' ) as f :
1885+ local_file_md5 = get_raw_md5 (f .read ())
1886+ content_md5 = get_raw_md5 (content .encode ("utf-8" ))
1887+ assert local_file_md5 and content_md5 and local_file_md5 == content_md5
1888+ if os .path .exists ('test_for_aes_local' ):
1889+ os .remove ('test_for_aes_local' )
1890+
18681891
18691892def test_rsa_client ():
18701893 """测试rsa加密客户端的上传下载操作"""
@@ -3412,7 +3435,7 @@ def test_update_object_meta():
34123435 assert response ['x-cos-meta-key2' ] == 'value2'
34133436
34143437def test_cos_comm_misc ():
3415- from qcloud_cos .cos_comm import format_dict_or_list , get_date , client_can_retry , format_path
3438+ from qcloud_cos .cos_comm import format_dict_or_list , get_date , get_raw_md5 , client_can_retry , format_path
34163439 data = [
34173440 {'aaa' : '111' },
34183441 {'bbb' : '222' },
@@ -3423,6 +3446,9 @@ def test_cos_comm_misc():
34233446 r = get_date (2022 , 5 , 30 )
34243447 assert r == '2022-05-30T00:00:00+08:00'
34253448
3449+ r = get_raw_md5 (b'12345' * 1024 )
3450+ assert r
3451+
34263452 with open ("tmp_test" , 'w' ) as f :
34273453 r = client_can_retry (0 , data = f )
34283454 assert r
@@ -3447,6 +3473,15 @@ def test_cosconfig_misc():
34473473 test_conf .set_ip_port ('10.0.0.1' , 80 )
34483474 test_conf .set_credential (SecretId = SECRET_ID , SecretKey = SECRET_KEY , Token = None )
34493475
3476+ def test_cos_exception_unknow ():
3477+ msg = '<Error></Error>'
3478+ e = CosServiceError ('GET' , msg , '400' )
3479+ assert e .get_error_code () == 'Unknown'
3480+ assert e .get_error_msg () == 'Unknown'
3481+ assert e .get_resource_location () == 'Unknown'
3482+ assert e .get_trace_id () == 'Unknown'
3483+ assert e .get_request_id () == 'Unknown'
3484+
34503485if __name__ == "__main__" :
34513486 setUp ()
34523487 """
0 commit comments