@@ -47,13 +47,13 @@ impl Assertion {
47
47
48
48
pub fn build_role_links ( & mut self , rm : Arc < RwLock < dyn RoleManager > > ) -> Result < ( ) > {
49
49
let count = self . value . chars ( ) . filter ( |& c| c == '_' ) . count ( ) ;
50
+ if count < 2 {
51
+ return Err ( ModelError :: P (
52
+ r#"the number of "_" in role definition should be at least 2"# . to_owned ( ) ,
53
+ )
54
+ . into ( ) ) ;
55
+ }
50
56
for rule in & self . policy {
51
- if count < 2 {
52
- return Err ( ModelError :: P (
53
- r#"the number of "_" in role definition should be at least 2"# . to_owned ( ) ,
54
- )
55
- . into ( ) ) ;
56
- }
57
57
if rule. len ( ) < count {
58
58
return Err ( PolicyError :: UnmatchPolicyDefinition ( count, rule. len ( ) ) . into ( ) ) ;
59
59
}
@@ -78,6 +78,12 @@ impl Assertion {
78
78
d : EventData ,
79
79
) -> Result < ( ) > {
80
80
let count = self . value . chars ( ) . filter ( |& c| c == '_' ) . count ( ) ;
81
+ if count < 2 {
82
+ return Err ( ModelError :: P (
83
+ r#"the number of "_" in role definition should be at least 2"# . to_owned ( ) ,
84
+ )
85
+ . into ( ) ) ;
86
+ }
81
87
82
88
if let Some ( ( insert, rules) ) = match d {
83
89
EventData :: AddPolicy ( _, _, rule) => Some ( ( true , vec ! [ rule] ) ) ,
@@ -88,12 +94,6 @@ impl Assertion {
88
94
_ => None ,
89
95
} {
90
96
for rule in rules {
91
- if count < 2 {
92
- return Err ( ModelError :: P (
93
- r#"the number of "_" in role definition should be at least 2"# . to_owned ( ) ,
94
- )
95
- . into ( ) ) ;
96
- }
97
97
if rule. len ( ) < count {
98
98
return Err ( PolicyError :: UnmatchPolicyDefinition ( count, rule. len ( ) ) . into ( ) ) ;
99
99
}
0 commit comments