@@ -21,25 +21,25 @@ func TestAPIUser_ValidationUpdated(t *testing.T) {
2121 {
2222 name : "valid API user with all fields" ,
2323 apiUser : & APIUser {
24- Owner : "groups/test-group-123 " ,
24+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
2525 DisplayName : "Test API User" ,
2626 State : APIUserState_API_USER_STATE_ACTIVE ,
27- Roles : []string {"groups/test-group-123/ROLE_IAM_VIEWER " },
27+ Roles : []string {"groups/01ARZ3NDEKTSV4RRFFQ69G5FAV/3000001 " },
2828 },
2929 wantValid : true ,
3030 },
3131 {
3232 name : "valid API user with minimal required fields" ,
3333 apiUser : & APIUser {
34- Owner : "groups/test-group-123 " ,
34+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
3535 DisplayName : "Test API User" ,
3636 },
3737 wantValid : true ,
3838 },
3939 {
4040 name : "valid API user with empty system-set fields" ,
4141 apiUser : & APIUser {
42- Owner : "groups/test-group-123 " ,
42+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
4343 DisplayName : "Test API User" ,
4444 State : APIUserState_API_USER_STATE_UNSPECIFIED , // System set, can be unspecified
4545 Roles : []string {}, // Can be empty (0 roles allowed)
@@ -49,7 +49,7 @@ func TestAPIUser_ValidationUpdated(t *testing.T) {
4949 {
5050 name : "valid API user with no roles" ,
5151 apiUser : & APIUser {
52- Owner : "groups/test-group-123 " ,
52+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
5353 DisplayName : "Test API User" ,
5454 Roles : []string {}, // 0 roles allowed
5555 },
@@ -62,7 +62,7 @@ func TestAPIUser_ValidationUpdated(t *testing.T) {
6262 DisplayName : "Test API User" ,
6363 },
6464 wantValid : false ,
65- wantError : "owner is required" ,
65+ wantError : "required" ,
6666 },
6767 {
6868 name : "invalid owner format - missing groups prefix" ,
@@ -71,7 +71,7 @@ func TestAPIUser_ValidationUpdated(t *testing.T) {
7171 DisplayName : "Test API User" ,
7272 },
7373 wantValid : false ,
74- wantError : "owner must be in format groups/{group_id} " ,
74+ wantError : "pattern " ,
7575 },
7676 {
7777 name : "invalid owner format - invalid group ID characters" ,
@@ -80,37 +80,37 @@ func TestAPIUser_ValidationUpdated(t *testing.T) {
8080 DisplayName : "Test API User" ,
8181 },
8282 wantValid : false ,
83- wantError : "group_id contains only alphanumeric characters " ,
83+ wantError : "pattern " ,
8484 },
8585 {
86- name : "valid owner with underscores and hyphens " ,
86+ name : "valid owner with proper ULIDv2 format " ,
8787 apiUser : & APIUser {
88- Owner : "groups/test_group-123 " ,
88+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
8989 DisplayName : "Test API User" ,
9090 },
9191 wantValid : true ,
9292 },
9393 {
9494 name : "owners field accepts any values since no validation defined" ,
9595 apiUser : & APIUser {
96- Owner : "groups/test-group-123 " ,
96+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
9797 DisplayName : "Test API User" ,
9898 },
9999 wantValid : true , // No validation rules defined for owners field in proto
100100 },
101101 {
102102 name : "empty display name - should fail (required field)" ,
103103 apiUser : & APIUser {
104- Owner : "groups/test-group-123 " ,
104+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
105105 DisplayName : "" ,
106106 },
107107 wantValid : false ,
108- wantError : "display name is required" ,
108+ wantError : "required" ,
109109 },
110110 {
111111 name : "display name too long" ,
112112 apiUser : & APIUser {
113- Owner : "groups/test-group-123 " ,
113+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
114114 DisplayName : string (make ([]byte , 256 )), // 256 characters
115115 },
116116 wantValid : false ,
@@ -119,7 +119,7 @@ func TestAPIUser_ValidationUpdated(t *testing.T) {
119119 {
120120 name : "valid state when specified" ,
121121 apiUser : & APIUser {
122- Owner : "groups/test-group-123 " ,
122+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
123123 DisplayName : "Test API User" ,
124124 State : APIUserState_API_USER_STATE_ACTIVE ,
125125 },
@@ -128,7 +128,7 @@ func TestAPIUser_ValidationUpdated(t *testing.T) {
128128 {
129129 name : "valid unspecified state (system can set this)" ,
130130 apiUser : & APIUser {
131- Owner : "groups/test-group-123 " ,
131+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
132132 DisplayName : "Test API User" ,
133133 State : APIUserState_API_USER_STATE_UNSPECIFIED ,
134134 },
@@ -137,20 +137,21 @@ func TestAPIUser_ValidationUpdated(t *testing.T) {
137137 {
138138 name : "multiple valid roles" ,
139139 apiUser : & APIUser {
140- Owner : "groups/test-group-123 " ,
140+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
141141 DisplayName : "Test API User" ,
142- Roles : []string {"groups/test-group-123/ROLE_IAM_VIEWER " , "groups/test-group-123/ROLE_IAM_ADMIN " },
142+ Roles : []string {"groups/01ARZ3NDEKTSV4RRFFQ69G5FAV/3000001 " , "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV/3000000 " },
143143 },
144144 wantValid : true ,
145145 },
146146 {
147147 name : "invalid role format when roles provided" ,
148148 apiUser : & APIUser {
149- Owner : "groups/test-group-123 " ,
149+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
150150 DisplayName : "Test API User" ,
151- Roles : []string {"invalid-role-format" }, // Invalid role format
151+ Roles : []string {"invalid-role-format" },
152152 },
153- wantValid : true , // Currently no validation on role format in proto
153+ wantValid : false , // Role validation is enforced
154+ wantError : "pattern" ,
154155 },
155156 }
156157
@@ -174,29 +175,21 @@ func TestAPIUser_ValidationOwnerFormatsUpdated(t *testing.T) {
174175 validator , err := protovalidate .New ()
175176 require .NoError (t , err )
176177
178+ // Valid ULIDv2 formats
177179 validOwnerFormats := []string {
178- "groups/a" , // single character
179- "groups/abc123" , // alphanumeric
180- "groups/test-group-123" , // with hyphens
181- "groups/test_group_123" , // with underscores
182- "groups/group-with_mixed-123" , // mixed separators
183- "groups/ABC123" , // uppercase
184- "groups/a1b2c3" , // mixed case
180+ "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV" , // Standard ULIDv2
181+ "groups/01BX5ZZKBKACTAV9WEVGEMMVRZ" , // Another valid ULIDv2
185182 }
186183
184+ // Invalid owner formats
187185 invalidOwnerFormats := []string {
188- "" , // empty (required field)
189- "groups/" , // missing group ID
190- "groups/-invalid" , // starts with hyphen
191- "groups/invalid-" , // ends with hyphen
192- "groups/_invalid" , // starts with underscore
193- "groups/invalid_" , // ends with underscore
194- "groups/inv@lid" , // invalid character @
195- "groups/inv!lid" , // invalid character !
196- "groups/inv lid" , // space
197- "groups/inv.lid" , // dot
198- "group/test" , // wrong prefix
199- "test-group-123" , // no prefix
186+ "" , // empty (required field)
187+ "groups/" , // missing group ID
188+ "groups/01ARZ3NDEKTSV4RRFFQ69G5FIL" , // Contains 'I' and 'L' (invalid in ULIDv2)
189+ "groups/01ARZ3NDEKTSV4RRFFQ69G5FA" , // Too short (25 chars instead of 26)
190+ "groups/01ARZ3NDEKTSV4RRFFQ69G5FAVX" , // Too long (27 chars instead of 26)
191+ "group/01ARZ3NDEKTSV4RRFFQ69G5FAV" , // Wrong prefix (missing 's')
192+ "test-group-123" , // No prefix
200193 }
201194
202195 // Test valid formats
@@ -233,7 +226,7 @@ func TestAPIUser_SystemSetFieldsOptional(t *testing.T) {
233226 t .Run ("all system-set fields can be empty/unspecified" , func (t * testing.T ) {
234227 apiUser := & APIUser {
235228 // Only required fields
236- Owner : "groups/test-group-123 " ,
229+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
237230 DisplayName : "Test API User" ,
238231
239232 // System-set fields can be empty/unspecified
@@ -249,7 +242,7 @@ func TestAPIUser_SystemSetFieldsOptional(t *testing.T) {
249242
250243 t .Run ("system-set fields are validated when present" , func (t * testing.T ) {
251244 apiUser := & APIUser {
252- Owner : "groups/test-group-123 " ,
245+ Owner : "groups/01ARZ3NDEKTSV4RRFFQ69G5FAV " ,
253246 DisplayName : "Test API User" ,
254247 }
255248
0 commit comments