Merge "Fix the bug on APP_CERTIFICATE_LINEAGE rule as we forgot to modify the binary rule parser to support the new rule." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f084f35b7a
@@ -168,6 +168,7 @@ public class RuleBinaryParser implements RuleParser {
|
|||||||
switch (key) {
|
switch (key) {
|
||||||
case AtomicFormula.PACKAGE_NAME:
|
case AtomicFormula.PACKAGE_NAME:
|
||||||
case AtomicFormula.APP_CERTIFICATE:
|
case AtomicFormula.APP_CERTIFICATE:
|
||||||
|
case AtomicFormula.APP_CERTIFICATE_LINEAGE:
|
||||||
case AtomicFormula.INSTALLER_NAME:
|
case AtomicFormula.INSTALLER_NAME:
|
||||||
case AtomicFormula.INSTALLER_CERTIFICATE:
|
case AtomicFormula.INSTALLER_CERTIFICATE:
|
||||||
case AtomicFormula.STAMP_CERTIFICATE_HASH:
|
case AtomicFormula.STAMP_CERTIFICATE_HASH:
|
||||||
|
|||||||
@@ -71,9 +71,11 @@ public class RuleBinaryParserTest {
|
|||||||
|
|
||||||
private static final String PACKAGE_NAME = getBits(AtomicFormula.PACKAGE_NAME, KEY_BITS);
|
private static final String PACKAGE_NAME = getBits(AtomicFormula.PACKAGE_NAME, KEY_BITS);
|
||||||
private static final String APP_CERTIFICATE = getBits(AtomicFormula.APP_CERTIFICATE, KEY_BITS);
|
private static final String APP_CERTIFICATE = getBits(AtomicFormula.APP_CERTIFICATE, KEY_BITS);
|
||||||
|
private static final String APP_CERTIFICATE_LINEAGE =
|
||||||
|
getBits(AtomicFormula.APP_CERTIFICATE_LINEAGE, KEY_BITS);
|
||||||
private static final String VERSION_CODE = getBits(AtomicFormula.VERSION_CODE, KEY_BITS);
|
private static final String VERSION_CODE = getBits(AtomicFormula.VERSION_CODE, KEY_BITS);
|
||||||
private static final String PRE_INSTALLED = getBits(AtomicFormula.PRE_INSTALLED, KEY_BITS);
|
private static final String PRE_INSTALLED = getBits(AtomicFormula.PRE_INSTALLED, KEY_BITS);
|
||||||
private static final int INVALID_KEY_VALUE = 8;
|
private static final int INVALID_KEY_VALUE = 9;
|
||||||
private static final String INVALID_KEY = getBits(INVALID_KEY_VALUE, KEY_BITS);
|
private static final String INVALID_KEY = getBits(INVALID_KEY_VALUE, KEY_BITS);
|
||||||
|
|
||||||
private static final String EQ = getBits(AtomicFormula.EQ, OPERATOR_BITS);
|
private static final String EQ = getBits(AtomicFormula.EQ, OPERATOR_BITS);
|
||||||
@@ -336,6 +338,40 @@ public class RuleBinaryParserTest {
|
|||||||
assertThat(rules).isEqualTo(Collections.singletonList(expectedRule));
|
assertThat(rules).isEqualTo(Collections.singletonList(expectedRule));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBinaryString_validAtomicFormulaWithCertificateLineage() throws Exception {
|
||||||
|
String appCertificate = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
||||||
|
String ruleBits =
|
||||||
|
START_BIT
|
||||||
|
+ ATOMIC_FORMULA_START_BITS
|
||||||
|
+ APP_CERTIFICATE_LINEAGE
|
||||||
|
+ EQ
|
||||||
|
+ IS_HASHED
|
||||||
|
+ getBits(appCertificate.length(), VALUE_SIZE_BITS)
|
||||||
|
+ getValueBits(appCertificate)
|
||||||
|
+ DENY
|
||||||
|
+ END_BIT;
|
||||||
|
byte[] ruleBytes = getBytes(ruleBits);
|
||||||
|
ByteBuffer rule =
|
||||||
|
ByteBuffer.allocate(DEFAULT_FORMAT_VERSION_BYTES.length + ruleBytes.length);
|
||||||
|
rule.put(DEFAULT_FORMAT_VERSION_BYTES);
|
||||||
|
rule.put(ruleBytes);
|
||||||
|
|
||||||
|
RuleParser binaryParser = new RuleBinaryParser();
|
||||||
|
Rule expectedRule =
|
||||||
|
new Rule(
|
||||||
|
new AtomicFormula.StringAtomicFormula(
|
||||||
|
AtomicFormula.APP_CERTIFICATE_LINEAGE,
|
||||||
|
IntegrityUtils.getHexDigest(
|
||||||
|
appCertificate.getBytes(StandardCharsets.UTF_8)),
|
||||||
|
/* isHashedValue= */ true),
|
||||||
|
Rule.DENY);
|
||||||
|
|
||||||
|
List<Rule> rules = binaryParser.parse(rule.array());
|
||||||
|
|
||||||
|
assertThat(rules).isEqualTo(Collections.singletonList(expectedRule));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBinaryString_validAtomicFormula_integerValue_noIndexing() throws Exception {
|
public void testBinaryString_validAtomicFormula_integerValue_noIndexing() throws Exception {
|
||||||
int versionCode = 1;
|
int versionCode = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user