Skip to content

Commit 6ee2f8b

Browse files
committed
Removed redundant functions
1 parent cdcc091 commit 6ee2f8b

File tree

1 file changed

+0
-180
lines changed

1 file changed

+0
-180
lines changed

src/features/signatureValidator.controller.js

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import KJUR from 'jsrsasign';
2-
import randomBytes from 'randombytes';
32
import isEmpty from 'lodash/isEmpty';
43

54
import Signature from './Signature';
@@ -19,15 +18,12 @@ function signatureValidatorController($scope, Notification, testRequestService,
1918
controller.addSignature = addSignature;
2019
controller.addUrlencodedBody = addUrlencodedBody;
2120
controller.allBaseStringsFormed = allBaseStringsFormed;
22-
controller.authPrefix = authPrefix;
2321
controller.canSendTestRequest = canSendTestRequest;
2422
controller.compareBaseString = compareBaseString;
25-
controller.changeAuthLevel = changeAuthLevel;
2623
controller.changeRequestBodyType = changeRequestBodyType;
2724
controller.generateAuthHeader = generateAuthHeader;
2825
controller.getApiTestHeaders = getApiTestHeaders;
2926
controller.getApiTestResponseClass = getApiTestResponseClass;
30-
controller.isEmpty = isEmpty;
3127
controller.formSignatureUrls = formSignatureUrls;
3228
controller.onAllowCustomSignatureUrlChange = onAllowCustomSignatureUrlChange;
3329
controller.onApiUrlChange = onApiUrlChange;
@@ -37,15 +33,8 @@ function signatureValidatorController($scope, Notification, testRequestService,
3733
controller.removeSignature = removeSignature;
3834
controller.removeUrlencodedBody = removeUrlencodedBody;
3935
controller.sendTestRequest = sendTestRequest;
40-
controller.signatureMethod = signatureMethod;
41-
controller.signatureGenerated = signatureGenerated;
4236
controller.showOptions = showOptions;
4337

44-
$scope.formSignature = formSignature; // Main signature generation function
45-
$scope.nonceGenChange = nonceGenChange;
46-
$scope.timestampGenChange = timestampGenChange;
47-
$scope.parseInputFile = parseInputFile;
48-
4938
function init() {
5039
controller.sendingTestRequest = false;
5140
controller.authHeader = '';
@@ -185,52 +174,13 @@ function signatureValidatorController($scope, Notification, testRequestService,
185174
}));
186175
}
187176

188-
function signatureMethod() {
189-
switch (controller.selectedLevel) {
190-
case 0:
191-
return '';
192-
case 1:
193-
return config.main.sigMethod.level1;
194-
case 2:
195-
return config.main.sigMethod.level2;
196-
}
197-
}
198-
199-
function changeAuthLevel(level) {
200-
controller.selectedLevel = level;
201-
controller.apiTest = null;
202-
formSignature();
203-
}
204-
205177
function changeRequestBodyType() {
206178
if (controller.requestBodyType === 'application/x-www-form-urlencoded' &&
207179
controller.requestBody.urlencoded.length === 0) {
208180
addUrlencodedBody('', '');
209181
}
210182
}
211183

