-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kie-issues#2466: Serverless Logic Web Tools: Runtime Tools settings doesn't validate the data index url. #2608
base: main
Are you sure you want to change the base?
Conversation
@fantonangeli Please review this PR. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @kumaradityaraj for your prompt PR.
const settings = useSettings(); | ||
const settingsDispatch = useSettingsDispatch(); | ||
const [config, setConfig] = useState(settings.runtimeTools.config); | ||
const [isModalOpen, setIsModalOpen] = useState(false); | ||
const [isDataIndexUrlValidated, setDataIndexUrlValidated] = useState(DataIndexValidation.INVALID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [isDataIndexUrlValidated, setDataIndexUrlValidated] = useState(DataIndexValidation.INVALID); | |
const [isDataIndexUrlValidated, setDataIndexUrlValidated] = useState(DataIndexValidation.INITIAL); |
|
||
const PAGE_TITLE = "Runtime Tools"; | ||
|
||
enum DataIndexValidation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XXS suggestion. On some pages we call this FormValiationOptions
, we can make this name consistent with those pages:
packages/serverless-logic-web-tools/src/settings/openshift/OpenShiftSettingsSimpleConfig.tsx
packages/online-editor/src/accounts/kubernetes/ConnectToKubernetesSimple.tsx
packages/online-editor/src/accounts/openshift/ConnecToOpenShiftSimple.tsx
enum DataIndexValidation { | |
enum FormValiationOptions { |
@@ -71,6 +71,7 @@ interface AppDictionary extends ReferenceDictionary { | |||
validationError: string; | |||
connectionError: string; | |||
configExpiredWarning: string; | |||
validDataIndexURLError: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking care of the translations.
This section is related to the OpenShift settings page.
I suggest creating a section for RuntimeToolsSettings page to store this property.
ie: RuntimeToolsSettings.configModal.validDataIndexURLError
["http://example.com/", true], | ||
["https://example.com/", true], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ensure we accept only http/https protocol.
["http://example.com/", true], | |
["https://example.com/", true], | |
["http://example.com", true], | |
["http://example.com/", true], | |
["https://example.com/", true], | |
["ftps://example.com/", false], |
new URL(url); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a bug here, we are accepting every protocol in this function.
@tiagobento it's out of scope, but do you think we should also reproduce this suggestion here?
https://github.com/kumaradityaraj/kie-tools/blob/fc27f22fa01303a39132ae27494b43a41bc7101f/packages/kubernetes-bridge/src/service/KubernetesConnection.ts#L51
new URL(url); | |
return true; | |
const parsedUrl = new URL(url); | |
return parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:"; |
["https://example.com/", true], | ||
["loremIpsum", false], | ||
["google.com", false], | ||
])("should validate the data index URL", (inputUrl, isValidUrl) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's improve the log messages.
])("should validate the data index URL", (inputUrl, isValidUrl) => { | |
])("the data index URL %s validation should be %s", (inputUrl, isValidUrl) => { |
@@ -26,3 +26,12 @@ | |||
export function removeTrailingSlashFromUrl(url: string): string { | |||
return url.replace(/\/$/, ""); | |||
} | |||
|
|||
export function validDataIndexUrl(url: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make this name consistent with the other kie-tools validation functions.
export function validDataIndexUrl(url: string): boolean { | |
export function isDataIndexUrlValid(url: string): boolean { |
|
||
import { validDataIndexUrl } from "../../src/url"; | ||
|
||
describe("removeTrailingSlash", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover?
setDataIndexUrlValidated(DataIndexValidation.INVALID); | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After checking if it's valid it would be great to really test the url answers to a simple query.
You can use:
export async function verifyDataIndex(dataIndexUrl?: string): Promise<boolean> { |
Maybe we can move
verifyDataIndex()
inside the package runtime-tools-swf-gateway-api
to avoid code duplication.
Closes apache/incubator/kie-issues#2466
Description:
The data index url is now validated and if its invalid an alert is shown.
How to test:
serverless-logic-web-tools
packagepnpm start
Preview:
Screen.Recording.2024-09-20.at.4.21.45.PM.mov