Skip to content

Commit f123eb1

Browse files
adding validation to Proxy URL to ensure the user entered a protocol (#223)
1 parent ae1e4c8 commit f123eb1

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

electron/app/locales/en/webui.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,8 @@
14361436
"validation-helper-ingress-path-message-detail": "The path expression must start with / and not having any white space in it",
14371437
"validation-helper-ingress-annotation-hint": "Enter a valid annotation name value pair",
14381438
"validation-helper-ingress-annotation-message-detail": "The annotation ({{annotation}}) must be a name value pair separate by colon",
1439+
"validation-helper-proxy-url-hint": "Enter a valid URL with a protocol specified",
1440+
"validation-helper-proxy-url-message-detail": "The proxy URL entered does not have a protocol specified.",
14391441

14401442
"validation-error-dialog-default-title": "Unknown action failed",
14411443

webui/src/js/utils/validation-helper.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
66
'use strict';
@@ -32,7 +32,9 @@ function(i18n, Validator, ojvalidationError, RegExpValidator, LengthValidator, N
3232
'(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:' +
3333
'(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])';
3434

35-
const ingressPathRegexText = '^\\/\\S*$';
35+
const ingressPathRegexText = '\\/\\S*';
36+
37+
const proxyUrlRegexText = '[a-zA-Z0-9]+:\\/\\/.+';
3638

3739
this.createValidatableObject = (flowName) => {
3840
class ValidatableObject {
@@ -140,6 +142,17 @@ function(i18n, Validator, ojvalidationError, RegExpValidator, LengthValidator, N
140142
];
141143
};
142144

145+
this.getProxyUrlValidators = (options) => {
146+
const regExpValidatorOptions = {
147+
pattern: proxyUrlRegexText,
148+
hint: getHintField(options, 'hint', i18n.t('validation-helper-proxy-url-hint')),
149+
messageSummary: getMessageSummary(options),
150+
messageDetail: getMessageDetail(options, 'messageDetail',
151+
i18n.t('validation-helper-proxy-url-message-detail'))
152+
};
153+
return [ new RegExpValidator(regExpValidatorOptions) ];
154+
};
155+
143156
this.getImageTagValidators = (options) => {
144157
const regExpValidatorOptions = {
145158
pattern: imageReferenceRegexText,

webui/src/js/viewModels/network-page.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
44
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
55
*/
6-
define(['accUtils', 'knockout', 'utils/i18n', 'models/wkt-project',
6+
define(['accUtils', 'knockout', 'utils/i18n', 'models/wkt-project', 'utils/validation-helper',
77
'ojs/ojinputtext', 'ojs/ojbutton', 'ojs/ojformlayout', 'ojs/ojinputnumber'],
8-
function(accUtils, ko, i18n, project) {
8+
function(accUtils, ko, i18n, project, validationHelper) {
99
function NetworkPageViewModel() {
1010

1111
this.connected = () => {
@@ -34,6 +34,7 @@ function(accUtils, ko, i18n, project) {
3434
return i18n.t(`user-settings-dialog-${labelId}`);
3535
};
3636

37+
this.getProxyUrlValidators = () => validationHelper.getProxyUrlValidators();
3738
this.proxyUrl = ko.observable();
3839
this.bypassProxyHosts = ko.observable();
3940
this.requestTimeoutSeconds = ko.observable(5);

webui/src/js/viewModels/user-settings-dialog.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
44
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
55
*/
66
'use strict';
77

8-
define(['accUtils', 'knockout', 'utils/observable-properties', 'utils/i18n', 'ojs/ojarraydataprovider', 'models/wkt-project',
9-
'utils/wkt-logger', 'ojs/ojknockout', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog', 'ojs/ojformlayout',
10-
'ojs/ojswitch', 'ojs/ojselectsingle', 'ojs/ojvalidationgroup', 'ojs/ojinputnumber'],
11-
function(accUtils, ko, utils, i18n, ArrayDataProvider, project, wktLogger) {
8+
define(['accUtils', 'knockout', 'utils/observable-properties', 'utils/i18n', 'ojs/ojarraydataprovider',
9+
'models/wkt-project', 'utils/validation-helper', 'utils/wkt-logger', 'ojs/ojknockout', 'ojs/ojinputtext',
10+
'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog', 'ojs/ojformlayout', 'ojs/ojswitch', 'ojs/ojselectsingle',
11+
'ojs/ojvalidationgroup', 'ojs/ojinputnumber'],
12+
function(accUtils, ko, utils, i18n, ArrayDataProvider, project, validationHelper, wktLogger) {
1213
function UserSettingsDialogModel(payload) {
1314

1415
this.connected = () => {
@@ -45,6 +46,7 @@ function(accUtils, ko, utils, i18n, ArrayDataProvider, project, wktLogger) {
4546
return payload.isDevMode;
4647
};
4748

49+
this.getProxyUrlValidators = () => validationHelper.getProxyUrlValidators();
4850
this.proxyUrl = ko.observable();
4951
this.bypassProxyHosts = ko.observable();
5052
this.consoleLogLevel = ko.observable(payload.defaults.level);

webui/src/js/views/network-page.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
Copyright (c) 2021, 2023, Oracle and/or its affiliates.
33
Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
44
-->
55
<div class="wkt-dialog-content" id="networkSettings">
@@ -11,6 +11,7 @@ <h6><oj-bind-text value="[[labelMapper('title')]]"></oj-bind-text></h6>
1111
<oj-form-layout max-columns="1" direction="row">
1212
<oj-input-text label-hint="[[settingsLabelMapper('https-proxy-url-label')]]"
1313
value="{{proxyUrl}}"
14+
validators="[[getProxyUrlValidators()]]"
1415
help.instruction="[[settingsLabelMapper('https-proxy-url-help')]]">
1516
</oj-input-text>
1617
<oj-input-text label-hint="[[settingsLabelMapper('bypass-proxy-hosts-label')]]"

webui/src/js/views/user-settings-dialog.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
Copyright (c) 2021, 2023, Oracle and/or its affiliates.
33
Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
44
-->
55
<oj-dialog id="userSettingsDialog" class="wkt-user-settings-dialog" initial-visibility="show">
@@ -12,6 +12,7 @@ <h6 class="wkt-subheading"><oj-bind-text value="[[labelMapper('proxy-section-tit
1212
<oj-form-layout max-columns="1" direction="row">
1313
<oj-input-text label-hint="[[labelMapper('https-proxy-url-label')]]"
1414
value="{{proxyUrl}}"
15+
validators="[[getProxyUrlValidators()]]"
1516
help.instruction="[[labelMapper('https-proxy-url-help')]]">
1617
</oj-input-text>
1718
<oj-input-text label-hint="[[labelMapper('bypass-proxy-hosts-label')]]"

0 commit comments

Comments
 (0)