Include isHashedValue in rule structure
Bug: 141979167 Test: atest FrameworksServicesTests:RuleXmlSerializerTest Test: atest FrameworksServicesTests:RuleXmlParserTest Change-Id: Ic4587c5bcd65e0748c15655f79136eaa50a4eb1f
This commit is contained in:
@@ -253,6 +253,8 @@ public abstract class AtomicFormula implements Formula {
|
||||
/** An {@link AtomicFormula} with a key and string value. */
|
||||
public static final class StringAtomicFormula extends AtomicFormula implements Parcelable {
|
||||
private final String mValue;
|
||||
// Indicates whether the value is the actual value or the hashed value.
|
||||
private final boolean mIsHashedValue;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link StringAtomicFormula}.
|
||||
@@ -262,8 +264,9 @@ public abstract class AtomicFormula implements Formula {
|
||||
*
|
||||
* @throws IllegalArgumentException if {@code key} cannot be used with string value
|
||||
*/
|
||||
public StringAtomicFormula(@Key int key, @NonNull String value) {
|
||||
public StringAtomicFormula(@Key int key, @NonNull String value, boolean isHashedValue) {
|
||||
super(key);
|
||||
mIsHashedValue = isHashedValue;
|
||||
checkArgument(
|
||||
key == PACKAGE_NAME
|
||||
|| key == APP_CERTIFICATE
|
||||
@@ -277,6 +280,7 @@ public abstract class AtomicFormula implements Formula {
|
||||
StringAtomicFormula(Parcel in) {
|
||||
super(in.readInt());
|
||||
mValue = in.readStringNoHelper();
|
||||
mIsHashedValue = in.readByte() != 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -335,6 +339,7 @@ public abstract class AtomicFormula implements Formula {
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeInt(getKey());
|
||||
dest.writeStringNoHelper(mValue);
|
||||
dest.writeByte((byte) (mIsHashedValue ? 1 : 0));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -342,6 +347,10 @@ public abstract class AtomicFormula implements Formula {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public boolean getIsHashedValue() {
|
||||
return mIsHashedValue;
|
||||
}
|
||||
|
||||
private String getMetadataValueByKey(AppInstallMetadata appInstallMetadata) {
|
||||
switch (getKey()) {
|
||||
case PACKAGE_NAME:
|
||||
|
||||
@@ -51,6 +51,7 @@ public final class RuleXmlParser implements RuleParser {
|
||||
private static final String OPERATOR_ATTRIBUTE = "O";
|
||||
private static final String VALUE_ATTRIBUTE = "V";
|
||||
private static final String CONNECTOR_ATTRIBUTE = "C";
|
||||
private static final String IS_HASHED_VALUE_ATTRIBUTE = "H";
|
||||
|
||||
@Override
|
||||
public List<Rule> parse(String ruleText) throws RuleParseException {
|
||||
@@ -179,6 +180,8 @@ public final class RuleXmlParser implements RuleParser {
|
||||
int operator = Integer.parseInt(
|
||||
extractAttributeValue(parser, OPERATOR_ATTRIBUTE).orElse("-1"));
|
||||
String value = extractAttributeValue(parser, VALUE_ATTRIBUTE).orElse(null);
|
||||
String isHashedValue = extractAttributeValue(parser, IS_HASHED_VALUE_ATTRIBUTE).orElse(
|
||||
null);
|
||||
|
||||
int eventType;
|
||||
while ((eventType = parser.next()) != XmlPullParser.END_DOCUMENT) {
|
||||
@@ -186,17 +189,18 @@ public final class RuleXmlParser implements RuleParser {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return constructAtomicFormulaBasedOnKey(key, operator, value);
|
||||
return constructAtomicFormulaBasedOnKey(key, operator, value, isHashedValue);
|
||||
}
|
||||
|
||||
private static Formula constructAtomicFormulaBasedOnKey(@AtomicFormula.Key int key,
|
||||
@AtomicFormula.Operator int operator, String value) {
|
||||
@AtomicFormula.Operator int operator, String value, String isHashedValue) {
|
||||
switch (key) {
|
||||
case AtomicFormula.PACKAGE_NAME:
|
||||
case AtomicFormula.INSTALLER_NAME:
|
||||
case AtomicFormula.APP_CERTIFICATE:
|
||||
case AtomicFormula.INSTALLER_CERTIFICATE:
|
||||
return new AtomicFormula.StringAtomicFormula(key, value);
|
||||
return new AtomicFormula.StringAtomicFormula(key, value,
|
||||
Boolean.parseBoolean(isHashedValue));
|
||||
case AtomicFormula.PRE_INSTALLED:
|
||||
return new AtomicFormula.BooleanAtomicFormula(key, Boolean.parseBoolean(value));
|
||||
case AtomicFormula.VERSION_CODE:
|
||||
|
||||
@@ -48,6 +48,7 @@ public class RuleXmlSerializer implements RuleSerializer {
|
||||
private static final String OPERATOR_ATTRIBUTE = "O";
|
||||
private static final String VALUE_ATTRIBUTE = "V";
|
||||
private static final String CONNECTOR_ATTRIBUTE = "C";
|
||||
private static final String IS_HASHED_VALUE_ATTRIBUTE = "H";
|
||||
|
||||
@Override
|
||||
public void serialize(List<Rule> rules, OutputStream outputStream)
|
||||
@@ -129,6 +130,10 @@ public class RuleXmlSerializer implements RuleSerializer {
|
||||
if (atomicFormula instanceof AtomicFormula.StringAtomicFormula) {
|
||||
serializeAttributeValue(VALUE_ATTRIBUTE,
|
||||
((AtomicFormula.StringAtomicFormula) atomicFormula).getValue(), xmlSerializer);
|
||||
serializeAttributeValue(IS_HASHED_VALUE_ATTRIBUTE,
|
||||
String.valueOf(
|
||||
((AtomicFormula.StringAtomicFormula) atomicFormula).getIsHashedValue()),
|
||||
xmlSerializer);
|
||||
} else if (atomicFormula instanceof AtomicFormula.IntAtomicFormula) {
|
||||
serializeAttributeValue(OPERATOR_ATTRIBUTE,
|
||||
String.valueOf(((AtomicFormula.IntAtomicFormula) atomicFormula).getOperator()),
|
||||
|
||||
@@ -63,7 +63,8 @@ public class RuleEvaluatorTest {
|
||||
public void testEvaluateRules_noMatchedRules_allow() {
|
||||
Rule rule1 =
|
||||
new Rule(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_2),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_2,
|
||||
/* isHashedValue= */ false),
|
||||
Rule.DENY);
|
||||
|
||||
IntegrityCheckResult result =
|
||||
@@ -76,11 +77,13 @@ public class RuleEvaluatorTest {
|
||||
public void testEvaluateRules_oneMatch_deny() {
|
||||
Rule rule1 =
|
||||
new Rule(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1,
|
||||
/* isHashedValue= */ false),
|
||||
Rule.DENY);
|
||||
Rule rule2 =
|
||||
new Rule(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_2),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_2,
|
||||
/* isHashedValue= */ false),
|
||||
Rule.DENY);
|
||||
|
||||
IntegrityCheckResult result =
|
||||
@@ -94,15 +97,18 @@ public class RuleEvaluatorTest {
|
||||
public void testEvaluateRules_multipleMatches_deny() {
|
||||
Rule rule1 =
|
||||
new Rule(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1,
|
||||
/* isHashedValue= */ false),
|
||||
Rule.DENY);
|
||||
OpenFormula openFormula2 =
|
||||
new OpenFormula(
|
||||
OpenFormula.AND,
|
||||
Arrays.asList(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1,
|
||||
/* isHashedValue= */ false),
|
||||
new StringAtomicFormula(
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE)));
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE,
|
||||
/* isHashedValue= */ false)));
|
||||
Rule rule2 = new Rule(openFormula2, Rule.DENY);
|
||||
|
||||
IntegrityCheckResult result =
|
||||
@@ -119,7 +125,8 @@ public class RuleEvaluatorTest {
|
||||
OpenFormula.NOT,
|
||||
Collections.singletonList(
|
||||
new StringAtomicFormula(
|
||||
AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_2)));
|
||||
AtomicFormula.PACKAGE_NAME,
|
||||
PACKAGE_NAME_2, /* isHashedValue= */ false)));
|
||||
Rule rule = new Rule(openFormula, Rule.DENY);
|
||||
|
||||
IntegrityCheckResult result =
|
||||
@@ -150,9 +157,11 @@ public class RuleEvaluatorTest {
|
||||
new OpenFormula(
|
||||
OpenFormula.AND,
|
||||
Arrays.asList(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1,
|
||||
/* isHashedValue= */ false),
|
||||
new StringAtomicFormula(
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE)));
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE,
|
||||
/* isHashedValue= */ false)));
|
||||
Rule rule = new Rule(openFormula, Rule.DENY);
|
||||
|
||||
IntegrityCheckResult result =
|
||||
@@ -168,9 +177,11 @@ public class RuleEvaluatorTest {
|
||||
new OpenFormula(
|
||||
OpenFormula.OR,
|
||||
Arrays.asList(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1,
|
||||
/* isHashedValue= */ false),
|
||||
new StringAtomicFormula(
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE)));
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE,
|
||||
/* isHashedValue= */ false)));
|
||||
Rule rule = new Rule(openFormula, Rule.DENY);
|
||||
|
||||
IntegrityCheckResult result =
|
||||
@@ -185,9 +196,11 @@ public class RuleEvaluatorTest {
|
||||
new OpenFormula(
|
||||
OpenFormula.AND,
|
||||
Arrays.asList(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_2),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_2,
|
||||
/* isHashedValue= */ false),
|
||||
new StringAtomicFormula(
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE)));
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE,
|
||||
/* isHashedValue= */ false)));
|
||||
OpenFormula openFormula =
|
||||
new OpenFormula(OpenFormula.NOT, Collections.singletonList(openSubFormula));
|
||||
Rule rule = new Rule(openFormula, Rule.DENY);
|
||||
@@ -202,15 +215,18 @@ public class RuleEvaluatorTest {
|
||||
public void testEvaluateRules_forceAllow() {
|
||||
Rule rule1 =
|
||||
new Rule(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1,
|
||||
/* isHashedValue= */ false),
|
||||
Rule.FORCE_ALLOW);
|
||||
OpenFormula openFormula2 =
|
||||
new OpenFormula(
|
||||
OpenFormula.AND,
|
||||
Arrays.asList(
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1),
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME_1,
|
||||
/* isHashedValue= */ false),
|
||||
new StringAtomicFormula(
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE)));
|
||||
AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE,
|
||||
/* isHashedValue= */ false)));
|
||||
Rule rule2 = new Rule(openFormula2, Rule.DENY);
|
||||
|
||||
IntegrityCheckResult result =
|
||||
|
||||
@@ -38,7 +38,8 @@ public class AtomicFormulaTest {
|
||||
@Test
|
||||
public void testValidAtomicFormula_stringValue() {
|
||||
StringAtomicFormula stringAtomicFormula =
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.test.app");
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME,
|
||||
"com.test.app", /* isHashedValue= */ false);
|
||||
|
||||
assertEquals(AtomicFormula.PACKAGE_NAME, stringAtomicFormula.getKey());
|
||||
}
|
||||
@@ -66,7 +67,8 @@ public class AtomicFormulaTest {
|
||||
/* expectedExceptionMessageRegex */
|
||||
String.format(
|
||||
"Key VERSION_CODE cannot be used with StringAtomicFormula"),
|
||||
() -> new StringAtomicFormula(AtomicFormula.VERSION_CODE, "test-value"));
|
||||
() -> new StringAtomicFormula(AtomicFormula.VERSION_CODE, "test-value",
|
||||
/* isHashedValue= */ false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,7 +94,8 @@ public class AtomicFormulaTest {
|
||||
@Test
|
||||
public void testIsSatisfiable_string_true() {
|
||||
StringAtomicFormula stringAtomicFormula =
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.test.app");
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME,
|
||||
"com.test.app", /* isHashedValue= */ false);
|
||||
AppInstallMetadata appInstallMetadata =
|
||||
getAppInstallMetadataBuilder().setPackageName("com.test.app").build();
|
||||
|
||||
@@ -102,7 +105,8 @@ public class AtomicFormulaTest {
|
||||
@Test
|
||||
public void testIsSatisfiable_string_false() {
|
||||
StringAtomicFormula stringAtomicFormula =
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.test.app");
|
||||
new StringAtomicFormula(AtomicFormula.PACKAGE_NAME,
|
||||
"com.test.app", /* isHashedValue= */ false);
|
||||
AppInstallMetadata appInstallMetadata =
|
||||
getAppInstallMetadataBuilder().setPackageName("com.foo.bar").build();
|
||||
|
||||
@@ -231,7 +235,8 @@ public class AtomicFormulaTest {
|
||||
|
||||
@Test
|
||||
public void testParcelUnparcel_string() {
|
||||
StringAtomicFormula formula = new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "abc");
|
||||
StringAtomicFormula formula = new StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "abc",
|
||||
/* isHashedValue= */ false);
|
||||
Parcel p = Parcel.obtain();
|
||||
formula.writeToParcel(p, 0);
|
||||
p.setDataPosition(0);
|
||||
|
||||
@@ -35,7 +35,8 @@ import java.util.Collections;
|
||||
public class OpenFormulaTest {
|
||||
|
||||
private static final AtomicFormula ATOMIC_FORMULA_1 =
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "test1");
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "test1",
|
||||
/* isHashedValue= */ false);
|
||||
private static final AtomicFormula ATOMIC_FORMULA_2 =
|
||||
new AtomicFormula.IntAtomicFormula(AtomicFormula.VERSION_CODE, AtomicFormula.EQ, 1);
|
||||
|
||||
|
||||
@@ -36,9 +36,11 @@ public class RuleTest {
|
||||
private static final String PACKAGE_NAME = "com.test.app";
|
||||
private static final String APP_CERTIFICATE = "test_cert";
|
||||
private static final Formula PACKAGE_NAME_ATOMIC_FORMULA =
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME);
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, PACKAGE_NAME,
|
||||
/* isHashedValue= */ false);
|
||||
private static final Formula APP_CERTIFICATE_ATOMIC_FORMULA =
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE);
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.APP_CERTIFICATE, APP_CERTIFICATE,
|
||||
/* isHashedValue= */ false);
|
||||
|
||||
@Test
|
||||
public void testValidRule() {
|
||||
|
||||
@@ -58,7 +58,8 @@ public class RuleXmlParserTest {
|
||||
RuleParser xmlParser = new RuleXmlParser();
|
||||
InputStream inputStream = new ByteArrayInputStream(ruleXmlOpenFormula.getBytes());
|
||||
Rule expectedRule = new Rule(new OpenFormula(OpenFormula.NOT, Collections.singletonList(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"))),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false))),
|
||||
Rule.DENY);
|
||||
|
||||
List<Rule> rules = xmlParser.parse(inputStream);
|
||||
@@ -84,7 +85,8 @@ public class RuleXmlParserTest {
|
||||
+ "</RL>";
|
||||
RuleParser xmlParser = new RuleXmlParser();
|
||||
Rule expectedRule = new Rule(new OpenFormula(OpenFormula.NOT, Collections.singletonList(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"))),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false))),
|
||||
Rule.DENY);
|
||||
|
||||
List<Rule> rules = xmlParser.parse(ruleXmlOpenFormula);
|
||||
@@ -114,8 +116,10 @@ public class RuleXmlParserTest {
|
||||
+ "</RL>";
|
||||
RuleParser xmlParser = new RuleXmlParser();
|
||||
Rule expectedRule = new Rule(new OpenFormula(OpenFormula.AND, Arrays.asList(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.APP_CERTIFICATE, "test_cert"))),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.APP_CERTIFICATE, "test_cert",
|
||||
/* isHashedValue= */ false))),
|
||||
Rule.DENY);
|
||||
|
||||
List<Rule> rules = xmlParser.parse(ruleXmlOpenFormula);
|
||||
@@ -145,8 +149,10 @@ public class RuleXmlParserTest {
|
||||
+ "</RL>";
|
||||
RuleParser xmlParser = new RuleXmlParser();
|
||||
Rule expectedRule = new Rule(new OpenFormula(OpenFormula.OR, Arrays.asList(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.APP_CERTIFICATE, "test_cert"))),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.APP_CERTIFICATE, "test_cert",
|
||||
/* isHashedValue= */ false))),
|
||||
Rule.DENY);
|
||||
|
||||
List<Rule> rules = xmlParser.parse(ruleXmlOpenFormula);
|
||||
@@ -172,7 +178,8 @@ public class RuleXmlParserTest {
|
||||
+ "</RL>";
|
||||
RuleParser xmlParser = new RuleXmlParser();
|
||||
Rule expectedRule = new Rule(new OpenFormula(OpenFormula.NOT, Collections.singletonList(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"))),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false))),
|
||||
Rule.DENY);
|
||||
|
||||
List<Rule> rules = xmlParser.parse(ruleXmlOpenFormula);
|
||||
@@ -297,7 +304,8 @@ public class RuleXmlParserTest {
|
||||
+ "</RL>";
|
||||
RuleParser xmlParser = new RuleXmlParser();
|
||||
Rule expectedRule = new Rule(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false),
|
||||
Rule.DENY);
|
||||
|
||||
List<Rule> rules = xmlParser.parse(ruleXmlAtomicFormula);
|
||||
@@ -364,7 +372,8 @@ public class RuleXmlParserTest {
|
||||
+ "</RL>";
|
||||
RuleParser xmlParser = new RuleXmlParser();
|
||||
Rule expectedRule = new Rule(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false),
|
||||
Rule.DENY);
|
||||
|
||||
List<Rule> rules = xmlParser.parse(ruleXmlAtomicFormula);
|
||||
|
||||
@@ -57,12 +57,14 @@ public class RuleXmlSerializerTest {
|
||||
public void testXmlString_serializeMultipleRules_oneEmpty() throws Exception {
|
||||
Rule rule1 = null;
|
||||
Rule rule2 = new Rule(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false),
|
||||
Rule.DENY);
|
||||
RuleSerializer xmlSerializer = new RuleXmlSerializer();
|
||||
Map<String, String> packageNameAttrs = new LinkedHashMap<>();
|
||||
packageNameAttrs.put("K", String.valueOf(AtomicFormula.PACKAGE_NAME));
|
||||
packageNameAttrs.put("V", "com.app.test");
|
||||
packageNameAttrs.put("H", "false");
|
||||
String expectedRules = "<RL>"
|
||||
+ generateTagWithAttribute(/* tag= */ "R",
|
||||
Collections.singletonMap("E", String.valueOf(Rule.DENY)),
|
||||
@@ -81,12 +83,13 @@ public class RuleXmlSerializerTest {
|
||||
Rule rule = new Rule(new OpenFormula(OpenFormula.NOT,
|
||||
Collections.singletonList(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME,
|
||||
"com.app.test"))), Rule.DENY);
|
||||
"com.app.test", /* isHashedValue= */ false))), Rule.DENY);
|
||||
RuleSerializer xmlSerializer = new RuleXmlSerializer();
|
||||
OutputStream outputStream = new ByteArrayOutputStream();
|
||||
Map<String, String> packageNameAttrs = new LinkedHashMap<>();
|
||||
packageNameAttrs.put("K", String.valueOf(AtomicFormula.PACKAGE_NAME));
|
||||
packageNameAttrs.put("V", "com.app.test");
|
||||
packageNameAttrs.put("H", "false");
|
||||
String expectedRules = "<RL>"
|
||||
+ generateTagWithAttribute(/* tag= */ "R",
|
||||
Collections.singletonMap("E", String.valueOf(Rule.DENY)),
|
||||
@@ -110,11 +113,12 @@ public class RuleXmlSerializerTest {
|
||||
Rule rule = new Rule(new OpenFormula(OpenFormula.NOT,
|
||||
Collections.singletonList(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME,
|
||||
"com.app.test"))), Rule.DENY);
|
||||
"com.app.test", /* isHashedValue= */ false))), Rule.DENY);
|
||||
RuleSerializer xmlSerializer = new RuleXmlSerializer();
|
||||
Map<String, String> packageNameAttrs = new LinkedHashMap<>();
|
||||
packageNameAttrs.put("K", String.valueOf(AtomicFormula.PACKAGE_NAME));
|
||||
packageNameAttrs.put("V", "com.app.test");
|
||||
packageNameAttrs.put("H", "false");
|
||||
String expectedRules = "<RL>"
|
||||
+ generateTagWithAttribute(/* tag= */ "R",
|
||||
Collections.singletonMap("E", String.valueOf(Rule.DENY)),
|
||||
@@ -136,16 +140,18 @@ public class RuleXmlSerializerTest {
|
||||
public void testXmlString_serializeValidOpenFormula_andConnector() throws Exception {
|
||||
Rule rule = new Rule(new OpenFormula(OpenFormula.AND,
|
||||
Arrays.asList(new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME,
|
||||
"com.app.test"),
|
||||
"com.app.test", /* isHashedValue= */ false),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.APP_CERTIFICATE,
|
||||
"test_cert"))), Rule.DENY);
|
||||
"test_cert", /* isHashedValue= */ false))), Rule.DENY);
|
||||
RuleSerializer xmlSerializer = new RuleXmlSerializer();
|
||||
Map<String, String> packageNameAttrs = new LinkedHashMap<>();
|
||||
packageNameAttrs.put("K", String.valueOf(AtomicFormula.PACKAGE_NAME));
|
||||
packageNameAttrs.put("V", "com.app.test");
|
||||
packageNameAttrs.put("H", "false");
|
||||
Map<String, String> appCertificateAttrs = new LinkedHashMap<>();
|
||||
appCertificateAttrs.put("K", String.valueOf(AtomicFormula.APP_CERTIFICATE));
|
||||
appCertificateAttrs.put("V", "test_cert");
|
||||
appCertificateAttrs.put("H", "false");
|
||||
String expectedRules = "<RL>"
|
||||
+ generateTagWithAttribute(/* tag= */ "R",
|
||||
Collections.singletonMap("E", String.valueOf(Rule.DENY)),
|
||||
@@ -168,16 +174,18 @@ public class RuleXmlSerializerTest {
|
||||
public void testXmlString_serializeValidOpenFormula_orConnector() throws Exception {
|
||||
Rule rule = new Rule(new OpenFormula(OpenFormula.OR,
|
||||
Arrays.asList(new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME,
|
||||
"com.app.test"),
|
||||
"com.app.test", /* isHashedValue= */ false),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.APP_CERTIFICATE,
|
||||
"test_cert"))), Rule.DENY);
|
||||
"test_cert", /* isHashedValue= */ false))), Rule.DENY);
|
||||
RuleSerializer xmlSerializer = new RuleXmlSerializer();
|
||||
Map<String, String> packageNameAttrs = new LinkedHashMap<>();
|
||||
packageNameAttrs.put("K", String.valueOf(AtomicFormula.PACKAGE_NAME));
|
||||
packageNameAttrs.put("V", "com.app.test");
|
||||
packageNameAttrs.put("H", "false");
|
||||
Map<String, String> appCertificateAttrs = new LinkedHashMap<>();
|
||||
appCertificateAttrs.put("K", String.valueOf(AtomicFormula.APP_CERTIFICATE));
|
||||
appCertificateAttrs.put("V", "test_cert");
|
||||
appCertificateAttrs.put("H", "false");
|
||||
String expectedRules = "<RL>"
|
||||
+ generateTagWithAttribute(/* tag= */ "R",
|
||||
Collections.singletonMap("E", String.valueOf(Rule.DENY)),
|
||||
@@ -199,12 +207,14 @@ public class RuleXmlSerializerTest {
|
||||
@Test
|
||||
public void testXmlString_serializeValidAtomicFormula_stringValue() throws Exception {
|
||||
Rule rule = new Rule(
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test"),
|
||||
new AtomicFormula.StringAtomicFormula(AtomicFormula.PACKAGE_NAME, "com.app.test",
|
||||
/* isHashedValue= */ false),
|
||||
Rule.DENY);
|
||||
RuleSerializer xmlSerializer = new RuleXmlSerializer();
|
||||
Map<String, String> packageNameAttrs = new LinkedHashMap<>();
|
||||
packageNameAttrs.put("K", String.valueOf(AtomicFormula.PACKAGE_NAME));
|
||||
packageNameAttrs.put("V", "com.app.test");
|
||||
packageNameAttrs.put("H", "false");
|
||||
String expectedRules = "<RL>"
|
||||
+ generateTagWithAttribute(/* tag= */ "R",
|
||||
Collections.singletonMap("E", String.valueOf(Rule.DENY)),
|
||||
|
||||
Reference in New Issue
Block a user