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 {
1414 count (violation) == 0
1515}
1616
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+
1725# METADATA
1826# entrypoint: true
1927violation contains {" field" : " username" , " code" : " username-too-short" , " msg" : " username too short" } if {
@@ -39,6 +47,20 @@ violation contains {
3947 not regex.match (` ^[a-z0-9.=_/-]+$` , input.username)
4048}
4149
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+
4264violation contains {" msg" : " unspecified registration method" } if {
4365 not input.registration_method
4466}
Original file line number Diff line number Diff line change @@ -75,6 +75,20 @@ test_numeric_username if {
7575 not register.allow with input as {" username" : " 1234" , " registration_method" : " upstream-oauth2" }
7676}
7777
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+
7892test_ip_ban if {
7993 not register.allow with input as {
8094 " username" : " hello" ,
You can’t perform that action at this time.
0 commit comments