Files
build/tools/releasetools/test_sign_target_files_apks.py
Tao Bao a7054eede1 releasetools: Fix the tag replacement for ro.build.vendor.fingerprint.
For devices using derived fingerprint (i.e. /system/build.prop doesn't
contain ro.build.fingerprint, but has ro.build.thumbprint instead), the
current code (in android.os.Build) doesn't have a matching logic to do
the same for ro.vendor.build.fingerprint. This means we will see
ro.build.thumbprint in /system/build.prop, while there's no matching
ro.vendor.build.thumbprint in /vendor/build.prop.

From signing script point of view, it should just apply the tag
replacement (e.g. test-keys -> release-keys) for whatever it sees when
signing a target_files.zip.

This CL also adds unit tests for EditTags() and RewriteProps().

Fixes: 27950003
Test: Use 'sign_target_files_apks.py' to sign a target that uses derived
      fingerprint and vendor partition. Check VENDOR/build.prop.
Test: python -m unittest test_sign_target_files_apks
Change-Id: I09019da970840cd82f54b68a32b4e94984bc1d8d
2017-12-08 15:19:47 -08:00

68 lines
2.6 KiB
Python

#
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import print_function
import unittest
from sign_target_files_apks import EditTags, RewriteProps
class SignTargetFilesApksTest(unittest.TestCase):
def test_EditTags(self):
self.assertEqual(EditTags('dev-keys'), ('release-keys'))
self.assertEqual(EditTags('test-keys'), ('release-keys'))
# Multiple tags.
self.assertEqual(EditTags('abc,dev-keys,xyz'), ('abc,release-keys,xyz'))
# Tags are sorted.
self.assertEqual(EditTags('xyz,abc,dev-keys,xyz'), ('abc,release-keys,xyz'))
def test_RewriteProps(self):
props = (
('', '\n'),
('ro.build.fingerprint=foo/bar/dev-keys',
'ro.build.fingerprint=foo/bar/release-keys\n'),
('ro.build.thumbprint=foo/bar/dev-keys',
'ro.build.thumbprint=foo/bar/release-keys\n'),
('ro.vendor.build.fingerprint=foo/bar/dev-keys',
'ro.vendor.build.fingerprint=foo/bar/release-keys\n'),
('ro.vendor.build.thumbprint=foo/bar/dev-keys',
'ro.vendor.build.thumbprint=foo/bar/release-keys\n'),
('# comment line 1', '# comment line 1\n'),
('ro.bootimage.build.fingerprint=foo/bar/dev-keys',
'ro.bootimage.build.fingerprint=foo/bar/release-keys\n'),
('ro.build.description='
'sailfish-user 8.0.0 OPR6.170623.012 4283428 dev-keys',
'ro.build.description='
'sailfish-user 8.0.0 OPR6.170623.012 4283428 release-keys\n'),
('ro.build.tags=dev-keys', 'ro.build.tags=release-keys\n'),
('# comment line 2', '# comment line 2\n'),
('ro.build.display.id=OPR6.170623.012 dev-keys',
'ro.build.display.id=OPR6.170623.012\n'),
('# comment line 3', '# comment line 3\n'),
)
# Assert the case for each individual line.
for input, output in props:
self.assertEqual(RewriteProps(input), output)
# Concatenate all the input lines.
self.assertEqual(RewriteProps('\n'.join([prop[0] for prop in props])),
''.join([prop[1] for prop in props]))