Skip to content

Commit 0f4d9df

Browse files
committed
fix(runValidation): Throw error if manifest path is not absolute
1 parent 4c87335 commit 0f4d9df

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/tools/run_manifest_validation/runValidation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {InvalidInputError} from "../../utils.js";
77
import {getManifestSchema} from "../../utils/ui5Manifest.js";
88
import {Mutex} from "async-mutex";
99
import {fileURLToPath} from "url";
10+
import {isAbsolute} from "path";
1011

1112
const log = getLogger("tools:run_manifest_validation:runValidation");
1213
const schemaCache = new Map<string, AnySchemaObject>();
@@ -80,6 +81,10 @@ async function readManifest(path: string) {
8081
let content: string;
8182
let json: object;
8283

84+
if (!isAbsolute(path)) {
85+
throw new InvalidInputError(`The manifest path must be absolute: '${path}'`);
86+
}
87+
8388
try {
8489
content = await readFile(path, "utf-8");
8590
} catch (error) {

src/tools/run_manifest_validation/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {z} from "zod";
22

33
export const inputSchema = {
44
manifestPath: z.string()
5-
.describe("Path to the manifest file to validate."),
5+
.describe("Absolute path to the manifest file to validate."),
66
};
77

88
export const outputSchema = {

test/lib/tools/run_manifest_validation/runValidation.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import anyTest, {TestFn} from "ava";
22
import * as sinon from "sinon";
33
import esmock from "esmock";
44
import {readFile} from "fs/promises";
5+
import {InvalidInputError} from "../../../../src/utils.js";
56

67
const test = anyTest as TestFn<{
78
sinon: sinon.SinonSandbox;
@@ -136,17 +137,27 @@ test("runValidation successfully validates invalid manifest", async (t) => {
136137
});
137138
});
138139

140+
test("runValidation throws error when manifest file path is not absolute", async (t) => {
141+
const {runValidation} = t.context;
142+
143+
await t.throwsAsync(async () => {
144+
return await runValidation("relativeManifest.json");
145+
}, {
146+
instanceOf: InvalidInputError,
147+
message: "The manifest path must be absolute: 'relativeManifest.json'",
148+
});
149+
});
150+
139151
test("runValidation throws error when manifest file path is not correct", async (t) => {
140152
const {runValidation, readFileStub} = t.context;
141153

142154
// Stub the readFile function to throw an error
143155
readFileStub.rejects(new Error("File not found"));
144156

145157
await t.throwsAsync(async () => {
146-
const result = await runValidation("/nonexistent/path");
147-
return result;
158+
return await runValidation("/nonexistent/path");
148159
}, {
149-
instanceOf: Error,
160+
instanceOf: InvalidInputError,
150161
message: /Failed to read manifest file at .+: .+/,
151162
});
152163
});
@@ -157,10 +168,9 @@ test("runValidation throws error when manifest file content is invalid JSON", as
157168
t.context.manifestFileContent = "Invalid JSON Content";
158169

159170
await t.throwsAsync(async () => {
160-
const result = await runValidation("/path/to/manifest.json");
161-
return result;
171+
return await runValidation("/path/to/manifest.json");
162172
}, {
163-
instanceOf: Error,
173+
instanceOf: InvalidInputError,
164174
message: /Failed to parse manifest file at .+ as JSON: .+/,
165175
});
166176
});
@@ -172,8 +182,7 @@ test("runValidation throws error when schema validation function cannot be compi
172182
getManifestSchemaStub.resolves(null); // Simulate invalid schema
173183

174184
await t.throwsAsync(async () => {
175-
const result = await runValidation("/path/to/manifest.json");
176-
return result;
185+
return await runValidation("/path/to/manifest.json");
177186
}, {
178187
instanceOf: Error,
179188
message: /Failed to create UI5 manifest validate function: .+/,
@@ -247,8 +256,7 @@ test("runValidation throws error when external schema cannot be fetched", async
247256
.rejects(new Error("Failed to fetch external schema"));
248257

249258
await t.throwsAsync(async () => {
250-
const result = await runValidation("/path/to/manifest.json");
251-
return result;
259+
return await runValidation("/path/to/manifest.json");
252260
}, {
253261
instanceOf: Error,
254262
message: /Failed to create UI5 manifest validate function: .+/,

0 commit comments

Comments
 (0)