Skip to content

Commit

Permalink
catching some bad groups in arrays and objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Newton committed Dec 17, 2017
1 parent d0752da commit 16c9334
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/jcr/check_groups.rb
Expand Up @@ -56,7 +56,7 @@ def self.disallowed_group_in_value? node, mapping
disallowed_group_in_value?( groupee[:group_rule], mapping )
elsif groupee[:target_rule_name]
trule = get_name_mapping( groupee[:target_rule_name][:rule_name], mapping )
disallowed_group_in_value?( trule[:rule], mapping )
disallowed_group_in_value?( trule, mapping )
elsif groupee[:member_rule]
raise_group_error( "groups in value rules cannot have member rules", groupee[:member_rule] )
elsif groupee[:object_rule]
Expand Down Expand Up @@ -132,9 +132,7 @@ def self.disallowed_group_in_array? node, mapping
disallowed_group_in_array?( groupee[:group_rule], mapping )
elsif groupee[:target_rule_name]
trule = get_name_mapping( groupee[:target_rule_name][:rule_name], mapping )
if trule[:group_rule]
disallowed_group_in_array?( trule[:group_rule], mapping )
end
disallowed_group_in_array?( trule, mapping )
elsif groupee[:member_rule]
raise_group_error( "groups in array rules cannot have member rules", groupee[:member_rule] )
else
Expand Down Expand Up @@ -169,9 +167,7 @@ def self.disallowed_group_in_object? node, mapping
disallowed_group_in_object?( groupee[:group_rule], mapping )
elsif groupee[:target_rule_name]
trule = get_name_mapping( groupee[:target_rule_name][:rule_name], mapping )
if trule[:group_rule]
disallowed_group_in_object?( trule[:group_rule], mapping )
end
disallowed_group_in_object?( trule, mapping )
elsif groupee[:array_rule]
raise_group_error( "groups in object rules cannot have array rules", groupee[:member_rule] )
elsif groupee[:object_rule]
Expand Down
14 changes: 14 additions & 0 deletions spec/check_groups_spec.rb
Expand Up @@ -169,6 +169,13 @@
expect{ JCR.check_groups( tree, mapping ) }.to raise_error JCR::JcrValidatorError
end

it 'should error with array with group referencing a member' do
tree = JCR.parse( '$t=[$g] $g=($m) $m="foo":string' )
mapping = JCR.map_rule_names( tree )
JCR.check_rule_target_names( tree, mapping )
expect{ JCR.check_groups( tree, mapping ) }.to raise_error JCR::JcrValidatorError
end

#
# object rule tests
#
Expand Down Expand Up @@ -263,4 +270,11 @@
expect{ JCR.check_groups( tree, mapping ) }.to raise_error JCR::JcrValidatorError
end

it 'should error with group with both object-rule' do
tree = JCR.parse( '$t={$g} $g=($m) $m={"foo":string}' )
mapping = JCR.map_rule_names( tree )
JCR.check_rule_target_names( tree, mapping )
expect{ JCR.check_groups( tree, mapping ) }.to raise_error JCR::JcrValidatorError
end

end

0 comments on commit 16c9334

Please sign in to comment.