]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Fix bug when creating S3 keys 22468/head
authorVolker Theile <vtheile@suse.com>
Fri, 8 Jun 2018 11:44:45 +0000 (13:44 +0200)
committerVolker Theile <vtheile@suse.com>
Thu, 14 Jun 2018 08:52:47 +0000 (10:52 +0200)
Currently a new subuser is created if a key is created for the main user. That's because the uid is set as subuser parameter, too.
To fix that the key's user name, e.g. test2 or test1:subuser2, must be splitted into its user and subuser parts.

Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-user.service.ts

index 573a86d135c81103050dd8e1000e9c505c627384..59b3a2340198d94dbcc6d9daa92c4df2c514bc97 100644 (file)
@@ -9,6 +9,7 @@ import { Observable } from 'rxjs/Observable';
 
 import { RgwUserService } from '../../../shared/api/rgw-user.service';
 import { SharedModule } from '../../../shared/shared.module';
+import { RgwUserS3Key } from '../models/rgw-user-s3-key';
 import { RgwUserFormComponent } from './rgw-user-form.component';
 
 describe('RgwUserFormComponent', () => {
@@ -49,6 +50,51 @@ describe('RgwUserFormComponent', () => {
     expect(component).toBeTruthy();
   });
 
+  describe('s3 key management', () => {
+    let rgwUserService: RgwUserService;
+
+    beforeEach(() => {
+      rgwUserService = TestBed.get(RgwUserService);
+      spyOn(rgwUserService, 'addS3Key').and.stub();
+    });
+
+    it('should not update key', () => {
+      component.setS3Key(new RgwUserS3Key(), 3);
+      expect(component.s3Keys.length).toBe(0);
+      expect(rgwUserService.addS3Key).not.toHaveBeenCalled();
+    });
+
+    it('should set key', () => {
+      const key = new RgwUserS3Key();
+      key.user = 'test1:subuser2';
+      component.setS3Key(key);
+      expect(component.s3Keys.length).toBe(1);
+      expect(component.s3Keys[0].user).toBe('test1:subuser2');
+      expect(rgwUserService.addS3Key).toHaveBeenCalledWith(
+        'test1',
+        'subuser2',
+        undefined,
+        undefined,
+        undefined
+      );
+    });
+
+    it('should set key w/o subuser', () => {
+      const key = new RgwUserS3Key();
+      key.user = 'test1';
+      component.setS3Key(key);
+      expect(component.s3Keys.length).toBe(1);
+      expect(component.s3Keys[0].user).toBe('test1');
+      expect(rgwUserService.addS3Key).toHaveBeenCalledWith(
+        'test1',
+        '',
+        undefined,
+        undefined,
+        undefined
+      );
+    });
+  });
+
   describe('quotaMaxSizeValidator', () => {
     it('should validate max size (1/7)', () => {
       const resp = component.quotaMaxSizeValidator(new FormControl(''));
index 984906cf7f663cb9ac40c8ddd7e86eb6b5d8bee3..01282db41ef93daeafec0026ff327b1eb9442948 100644 (file)
@@ -442,9 +442,11 @@ export class RgwUserFormComponent implements OnInit, OnDestroy {
     if (_.isNumber(index)) { // Modify
       // Nothing to do here at the moment.
     } else { // Add
+      // Split the key's user name into its user and subuser parts.
+      const userMatches = key.user.match(/([^:]+)(:(.+))?/);
       // Create an observable to add the S3 key when the form is submitted.
       this.submitObservables.push(this.rgwUserService.addS3Key(
-        this.userForm.get('user_id').value, key.user, key.access_key,
+        userMatches[1], userMatches[2] ? userMatches[3] : '', key.access_key,
         key.secret_key, key.generate_key));
       // If the access and the secret key are auto-generated, then visualize
       // this to the user by displaying a notification instead of the key.
index 06766f991169d81ccaee2ad087294704c57c705b..3fa913067a75687f758b10cdba0cefb1529e3aff 100644 (file)
@@ -132,7 +132,9 @@ export class RgwUserService {
       params = params.append('access-key', accessKey);
       params = params.append('secret-key', secretKey);
     }
-    params = params.append('subuser', subuser);
+    if (!_.isEmpty(subuser)) {
+      params = params.append('subuser', subuser);
+    }
     return this.http.put(`${this.url}?key`, null, {params: params});
   }