Skip to content

Commit 7e7d40a

Browse files
committed
Add example microflow policy
1 parent 9efbde2 commit 7e7d40a

File tree

4 files changed

+83
-19
lines changed

4 files changed

+83
-19
lines changed

docs/mendix-best-practices/Microflows/31-String-empty-check-not-completed.markdown

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# METADATA
2+
# scope: package
3+
# title: Empty String check not complete
4+
# description: Technically, there is a difference between empty and "". Make sure to check them both.
5+
# authors:
6+
# - Xiwen Cheng <[email protected]>
7+
# custom:
8+
# category: Error
9+
# rulename: EmptyStringCheckNotComplete
10+
# severity: MEDIUM
11+
# rulenumber: 005_0001
12+
# remediation: Always check a string for empty based on != empty and != "". The first one equals database NULL value, the latter one indicates a truncated string.
13+
# input: "*/**/*$Microflow.yaml"
14+
package app.mendix.microflows.empty_string_check_not_complete
15+
import rego.v1
16+
annotation := rego.metadata.chain()[1].annotations
17+
18+
default allow := false
19+
allow if count(errors) == 0
20+
21+
errors contains error if {
22+
[p, v] := walk(input)
23+
last := array.slice(p, count(p) - 1, count(p))[0]
24+
last == "Expression"
25+
contains(replace(v, " ", ""), "!=''")
26+
not contains(replace(v, " ", ""), "!=empty")
27+
error := sprintf("[%v, %v, %v] Expression in Microflow '%v' has incomplete empty string check '%v'",
28+
[
29+
annotation.custom.severity,
30+
annotation.custom.category,
31+
annotation.custom.rulenumber,
32+
input.Name,
33+
v,
34+
]
35+
)
36+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package app.mendix.microflows.empty_string_check_not_complete
2+
import rego.v1
3+
4+
5+
# Test data
6+
microflow_good = {
7+
"$Type": "Microflow$Page",
8+
"Name": "mf1",
9+
"ObjectCollection": {
10+
"$Type": "Microflows$MicroflowObjectCollection",
11+
"Objects": [
12+
{
13+
"$Type": "Microflows$ExclusiveSplit",
14+
"SplitCondition": {
15+
"$Type": "Microflows$ExpressionSplitCondition",
16+
"Expression": "$Variable != empty and $Variable != ''",
17+
},
18+
},
19+
],
20+
},
21+
}
22+
23+
microflow_bad = {
24+
"$Type": "Microflow$Page",
25+
"Name": "mf1",
26+
"ObjectCollection": {
27+
"$Type": "Microflows$MicroflowObjectCollection",
28+
"Objects": [
29+
{
30+
"$Type": "Microflows$ExclusiveSplit",
31+
"SplitCondition": {
32+
"$Type": "Microflows$ExpressionSplitCondition",
33+
"Expression": "$Variable != ''",
34+
},
35+
},
36+
],
37+
},
38+
}
39+
40+
# Test cases
41+
test_simple if {
42+
allow with input as microflow_good
43+
}
44+
45+
test_simple_negative if {
46+
not allow with input as microflow_bad
47+
}

resources/app/App.mpr

4 KB
Binary file not shown.

0 commit comments

Comments
 (0)