Skip to content

Commit

Permalink
Test empty match/equals/contains section for rundeck#206
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Apr 24, 2013
1 parent 194626b commit b81947a
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,30 @@ public void testTypeRuleContextMatcherMatchRule() {
}
}

public void testTypeRuleContextMatcherMatchRuleWithInvalidContentShouldNotMatch() {
//invalid content
final Object load = yaml.load("match: \n"
+ "name: '.*blah.*'\n"
+ "allow: '*'");
assertTrue(load instanceof Map);
final Map ruleSection = (Map) load;
final YamlPolicy.TypeRuleContextMatcher typeRuleContext = new YamlPolicy.TypeRuleContextMatcher(
ruleSection, 1);

final HashMap<String, String> resmap = new HashMap<String, String>();

//false result for no match
assertFalse(typeRuleContext.ruleMatchesMatchSection(resmap, ruleSection));

resmap.put("name", "something");
assertFalse(typeRuleContext.ruleMatchesMatchSection(resmap, ruleSection));
resmap.put("name", "blah");
assertFalse(typeRuleContext.ruleMatchesMatchSection(resmap, ruleSection));
resmap.put("name", "ablahz");
assertFalse(typeRuleContext.ruleMatchesMatchSection(resmap, ruleSection));

}

public void testTypeRuleContextMatcherEqualsRule() {
{
//equality for single attribute 'name'
Expand Down Expand Up @@ -1669,6 +1693,28 @@ public void testTypeRuleContextMatcherEqualsRule() {
}
}

public void testTypeRuleContextMatcherEqualsRuleWithInvalidContentShouldNotMatch() {
//yaml name: is not indented properly
final Object load = yaml.load("equals: \n"
+ "name: blah\n"
+ "allow: '*'");
assertTrue(load instanceof Map);
final Map ruleSection = (Map) load;
final YamlPolicy.TypeRuleContextMatcher typeRuleContext = new YamlPolicy.TypeRuleContextMatcher(
ruleSection, 1);

final HashMap<String, String> resmap = new HashMap<String, String>();

//false result for no match
assertFalse(typeRuleContext.ruleMatchesEqualsSection(resmap, ruleSection));

resmap.put("name", "something");
assertFalse(typeRuleContext.ruleMatchesEqualsSection(resmap, ruleSection));
resmap.put("name", "blah");
assertFalse(typeRuleContext.ruleMatchesEqualsSection(resmap, ruleSection));
resmap.put("name", "ablahz");
assertFalse(typeRuleContext.ruleMatchesEqualsSection(resmap, ruleSection));
}
public void testTypeRuleContextMatcherContainsRule() {
{
//match single attribute
Expand Down Expand Up @@ -1773,6 +1819,31 @@ public void testTypeRuleContextMatcherContainsRule() {
}
}

public void testTypeRuleContextMatcherContainsRuleWithInvalidContentShouldNotMatch() {
//empty contains section
final Object load = yaml.load("contains: \n"
+ "name: blah\n"
+ "allow: '*'");
assertTrue(load instanceof Map);
final Map ruleSection = (Map) load;
final YamlPolicy.TypeRuleContextMatcher typeRuleContext = new YamlPolicy.TypeRuleContextMatcher(
ruleSection, 1);

final HashMap<String, String> resmap = new HashMap<String, String>();

//false result for no match
assertFalse(typeRuleContext.ruleMatchesContainsSection(resmap, ruleSection));

resmap.put("name", "something");
assertFalse(typeRuleContext.ruleMatchesContainsSection(resmap, ruleSection));
resmap.put("name", "blah");
assertFalse(typeRuleContext.ruleMatchesContainsSection(resmap, ruleSection));
resmap.put("name", "ablahz");
assertFalse(typeRuleContext.ruleMatchesContainsSection(resmap, ruleSection));
resmap.put("name", "blah, test");
assertFalse(typeRuleContext.ruleMatchesContainsSection(resmap, ruleSection));
}

public void testTypeRuleContextMatcher() {
{
//match any resource without any match constraints
Expand Down

0 comments on commit b81947a

Please sign in to comment.