Merge "releasetools: Fix the use of StringIO." am: 6b466c8f56 am: 706eb3c566

am: cc5d077015

Change-Id: I44bce08e0e59b9c3a25dc6296a752562f94071ed
This commit is contained in:
Tao Bao 2019-07-25 10:28:24 -07:00 committed by android-build-merger
commit cd7978a4ad
2 changed files with 20 additions and 7 deletions

View File

@ -111,6 +111,7 @@ import base64
import copy
import errno
import gzip
import io
import itertools
import logging
import os
@ -746,12 +747,7 @@ def WriteOtacerts(output_zip, filename, keys):
filename: The archive name in the output zip.
keys: A list of public keys to use during OTA package verification.
"""
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
temp_file = StringIO()
temp_file = io.BytesIO()
certs_zip = zipfile.ZipFile(temp_file, "w")
for k in keys:
common.ZipWrite(certs_zip, k)

View File

@ -15,6 +15,7 @@
#
import base64
import io
import os.path
import zipfile
@ -22,7 +23,7 @@ import common
import test_utils
from sign_target_files_apks import (
CheckApkAndApexKeysAvailable, EditTags, GetApkFileInfo, ReadApexKeysInfo,
ReplaceCerts, ReplaceVerityKeyId, RewriteProps)
ReplaceCerts, ReplaceVerityKeyId, RewriteProps, WriteOtacerts)
class SignTargetFilesApksTest(test_utils.ReleaseToolsTestCase):
@ -236,6 +237,22 @@ name="apex.apexd_test_different_app.apex" public_key="system/apex/apexd/apexd_te
}
self.assertEqual(output_xml, ReplaceCerts(input_xml))
def test_WriteOtacerts(self):
certs = [
os.path.join(self.testdata_dir, 'platform.x509.pem'),
os.path.join(self.testdata_dir, 'media.x509.pem'),
os.path.join(self.testdata_dir, 'testkey.x509.pem'),
]
entry_name = 'SYSTEM/etc/security/otacerts.zip'
output_file = common.MakeTempFile(suffix='.zip')
with zipfile.ZipFile(output_file, 'w') as output_zip:
WriteOtacerts(output_zip, entry_name, certs)
with zipfile.ZipFile(output_file) as input_zip:
self.assertIn(entry_name, input_zip.namelist())
otacerts_file = io.BytesIO(input_zip.read(entry_name))
with zipfile.ZipFile(otacerts_file) as otacerts_zip:
self.assertEqual(3, len(otacerts_zip.namelist()))
def test_CheckApkAndApexKeysAvailable(self):
input_file = common.MakeTempFile(suffix='.zip')
with zipfile.ZipFile(input_file, 'w') as input_zip: