Skip to content

Commit 3e55d67

Browse files
committed
refactor: Use new UI5_MCP_SERVER_ALLOWED_DOMAINS variable
1 parent 52b7fba commit 3e55d67

3 files changed

Lines changed: 12 additions & 19 deletions

File tree

src/tools/create_integration_card/create_integration_card.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ejs from "ejs";
77
import {getLogger} from "@ui5/logger";
88
import {Destination, SupportedCardType} from "./schema.js";
99
import semver from "semver";
10-
import {getAllowedOdataV4Domains, isValidUrl} from "../../utils/URLHelper.js";
10+
import {getAllowedDomains, isValidUrl} from "../../utils/URLHelper.js";
1111

1212
const log = getLogger("tools:create_integration_card:create_integration_card");
1313
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -43,7 +43,7 @@ export async function createIntegrationCard({
4343
}
4444

4545
if (destinations?.length) {
46-
const allowedDomains = getAllowedOdataV4Domains();
46+
const allowedDomains = getAllowedDomains();
4747

4848
for (const destination of destinations) {
4949
if (!isValidUrl(destination.defaultUrl, allowedDomains)) {

src/utils/URLHelper.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ export function isValidUrl(
7171
return true;
7272
};
7373

74-
export function getAllowedOdataV4Domains() {
75-
if ("UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS" in process.env) {
76-
const inputDomainList = process.env.UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS;
74+
export function getAllowedDomains() {
75+
if ("UI5_MCP_SERVER_ALLOWED_DOMAINS" in process.env || "UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS" in process.env) {
76+
const inputDomainList = process.env.UI5_MCP_SERVER_ALLOWED_DOMAINS ??
77+
process.env.UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS;
7778
if (!inputDomainList?.trim()) {
7879
// Empty list allows all domains
79-
log.verbose("Empty value for UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS, allowing all domains");
80+
log.verbose("Empty value for UI5_MCP_SERVER_ALLOWED_DOMAINS, allowing all domains");
8081
return [];
8182
}
8283
// Use the environment variable if set
@@ -88,7 +89,7 @@ export function getAllowedOdataV4Domains() {
8889
new URL(`https://${domain}`);
8990
} catch (err) {
9091
throw new InvalidInputError(
91-
`Invalid domain '${domain}' in UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS: ` +
92+
`Invalid domain '${domain}' in UI5_MCP_SERVER_ALLOWED_DOMAINS: ` +
9293
(err instanceof Error ? err.message : String(err))
9394
);
9495
}

test/lib/tools/create_integration_card/create_integration_card.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import esmock from "esmock";
33
import sinonGlobal from "sinon";
44
import {InvalidInputError} from "../../../../src/utils.js";
55
import path from "node:path";
6-
import {isValidUrl as realIsValidUrl, getAllowedOdataV4Domains} from "../../../../src/utils/URLHelper.js";
6+
import {isValidUrl as realIsValidUrl, getAllowedDomains} from "../../../../src/utils/URLHelper.js";
77

88
// Define test context type
99
const test = anyTest as TestFn<{
@@ -93,7 +93,7 @@ test.beforeEach(async (t) => {
9393
},
9494
"../../../../src/utils/URLHelper.js": {
9595
isValidUrl: t.context.isValidUrlStub,
96-
getAllowedOdataV4Domains,
96+
getAllowedDomains,
9797
},
9898
}
9999
);
@@ -243,10 +243,9 @@ test.serial("Destinations: Throws error when there is not allowed domain", async
243243
defaultUrl: "https://invalid-domain.com/api/v1/",
244244
},
245245
];
246-
const currentAllowedDomains = process.env.UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS;
247246
const allowedDomains = ["allowed-domain.com"];
248247

249-
process.env.UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS = "allowed-domain.com";
248+
process.env.UI5_MCP_SERVER_ALLOWED_DOMAINS = "allowed-domain.com";
250249

251250
await t.throwsAsync(async () => {
252251
await createIntegrationCard({
@@ -270,9 +269,6 @@ test.serial("Destinations: Throws error when there is not allowed domain", async
270269
[destinations[0].defaultUrl, allowedDomains],
271270
"isValidUrl should be called with the destination URL and allowed domains"
272271
);
273-
274-
// Restore original allowed domains after test
275-
process.env.UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS = currentAllowedDomains;
276272
});
277273

278274
test.serial("Destinations: Successfully generates card template with allowed destination domain", async (t) => {
@@ -284,8 +280,7 @@ test.serial("Destinations: Successfully generates card template with allowed des
284280
defaultUrl: "https://allowed-domain.com/api/v1/",
285281
},
286282
];
287-
const currentAllowedDomains = process.env.UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS;
288-
process.env.UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS = "allowed-domain.com";
283+
process.env.UI5_MCP_SERVER_ALLOWED_DOMAINS = "allowed-domain.com";
289284

290285
await t.notThrowsAsync(async () => {
291286
await createIntegrationCard({
@@ -303,7 +298,4 @@ test.serial("Destinations: Successfully generates card template with allowed des
303298
[destinations[0].defaultUrl, ["allowed-domain.com"]],
304299
"isValidUrl should be called with the destination URL and allowed domains"
305300
);
306-
307-
// Restore original allowed domains after test
308-
process.env.UI5_MCP_SERVER_ALLOWED_ODATA_DOMAINS = currentAllowedDomains;
309301
});

0 commit comments

Comments
 (0)