From 4067231f2c6534cc5590cc852997546051e30cd9 Mon Sep 17 00:00:00 2001 From: fatih camgoz Date: Thu, 15 May 2025 14:31:38 -0400 Subject: [PATCH 1/7] Check if cloud host name starts with visualstudio.com on plugins/catalog-backend-module-azure/src/lib/azure.ts Signed-off-by: Camgoz, Fatih --- .../src/lib/azure.test.ts | 93 +++++++++++++++++++ .../src/lib/azure.ts | 3 +- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend-module-azure/src/lib/azure.test.ts b/plugins/catalog-backend-module-azure/src/lib/azure.test.ts index 4839b625d2..f033a85113 100644 --- a/plugins/catalog-backend-module-azure/src/lib/azure.test.ts +++ b/plugins/catalog-backend-module-azure/src/lib/azure.test.ts @@ -392,4 +392,97 @@ describe('azure', () => { ), ).resolves.toHaveLength(totalCount); }); + + it('can search using visualstudio.com domain', async () => { + const response: CodeSearchResponse = { + count: 1, + results: [ + { + fileName: 'catalog-info.yaml', + path: '/catalog-info.yaml', + repository: { + name: 'backstage', + }, + project: { + name: '*', + }, + }, + ], + }; + + server.use( + rest.post( + `https://almsearch.dev.azure.com/shopify/_apis/search/codesearchresults`, + (req, res, ctx) => { + expect(req.headers.get('Authorization')).toBe('Basic OkFCQw=='); + expect(req.body).toEqual({ + searchText: 'path:/catalog-info.yaml repo:* proj:engineering', + $orderBy: [ + { + field: 'path', + sortOrder: 'ASC', + }, + ], + $skip: 0, + $top: 1000, + }); + return res(ctx.json(response)); + }, + ), + ); + + const { credentialsProvider, azureConfig } = createFixture( + 'backstage.visualstudio.com', + 'ABC', + ); + + await expect( + codeSearch( + credentialsProvider, + azureConfig, + 'shopify', + 'engineering', + '', + '/catalog-info.yaml', + '', + ), + ).resolves.toEqual(response.results); + }); + + it('identifies both dev.azure.com and visualstudio.com domains as cloud', async () => { + const domains = [ + { host: 'dev.azure.com', expectedCloud: true }, + { host: 'example.visualstudio.com', expectedCloud: true }, + { host: 'on-premise.company.com', expectedCloud: false }, + ]; + + for (const { host, expectedCloud } of domains) { + const mockResponse = { count: 0, results: [] }; + + const expectedBaseUrl = expectedCloud + ? 'https://almsearch.dev.azure.com' + : `https://${host}`; + + server.use( + rest.post( + `${expectedBaseUrl}/test-org/_apis/search/codesearchresults`, + (_req, res, ctx) => { + return res(ctx.json(mockResponse)); + }, + ), + ); + + const { credentialsProvider, azureConfig } = createFixture(host, 'TOKEN'); + + await codeSearch( + credentialsProvider, + azureConfig, + 'test-org', + 'test-project', + '', + '/test-path', + '', + ); + } + }); }); diff --git a/plugins/catalog-backend-module-azure/src/lib/azure.ts b/plugins/catalog-backend-module-azure/src/lib/azure.ts index 0b0d89c15b..daaf2b5678 100644 --- a/plugins/catalog-backend-module-azure/src/lib/azure.ts +++ b/plugins/catalog-backend-module-azure/src/lib/azure.ts @@ -46,7 +46,8 @@ interface CodeSearchRequest { }; } -const isCloud = (host: string) => host === 'dev.azure.com'; +const isCloud = (host: string) => + host === 'dev.azure.com' || host.endsWith('visualstudio.com'); const PAGE_SIZE = 1000; // codeSearch returns all files that matches the given search path. From be82d839d45fade67c500a3f9ac41bdcb67fc022 Mon Sep 17 00:00:00 2001 From: "Camgoz, Fatih" Date: Fri, 16 May 2025 12:46:15 -0400 Subject: [PATCH 2/7] added changeset file Signed-off-by: Camgoz, Fatih --- .changeset/wise-teeth-study.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/wise-teeth-study.md diff --git a/.changeset/wise-teeth-study.md b/.changeset/wise-teeth-study.md new file mode 100644 index 0000000000..a0ee07cc60 --- /dev/null +++ b/.changeset/wise-teeth-study.md @@ -0,0 +1,10 @@ +--- +'@backstage/plugin-catalog-backend-module-azure': minor +--- + +isCloud function now also checks if hostname endswith visualstudio.com along with dev.azure.com + +```diff +- const isCloud = (host: string) => host === 'dev.azure.com'; ++ const isCloud = (host: string) => host === 'dev.azure.com' || host.endsWith('visualstudio.com'); +``` From f8df253261105d5139b5961fc8ecdcb5670188e3 Mon Sep 17 00:00:00 2001 From: "Camgoz, Fatih" Date: Fri, 16 May 2025 13:39:50 -0400 Subject: [PATCH 3/7] Update isCloud method to resolve Incomplete URL substring sanitization error Signed-off-by: Camgoz, Fatih --- .changeset/wise-teeth-study.md | 16 +++++++++++++--- .../src/lib/azure.ts | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.changeset/wise-teeth-study.md b/.changeset/wise-teeth-study.md index a0ee07cc60..b7f32fbb02 100644 --- a/.changeset/wise-teeth-study.md +++ b/.changeset/wise-teeth-study.md @@ -2,9 +2,19 @@ '@backstage/plugin-catalog-backend-module-azure': minor --- -isCloud function now also checks if hostname endswith visualstudio.com along with dev.azure.com - +isCloud function now also checks if hostname is visualstudio.com or endswith visualstudio.com along with dev.azure.com +git s ```diff - const isCloud = (host: string) => host === 'dev.azure.com'; -+ const isCloud = (host: string) => host === 'dev.azure.com' || host.endsWith('visualstudio.com'); ++ const isCloud = (host: string) => { ++ if (host === 'dev.azure.com') { ++ return true; ++ } + ++ if (host === 'visualstudio.com' || host.endsWith('.visualstudio.com')) { ++ return true; ++ } + ++ return false; ++ }; ``` diff --git a/plugins/catalog-backend-module-azure/src/lib/azure.ts b/plugins/catalog-backend-module-azure/src/lib/azure.ts index daaf2b5678..5c68494f13 100644 --- a/plugins/catalog-backend-module-azure/src/lib/azure.ts +++ b/plugins/catalog-backend-module-azure/src/lib/azure.ts @@ -46,8 +46,18 @@ interface CodeSearchRequest { }; } -const isCloud = (host: string) => - host === 'dev.azure.com' || host.endsWith('visualstudio.com'); +const isCloud = (host: string) => { + if (host === 'dev.azure.com') { + return true; + } + + if (host === 'visualstudio.com' || host.endsWith('.visualstudio.com')) { + return true; + } + + return false; +}; + const PAGE_SIZE = 1000; // codeSearch returns all files that matches the given search path. From dade5de08bbe7d4c382619eb50823ef89267cbf9 Mon Sep 17 00:00:00 2001 From: "Camgoz, Fatih" Date: Fri, 16 May 2025 13:51:09 -0400 Subject: [PATCH 4/7] update changeset file Signed-off-by: Camgoz, Fatih --- .changeset/wise-teeth-study.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/wise-teeth-study.md b/.changeset/wise-teeth-study.md index b7f32fbb02..1745bdbcb8 100644 --- a/.changeset/wise-teeth-study.md +++ b/.changeset/wise-teeth-study.md @@ -3,7 +3,7 @@ --- isCloud function now also checks if hostname is visualstudio.com or endswith visualstudio.com along with dev.azure.com -git s + ```diff - const isCloud = (host: string) => host === 'dev.azure.com'; + const isCloud = (host: string) => { From 35e4afcc256b6b6dbf5a0426cf79ba440b76164a Mon Sep 17 00:00:00 2001 From: "Camgoz, Fatih" Date: Fri, 16 May 2025 14:30:08 -0400 Subject: [PATCH 5/7] update changeset file to resolve vale errors Signed-off-by: Camgoz, Fatih --- .changeset/wise-teeth-study.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.changeset/wise-teeth-study.md b/.changeset/wise-teeth-study.md index 1745bdbcb8..3db72c2d36 100644 --- a/.changeset/wise-teeth-study.md +++ b/.changeset/wise-teeth-study.md @@ -2,7 +2,7 @@ '@backstage/plugin-catalog-backend-module-azure': minor --- -isCloud function now also checks if hostname is visualstudio.com or endswith visualstudio.com along with dev.azure.com +The `isCloud` function now also checks if hostname is visualstudio.com or ends with .visualstudio.com along with dev.azure.com ```diff - const isCloud = (host: string) => host === 'dev.azure.com'; @@ -10,11 +10,11 @@ isCloud function now also checks if hostname is visualstudio.com or endswith vis + if (host === 'dev.azure.com') { + return true; + } - ++ + if (host === 'visualstudio.com' || host.endsWith('.visualstudio.com')) { + return true; + } - ++ + return false; + }; ``` From c0f43dc2ae9b7bdb2301d72f8c6942cfff8b430c Mon Sep 17 00:00:00 2001 From: "Camgoz, Fatih" Date: Fri, 16 May 2025 14:49:13 -0400 Subject: [PATCH 6/7] update azure.ts and changeset file Signed-off-by: Camgoz, Fatih --- .changeset/wise-teeth-study.md | 7 +++---- plugins/catalog-backend-module-azure/src/lib/azure.ts | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.changeset/wise-teeth-study.md b/.changeset/wise-teeth-study.md index 3db72c2d36..5e85fcf23e 100644 --- a/.changeset/wise-teeth-study.md +++ b/.changeset/wise-teeth-study.md @@ -1,17 +1,16 @@ --- -'@backstage/plugin-catalog-backend-module-azure': minor +'@backstage/plugin-catalog-backend-module-azure': patch --- -The `isCloud` function now also checks if hostname is visualstudio.com or ends with .visualstudio.com along with dev.azure.com +visualstudio.com domains are now supported along with dev.azure.com ```diff -- const isCloud = (host: string) => host === 'dev.azure.com'; + const isCloud = (host: string) => { + if (host === 'dev.azure.com') { + return true; + } + -+ if (host === 'visualstudio.com' || host.endsWith('.visualstudio.com')) { ++ if (host.endsWith('.visualstudio.com')) { + return true; + } + diff --git a/plugins/catalog-backend-module-azure/src/lib/azure.ts b/plugins/catalog-backend-module-azure/src/lib/azure.ts index 5c68494f13..7e9bf203ea 100644 --- a/plugins/catalog-backend-module-azure/src/lib/azure.ts +++ b/plugins/catalog-backend-module-azure/src/lib/azure.ts @@ -51,7 +51,7 @@ const isCloud = (host: string) => { return true; } - if (host === 'visualstudio.com' || host.endsWith('.visualstudio.com')) { + if (host.endsWith('.visualstudio.com')) { return true; } From 57eeb16233d47be63dc658e0f50d2211c2e3fa82 Mon Sep 17 00:00:00 2001 From: "Camgoz, Fatih" Date: Fri, 16 May 2025 14:51:49 -0400 Subject: [PATCH 7/7] update changeset file Signed-off-by: Camgoz, Fatih --- .changeset/wise-teeth-study.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.changeset/wise-teeth-study.md b/.changeset/wise-teeth-study.md index 5e85fcf23e..0695f98335 100644 --- a/.changeset/wise-teeth-study.md +++ b/.changeset/wise-teeth-study.md @@ -3,17 +3,3 @@ --- visualstudio.com domains are now supported along with dev.azure.com - -```diff -+ const isCloud = (host: string) => { -+ if (host === 'dev.azure.com') { -+ return true; -+ } -+ -+ if (host.endsWith('.visualstudio.com')) { -+ return true; -+ } -+ -+ return false; -+ }; -```