File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,14 @@ allow if {
14
14
count (violation) == 0
15
15
}
16
16
17
+ username_allowed if {
18
+ not data.registration.allowed_usernames
19
+ }
20
+
21
+ username_allowed if {
22
+ common.matches_string_constraints (input.username, data.registration.allowed_usernames)
23
+ }
24
+
17
25
# METADATA
18
26
# entrypoint: true
19
27
violation contains {" field" : " username" , " code" : " username-too-short" , " msg" : " username too short" } if {
@@ -39,6 +47,20 @@ violation contains {
39
47
not regex.match (` ^[a-z0-9.=_/-]+$` , input.username)
40
48
}
41
49
50
+ violation contains {
51
+ " field" : " username" , " code" : " username-banned" ,
52
+ " msg" : " username is banned" ,
53
+ } if {
54
+ common.matches_string_constraints (input.username, data.registration.banned_usernames)
55
+ }
56
+
57
+ violation contains {
58
+ " field" : " username" , " code" : " username-not-allowed" ,
59
+ " msg" : " username is not allowed" ,
60
+ } if {
61
+ not username_allowed
62
+ }
63
+
42
64
violation contains {" msg" : " unspecified registration method" } if {
43
65
not input.registration_method
44
66
}
Original file line number Diff line number Diff line change @@ -75,6 +75,20 @@ test_numeric_username if {
75
75
not register.allow with input as {" username" : " 1234" , " registration_method" : " upstream-oauth2" }
76
76
}
77
77
78
+ test_allowed_username if {
79
+ register.allow with input as {" username" : " hello" , " registration_method" : " upstream-oauth2" }
80
+ with data.registration.allowed_usernames.literals as [" hello" ]
81
+ not register.allow with input as {" username" : " hello" , " registration_method" : " upstream-oauth2" }
82
+ with data.registration.allowed_usernames.literals as [" world" ]
83
+ }
84
+
85
+ test_banned_username if {
86
+ not register.allow with input as {" username" : " hello" , " registration_method" : " upstream-oauth2" }
87
+ with data.registration.banned_usernames.literals as [" hello" ]
88
+ register.allow with input as {" username" : " hello" , " registration_method" : " upstream-oauth2" }
89
+ with data.registration.banned_usernames.literals as [" world" ]
90
+ }
91
+
78
92
test_ip_ban if {
79
93
not register.allow with input as {
80
94
" username" : " hello" ,
You can’t perform that action at this time.
0 commit comments