Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kumaradityaraj
Copy link
Contributor

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:

  • Navigate to serverless-logic-web-tools package
  • Execute the command pnpm start
  • Click on this link to set your data index url and validate it Runtime tools settings page

Preview:

Screen.Recording.2024-09-20.at.4.21.45.PM.mov

@kumaradityaraj
Copy link
Contributor Author

@fantonangeli Please review this PR. Thank you.

Copy link
Contributor

@fantonangeli fantonangeli left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [isDataIndexUrlValidated, setDataIndexUrlValidated] = useState(DataIndexValidation.INVALID);
const [isDataIndexUrlValidated, setDataIndexUrlValidated] = useState(DataIndexValidation.INITIAL);


const PAGE_TITLE = "Runtime Tools";

enum DataIndexValidation {
Copy link
Contributor

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

Suggested change
enum DataIndexValidation {
enum FormValiationOptions {

@@ -71,6 +71,7 @@ interface AppDictionary extends ReferenceDictionary {
validationError: string;
connectionError: string;
configExpiredWarning: string;
validDataIndexURLError: string;
Copy link
Contributor

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

Comment on lines +24 to +25
["http://example.com/", true],
["https://example.com/", true],
Copy link
Contributor

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.

Suggested change
["http://example.com/", true],
["https://example.com/", true],
["http://example.com", true],
["http://example.com/", true],
["https://example.com/", true],
["ftps://example.com/", false],

Comment on lines +32 to +33
new URL(url);
return true;
Copy link
Contributor

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

Suggested change
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) => {
Copy link
Contributor

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.

Suggested change
])("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 {
Copy link
Contributor

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.

Suggested change
export function validDataIndexUrl(url: string): boolean {
export function isDataIndexUrlValid(url: string): boolean {


import { validDataIndexUrl } from "../../src/url";

describe("removeTrailingSlash", () => {
Copy link
Contributor

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;
}

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serverless Logic Web Tools: Runtime Tools settings doesn't validate the data index url
2 participants