212-
function authPrefix() {
213-
if (controller.gatewayZone === config.constants.gatewayZones.internet) {
214-
switch (controller.selectedLevel) {
215-
case 1:
216-
return 'apex_l1_eg';
217-
case 2:
218-
return 'apex_l2_eg';
219-
default:
220-
return '';
221-
}
222-
} else if (controller.gatewayZone === config.constants.gatewayZones.intranet) {
223-
switch (controller.selectedLevel) {
224-
case 1:
225-
return 'apex_l1_ig';
226-
case 2:
227-
return 'apex_l2_ig';
228-
default:
229-
return '';
230-
}
231-
}
232-
}
233-
234184
function addUrlencodedBody(key, value) {
235185
controller.requestBody.urlencoded.push({
236186
key: key,
@@ -246,22 +196,6 @@ function signatureValidatorController($scope, Notification, testRequestService,
246196
return condition;
247197
}
248198

249-
/**
250-
* Automatically generates signature URL if the API is at api.gov.sg. Only runs when custom signature is unchecked.
251-
* @returns {string} Signature URL, with .e or .i optionally injected depending on the API domain and gateway zone.
252-
*/
253-
// function formSignatureUrl() {
254-
// if (controller.apiUrl === '' || !controller.apiUrl) return '';
255-
256-
// let apexDomain = controller.apiUrl.indexOf('.api.gov.sg');
257-
// if (apexDomain !== -1) {
258-
// let right = controller.apiUrl.substring(apexDomain);
259-
// let left = controller.apiUrl.substring(0, apexDomain);
260-
// let domainIdentifier = controller.gatewayZone === config.constants.gatewayZones.internet ? 'e' : 'i';
261-
// return `${left}.${domainIdentifier}${right}`;
262-
// } else { return controller.apiUrl; }
263-
// }
264-
265199
/**
266200
* Removes signature at given position
267201
* @param {number} index Index for signature in controller.signatures.
@@ -272,94 +206,6 @@ function signatureValidatorController($scope, Notification, testRequestService,
272206

273207
function removeUrlencodedBody(index) {
274208
controller.requestBody.urlencoded.splice(index, 1);
275-
formSignature();
276-
}
277-
278-
function formSignature() {
279-
if (controller.selectedLevel === 0) return;
280-
controller.showBasestringComparison = false;
281-
let valid = validateForm(controller.selectedLevel);
282-
if (valid) {
283-
let basestringOptions = {
284-
signatureUrl: controller.signatureUrl,
285-
authPrefix: authPrefix(),
286-
signatureMethod: signatureMethod(),
287-
appId: controller.appId,
288-
httpMethod: controller.httpMethod,
289-
appVersion: config.main.appVersion,
290-
// Optional parameters
291-
nonce: controller.nonce === 'auto-generated' ? randomBytes(32).toString('base64') : controller.nonce,
292-
timestamp: controller.timestamp === 'auto-generated' ? (new Date).getTime() : controller.timestamp,
293-
queryString: controller.queryString
294-
};
295-
// Process x-www-form-urlencoded body
296-
if (controller.httpMethod !== 'GET' &&
297-
controller.requestBodyType === 'application/x-www-form-urlencoded' &&
298-
controller.requestBody.urlencoded.length > 0) {
299-
basestringOptions.formData = controller.requestBody.urlencoded.reduce((finalObject, currentObject) => {
300-
if (currentObject.key && currentObject.value) { // false if any of them are empty strings
301-
finalObject[currentObject.key] = currentObject.value;
302-
}
303-
return finalObject;
304-
}, {});
305-
}
306-
307-
controller.basestring = testRequestService.generateBasestring(basestringOptions);
308-
309-
// 2. Signature generation
310-
let key;
311-
$scope.privateKeyError = false;
312-
if (controller.selectedLevel === 1) {
313-
key = controller.appSecret;
314-
} else if (controller.selectedLevel === 2) {
315-
try {
316-
key = KJUR.KEYUTIL.getKey(controller.pem, controller.pkeySecret);
317-
} catch (exception) {
318-
$scope.privateKeyError = true;
319-
controller.basestring = '';
320-
controller.authHeader = '';
321-
Notification.error({
322-
title: '',
323-
message: config.main.errorMessages.pkeyInvalid,
324-
delay: config.notificationShowTime
325-
});
326-
}
327-
}
328-
let signature = testRequestService.signBasestring(controller.selectedLevel, controller.basestring, key);
329-
let authHeader = testRequestService.genAuthHeader(basestringOptions, signature);
330-
controller.authHeader = authHeader;
331-
} else if (signatureGenerated()) {
332-
controller.basestring = '';
333-
controller.authHeader = '';
334-
}
335-
}
336-
337-
/**
338-
* Checks whether all necessary inputs are present
339-
* @param {number} level Apex auth level
340-
* @returns {boolean} true if form is valid, false otherwise
341-
*/
342-
function validateForm(level) {
343-
switch (level) {
344-
case 0:
345-
return controller.apiUrl && controller.apiUrl.length > 0;
346-
case 1:
347-
return controller.apiUrl && controller.apiUrl.length > 0 &&
348-
controller.appId && controller.appId.length > 0 &&
349-
controller.appSecret && controller.appSecret.length > 0 &&
350-
controller.nonce && controller.nonce.length > 0 &&
351-
controller.timestamp && controller.timestamp.length > 0;
352-
case 2:
353-
return controller.apiUrl && controller.apiUrl.length > 0 &&
354-
controller.appId && controller.appId.length > 0 &&
355-
controller.pem && controller.pem.length > 0 &&
356-
controller.nonce && controller.nonce.length > 0 &&
357-
controller.timestamp && controller.timestamp.length > 0;
358-
}
359-
}
360-
361-
function signatureGenerated() {
362-
return controller.basestring && controller.basestring.length > 0 && controller.authHeader && controller.authHeader.length > 0;
363209
}
364210

365211
function compareBaseString(signature, generated, input) {
@@ -446,36 +292,10 @@ function signatureValidatorController($scope, Notification, testRequestService,
446292
}
447293
})
448294
.finally(() => {
449-
formSignature();
450295
controller.sendingTestRequest = false;
451296
});
452297
}
453298

454-
function nonceGenChange() {
455-
$scope.nonceDisabled = !$scope.nonceDisabled;
456-
if ($scope.nonceDisabled) {
457-
controller.nonce = 'auto-generated';
458-
} else {
459-
controller.nonce = '';
460-
}
461-
formSignature();
462-
}
463-
464-
function timestampGenChange() {
465-
$scope.timestampDisabled = !$scope.timestampDisabled;
466-
if ($scope.timestampDisabled) {
467-
controller.timestamp = 'auto-generated';
468-
} else {
469-
controller.timestamp = '';
470-
}
471-
formSignature();
472-
}
473-
474-
function parseInputFile(fileText) {
475-
controller.pem = fileText;
476-
formSignature();
477-
}
478-
479299
function showOptions() {
480300
$uibModal.open({
481301
animation: true,

0 commit comments

Comments
 (0)