Skip to content

Commit

Permalink
Merge pull request #260 from KxSystems/KXI-37861
Browse files Browse the repository at this point in the history
KXI-37861: Support longer strings for server config
  • Loading branch information
ecmel authored Mar 11, 2024
2 parents c05622c + 61eea8b commit 160537d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
18 changes: 10 additions & 8 deletions src/validators/kdbValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import { ext } from "../extensionVariables";
import { validateUtils } from "../utils/validateUtils";

export const MAX_STR_LEN = 2048;

export function validateServerAlias(
input: string | undefined,
isLocal: boolean,
Expand All @@ -26,8 +28,8 @@ export function validateServerAlias(
if (input[0] === " ") {
return "Input value cannot start with a space.";
}
if (!validateUtils.isValidLength(input, 1, 64)) {
return "Input value must be between 1 and 64 alphanumeric characters in length.";
if (!validateUtils.isValidLength(input, 1, MAX_STR_LEN)) {
return `Input value must be between 1 and ${MAX_STR_LEN} alphanumeric characters in length.`;
}
if (!validateUtils.isAlphanumericWithHypens(input)) {
return "Input value must contain only alphanumeric characters and hypens only";
Expand All @@ -48,8 +50,8 @@ export function validateServerName(
input: string | undefined,
): string | undefined {
if (input !== undefined) {
if (!validateUtils.isValidLength(input, 1, 64)) {
return "Input value must be between 1 and 64 alphanumeric characters in length.";
if (!validateUtils.isValidLength(input, 1, MAX_STR_LEN)) {
return `Input value must be between 1 and ${MAX_STR_LEN} alphanumeric characters in length.`;
}
}
return undefined;
Expand All @@ -74,8 +76,8 @@ export function validateServerUsername(
input: string | undefined,
): string | undefined {
if (input !== undefined && input !== "") {
if (!validateUtils.isValidLength(input, 1, 64)) {
return "Input value must be between 1 and 64 alphanumeric characters in length.";
if (!validateUtils.isValidLength(input, 1, MAX_STR_LEN)) {
return `Input value must be between 1 and ${MAX_STR_LEN} alphanumeric characters in length.`;
}
}
return undefined;
Expand All @@ -85,8 +87,8 @@ export function validateServerPassword(
input: string | undefined,
): string | undefined {
if (input !== undefined) {
if (!validateUtils.isValidLength(input, 1, 64)) {
return "Input value must be between 1 and 64 alphanumeric characters in length.";
if (!validateUtils.isValidLength(input, 1, MAX_STR_LEN)) {
return `Input value must be between 1 and ${MAX_STR_LEN} alphanumeric characters in length.`;
}
}
return undefined;
Expand Down
3 changes: 2 additions & 1 deletion test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { Connection } from "../../src/models/connection";
import { QueryHistory } from "../../src/models/queryHistory";
import { Server, ServerDetails, ServerType } from "../../src/models/server";
import { NewConnectionPannel } from "../../src/panels/newConnection";
import { MAX_STR_LEN } from "../../src/validators/kdbValidator";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const dsCmd = require("../../src/commands/dataSourceCommand");
Expand Down Expand Up @@ -1079,7 +1080,7 @@ describe("serverCommand", () => {
});

it("should return error when the servername with an invalid length", async () => {
kdbData.serverName = "a".repeat(256);
kdbData.serverName = "a".repeat(MAX_STR_LEN + 1);
await serverCommand.addKdbConnection(kdbData);
windowMock
.expects("showErrorMessage")
Expand Down
16 changes: 8 additions & 8 deletions test/suite/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ describe("kdbValidator", () => {

it("Should return fail for server alias that is outside the size limits", () => {
const result = kdbValidators.validateServerAlias(
"ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt",
"t".repeat(kdbValidators.MAX_STR_LEN + 1),
false,
);
assert.strictEqual(
result,
"Input value must be between 1 and 64 alphanumeric characters in length.",
`Input value must be between 1 and ${kdbValidators.MAX_STR_LEN} alphanumeric characters in length.`,
"Input was outside the size limits.",
);
});
Expand Down Expand Up @@ -134,11 +134,11 @@ describe("kdbValidator", () => {

it("Should return fail for server name that is outside the size limits", () => {
const result = kdbValidators.validateServerName(
"ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt",
"t".repeat(kdbValidators.MAX_STR_LEN + 1),
);
assert.strictEqual(
result,
"Input value must be between 1 and 64 alphanumeric characters in length.",
`Input value must be between 1 and ${kdbValidators.MAX_STR_LEN} alphanumeric characters in length.`,
"Input was outside the size limits.",
);
});
Expand Down Expand Up @@ -186,11 +186,11 @@ describe("kdbValidator", () => {

it("Should return fail for server username that is outside the size limits", () => {
const result = kdbValidators.validateServerUsername(
"ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt",
"t".repeat(kdbValidators.MAX_STR_LEN + 1),
);
assert.strictEqual(
result,
"Input value must be between 1 and 64 alphanumeric characters in length.",
`Input value must be between 1 and ${kdbValidators.MAX_STR_LEN} alphanumeric characters in length.`,
"Input was outside the size limits.",
);
});
Expand All @@ -206,11 +206,11 @@ describe("kdbValidator", () => {

it("Should return fail for server password that is outside the size limits", () => {
const result = kdbValidators.validateServerPassword(
"ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt",
"t".repeat(kdbValidators.MAX_STR_LEN + 1),
);
assert.strictEqual(
result,
"Input value must be between 1 and 64 alphanumeric characters in length.",
`Input value must be between 1 and ${kdbValidators.MAX_STR_LEN} alphanumeric characters in length.`,
"Input was outside the size limits.",
);
});
Expand Down

0 comments on commit 160537d

Please sign in to comment.