@@ -1356,6 +1356,35 @@ def test_aes_client():
13561356 if os .path .exists ('test_multi_upload_local' ):
13571357 os .remove ('test_multi_upload_local' )
13581358
1359+ client_for_rsa .delete_object (test_bucket , 'test_multi_upload' )
1360+
1361+ def test_rsa_client ():
1362+ """测试rsa加密客户端的上传下载操作"""
1363+ content = '123456' * 1024 + '1'
1364+ client_for_rsa .delete_object (test_bucket , 'test_for_rsa' )
1365+ client_for_rsa .put_object (test_bucket , content , 'test_for_rsa' )
1366+ # 测试整个文件的md5
1367+ response = client_for_rsa .get_object (test_bucket , 'test_for_rsa' )
1368+ response ['Body' ].get_stream_to_file ('test_for_rsa_local' )
1369+ local_file_md5 = None
1370+ content_md5 = None
1371+ with open ('test_for_rsa_local' , 'rb' ) as f :
1372+ local_file_md5 = get_raw_md5 (f .read ())
1373+ content_md5 = get_raw_md5 (content .encode ("utf-8" ))
1374+ assert local_file_md5 and content_md5 and local_file_md5 == content_md5
1375+ if os .path .exists ('test_for_rsa_local' ):
1376+ os .remove ('test_for_rsa_local' )
1377+
1378+ # 测试读取部分数据的md5
1379+ response = client_for_rsa .get_object (test_bucket , 'test_for_rsa' , Range = 'bytes=5-3000' )
1380+ response ['Body' ].get_stream_to_file ('test_for_rsa_local' )
1381+ with open ('test_for_rsa_local' , 'rb' ) as f :
1382+ local_file_md5 = get_raw_md5 (f .read ())
1383+ content_md5 = get_raw_md5 (content [5 :3001 ].encode ("utf-8" ))
1384+ assert local_file_md5 and content_md5 and local_file_md5 == content_md5
1385+ if os .path .exists ('test_for_rsa_local' ):
1386+ os .remove ('test_for_rsa_local' )
1387+
13591388 client_for_rsa .delete_object (test_bucket , 'test_for_rsa' )
13601389
13611390 content = '1' * 1024 * 1024
@@ -1375,6 +1404,7 @@ def test_aes_client():
13751404 assert local_file_md5 and content_md5 and local_file_md5 == content_md5
13761405 if os .path .exists ('test_multi_upload_local' ):
13771406 os .remove ('test_multi_upload_local' )
1407+
13781408 client_for_rsa .delete_object (test_bucket , 'test_multi_upload' )
13791409
13801410
0 commit comments