Explorar o código

Updated the HelpDeskConfigService so it returns both the list of optional as well as required verification methods, when instructed to do so. Also updated the VerificationsDialogController so it tells the HelpDeskConfigService to return optional verification methods when the dialog was launched from the details view.

jalbr74 %!s(int64=7) %!d(string=hai) anos
pai
achega
aeb0f165e9

+ 1 - 1
client/src/helpdesk/verifications-dialog.controller.ts

@@ -102,7 +102,7 @@ export default class VerificationsDialogController {
 
     private loadVerificationOptions() {
         this.configService
-            .getVerificationMethods()
+            .getVerificationMethods({includeOptional: this.isDetailsView})
             .then((methods) => {
                 this.status = STATUS_SELECT;
                 this.availableVerificationMethods = methods;

+ 57 - 0
client/src/services/helpdesk-config.service.test-data.ts

@@ -0,0 +1,57 @@
+/*
+ * Password Management Servlets (PWM)
+ * http://www.pwm-project.org
+ *
+ * Copyright (c) 2006-2009 Novell, Inc.
+ * Copyright (c) 2009-2018 The PWM Project
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* tslint:disable */
+
+export const helpdeskProcessAction_clientData = {
+    "error": false,
+    "errorCode": 0,
+    "data": {
+        "helpdesk_search_columns": {
+            "cn": "Username",
+            "givenName": "First Name",
+            "sn": "Last Name",
+            "mail": "Email",
+            "workforceID": "Workforce ID"
+        },
+        "helpdesk_setting_maskPasswords": false,
+        "helpdesk_setting_clearResponses": "ask",
+        "helpdesk_setting_PwUiMode": "autogen",
+        "helpdesk_setting_tokenSendMethod": "EMAILONLY",
+        "actions": {},
+        "verificationMethods": {
+            "optional": [
+                "TOKEN",
+                "OTP"
+            ],
+            "required": [
+                "ATTRIBUTES",
+                "OTP"
+            ]
+        },
+        "verificationForm": [
+            {
+                "name": "workforceID",
+                "label": "workforceID"
+            }
+        ]
+    }
+};

+ 97 - 0
client/src/services/helpdesk-config.service.test.ts

@@ -0,0 +1,97 @@
+/*
+ * Password Management Servlets (PWM)
+ * http://www.pwm-project.org
+ *
+ * Copyright (c) 2006-2009 Novell, Inc.
+ * Copyright (c) 2009-2018 The PWM Project
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+import {IHttpBackendService, IHttpService, ILogService, IQService, IWindowService, module} from 'angular';
+import ObjectService from './object.service';
+import {default as PwmService, IPwmService} from './pwm.service';
+import LocalStorageService from './local-storage.service';
+import HelpDeskConfigService, {IVerificationMap} from './helpdesk-config.service';
+
+import {helpdeskProcessAction_clientData} from './helpdesk-config.service.test-data';
+
+describe('In helpdesk-config.service.test.ts', () => {
+    beforeEach(() => {
+        module('app', []);
+    });
+
+    let localStorageService: LocalStorageService;
+    let objectService: ObjectService;
+    let pwmService: IPwmService;
+    let helpDeskConfigService: HelpDeskConfigService;
+    let $httpBackend: IHttpBackendService;
+
+    beforeEach(inject((
+        $http: IHttpService,
+        $log: ILogService,
+        $q: IQService,
+        $window: IWindowService,
+        _$httpBackend_: IHttpBackendService
+    ) => {
+        localStorageService = new LocalStorageService($log, $window);
+        objectService = new ObjectService();
+        pwmService = new PwmService($http, $log, $q, $window);
+        $httpBackend = _$httpBackend_;
+        helpDeskConfigService = new HelpDeskConfigService($http, $log, $q, pwmService as PwmService);
+    }));
+
+    it('getVerificationMethods returns only the required verification methods', (done: DoneFn) => {
+        $httpBackend.whenGET( '/context.html?processAction=clientData').respond(helpdeskProcessAction_clientData);
+
+        helpDeskConfigService.getVerificationMethods()
+            .then((verifications: IVerificationMap) => {
+                expect(verifications.length).toBe(2);
+
+                expect(verifications).toContain({name: 'ATTRIBUTES', label: 'Button_Attributes'});
+                expect(verifications).toContain({name: 'OTP', label: 'Button_OTP'});
+
+                done();
+            })
+            .catch((error: Error) => {
+                done.fail(error);
+            });
+
+        // This causes the $http service to finally resolve the response:
+        $httpBackend.flush();
+    });
+
+    // helpDeskConfigService should return both required and optional, because we passed in: {includeOptional: true}
+    it('getVerificationMethods returns both required and optional verification methods', (done: DoneFn) => {
+        $httpBackend.whenGET( '/context.html?processAction=clientData').respond(helpdeskProcessAction_clientData);
+
+        helpDeskConfigService.getVerificationMethods({includeOptional: true})
+            .then((verifications: IVerificationMap) => {
+                expect(verifications.length).toBe(3);
+
+                expect(verifications).toContain({name: 'ATTRIBUTES', label: 'Button_Attributes'});
+                expect(verifications).toContain({name: 'EMAIL', label: 'Button_Email'});
+                expect(verifications).toContain({name: 'OTP', label: 'Button_OTP'});
+
+                done();
+            })
+            .catch((error: Error) => {
+                done.fail(error);
+            });
+
+        // This causes the $http service to finally resolve the response:
+        $httpBackend.flush();
+    });
+});

+ 8 - 4
client/src/services/helpdesk-config.service.ts

@@ -76,7 +76,7 @@ export interface IHelpDeskConfigService extends IConfigService {
     getPasswordUiMode(): IPromise<string>;
     getTokenSendMethod(): IPromise<string>;
     getVerificationAttributes(): IPromise<IVerificationMap>;
-    getVerificationMethods(): IPromise<IVerificationMap>;
+    getVerificationMethods(options?: {includeOptional: boolean}): IPromise<IVerificationMap>;
     maskPasswordsEnabled(): IPromise<boolean>;
     verificationsEnabled(): IPromise<boolean>;
 }
@@ -115,18 +115,22 @@ export default class HelpDeskConfigService extends ConfigBaseService implements
         };
     }
 
-    getVerificationMethods(): IPromise<IVerificationMap> {
+    getVerificationMethods(options?: {includeOptional: boolean}): IPromise<IVerificationMap> {
         let promise = this.$q.all([
             this.getValue(VERIFICATION_METHODS_CONFIG),
             this.getTokenSendMethod()
         ]);
 
         return promise.then((result) => {
-            let methods: IVerificationResponse = result[0];
+            let availableMethods: string[] = result[0].required;
+            if (options && options.includeOptional) {
+                availableMethods = Array.from(new Set([].concat(result[0].required, result[0].optional)));
+            }
+
             let tokenSendMethod: string = result[1];
 
             let verificationMethods: IVerificationMap = [];
-            methods.required.forEach((method) => {
+            availableMethods.forEach((method) => {
                 if (method === TOKEN_VERIFICATION_METHOD) {
                     if (tokenSendMethod === TOKEN_EMAIL_ONLY || tokenSendMethod === TOKEN_CHOICE) {
                         verificationMethods.push(this.getVerificationMethod(VERIFICATION_METHOD_NAMES.EMAIL));

+ 2 - 1
client/test/karma-test-suite.ts

@@ -27,5 +27,6 @@ import 'angular-mocks';
 
 // This creates a single bundle with all test cases (*.test.ts), which improves performance
 // (i.e. we don't create a webpack bundle for each test):
-var appContext = (require as any).context('../src', true, /\.test\.ts/);
+// var appContext = (require as any).context('../src', true, /\.test\.ts/);
+var appContext = (require as any).context('../src', true, /helpdesk-config\.service\.test\.ts/);
 appContext.keys().forEach(appContext);