From 32fd6af6b33c99dc981d2ff4f04e6f52e127844c Mon Sep 17 00:00:00 2001 From: Naman Munet Date: Fri, 16 May 2025 13:59:04 +0530 Subject: [PATCH] mgr/dashboard: accept dot(.) in user_id & (alphanumeric chars, _) in tenant in user form fixes: https://tracker.ceph.com/issues/71341 Signed-off-by: Naman Munet (cherry picked from commit 083d2a14f5da9df9c9142940f151636c466623ae) --- .../rgw-user-form.component.spec.ts | 25 +++++++++++++++++++ .../rgw-user-form/rgw-user-form.component.ts | 4 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts index a00d08ad75e1f..4c9707cad8508 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts @@ -167,6 +167,13 @@ describe('RgwUserFormComponent', () => { formHelper.expectValid('user_id'); })); + it('should validate that username can contain dot(.)', fakeAsync(() => { + spyOn(rgwUserService, 'get').and.returnValue(throwError('foo')); + formHelper.setValue('user_id', 'user.name', true); + tick(DUE_TIMER); + formHelper.expectValid('user_id'); + })); + it('should validate that username is invalid', fakeAsync(() => { spyOn(rgwUserService, 'get').and.returnValue(observableOf({})); formHelper.setValue('user_id', 'abc', true); @@ -175,6 +182,24 @@ describe('RgwUserFormComponent', () => { })); }); + describe('tenant validation', () => { + it('should validate that tenant is valid', fakeAsync(() => { + spyOn(rgwUserService, 'get').and.returnValue(throwError('foo')); + formHelper.setValue('show_tenant', true, true); + formHelper.setValue('tenant', 'new_tenant123', true); + tick(DUE_TIMER); + formHelper.expectValid('tenant'); + })); + + it('should validate that tenant is invalid', fakeAsync(() => { + spyOn(rgwUserService, 'get').and.returnValue(observableOf({})); + formHelper.setValue('show_tenant', true, true); + formHelper.setValue('tenant', 'new-tenant.dummy', true); + tick(DUE_TIMER); + formHelper.expectError('tenant', 'pattern'); + })); + }); + describe('max buckets', () => { it('disable creation (create)', () => { spyOn(rgwUserService, 'create'); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts index ec23ca0f7ba11..6a2804a549241 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts @@ -74,7 +74,7 @@ export class RgwUserFormComponent extends CdForm implements OnInit { // General user_id: [ null, - [Validators.required, Validators.pattern(/^[a-zA-Z0-9!@#%^&*()_-]+$/)], + [Validators.required, Validators.pattern(/^[a-zA-Z0-9!@#%^&*()._-]+$/)], this.editing ? [] : [ @@ -86,7 +86,7 @@ export class RgwUserFormComponent extends CdForm implements OnInit { show_tenant: [this.editing], tenant: [ null, - [Validators.pattern(/^[a-zA-Z0-9!@#%^&*()_-]+$/)], + [Validators.pattern(/^[a-zA-Z0-9_]+$/)], this.editing ? [] : [ -- 2.39.5