Merge "releasetools: Fix the use of StringIO."
This commit is contained in:
commit
6b466c8f56
|
@ -111,6 +111,7 @@ import base64
|
||||||
import copy
|
import copy
|
||||||
import errno
|
import errno
|
||||||
import gzip
|
import gzip
|
||||||
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -746,12 +747,7 @@ def WriteOtacerts(output_zip, filename, keys):
|
||||||
filename: The archive name in the output zip.
|
filename: The archive name in the output zip.
|
||||||
keys: A list of public keys to use during OTA package verification.
|
keys: A list of public keys to use during OTA package verification.
|
||||||
"""
|
"""
|
||||||
|
temp_file = io.BytesIO()
|
||||||
try:
|
|
||||||
from StringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from io import StringIO
|
|
||||||
temp_file = StringIO()
|
|
||||||
certs_zip = zipfile.ZipFile(temp_file, "w")
|
certs_zip = zipfile.ZipFile(temp_file, "w")
|
||||||
for k in keys:
|
for k in keys:
|
||||||
common.ZipWrite(certs_zip, k)
|
common.ZipWrite(certs_zip, k)
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import io
|
||||||
import os.path
|
import os.path
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ import common
|
||||||
import test_utils
|
import test_utils
|
||||||
from sign_target_files_apks import (
|
from sign_target_files_apks import (
|
||||||
CheckApkAndApexKeysAvailable, EditTags, GetApkFileInfo, ReadApexKeysInfo,
|
CheckApkAndApexKeysAvailable, EditTags, GetApkFileInfo, ReadApexKeysInfo,
|
||||||
ReplaceCerts, ReplaceVerityKeyId, RewriteProps)
|
ReplaceCerts, ReplaceVerityKeyId, RewriteProps, WriteOtacerts)
|
||||||
|
|
||||||
|
|
||||||
class SignTargetFilesApksTest(test_utils.ReleaseToolsTestCase):
|
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))
|
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):
|
def test_CheckApkAndApexKeysAvailable(self):
|
||||||
input_file = common.MakeTempFile(suffix='.zip')
|
input_file = common.MakeTempFile(suffix='.zip')
|
||||||
with zipfile.ZipFile(input_file, 'w') as input_zip:
|
with zipfile.ZipFile(input_file, 'w') as input_zip:
|
||||||
|
|
Loading…
Reference in New Issue