From 7846b0805873931cf5d477a9232c36f018693fbe 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 a1d740e6a4841..efdf125ad9ecb 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 @@ -176,6 +176,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); @@ -184,6 +191,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', () => { beforeEach(() => { component.loading = LoadingStatus.Ready; 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 f0783324c2451..fc4f15d2c1e19 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 @@ -82,7 +82,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 ? [] : [ @@ -94,7 +94,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