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', () => {
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(''));
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.
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});
}