From 3f47e043762dcfa07f03065bf9fe88ff5ff5329b Mon Sep 17 00:00:00 2001 From: JSON Date: Mon, 4 Sep 2023 11:37:21 +0100 Subject: [PATCH] fix: HEAD-679 only check snykgov.io domain to check if fedramp (#373) --- CHANGELOG.md | 6 ++++++ .../common/configuration/configuration.ts | 7 +++---- src/test/integration/analytics.test.ts | 2 +- src/test/unit/common/analytics/itly.test.ts | 2 +- src/test/unit/common/configuration.test.ts | 20 +++++++++++++++++++ 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 218b4265e..f91212396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Snyk Security - Code and Open Source Dependencies Changelog +## [1.21.6] + +### Added + +- Only check `snykgov.io` domain to check if fedramp + ## [1.21.5] ### Added diff --git a/src/snyk/common/configuration/configuration.ts b/src/snyk/common/configuration/configuration.ts index 5942bc144..5a6646193 100644 --- a/src/snyk/common/configuration/configuration.ts +++ b/src/snyk/common/configuration/configuration.ts @@ -196,16 +196,15 @@ export class Configuration implements IConfiguration { get isFedramp(): boolean { if (!this.customEndpoint) return false; - // FEDRAMP URL e.g. https://api.fedramp.snykgov.io + // FEDRAMP URL e.g. https://api.feddramp.snykgov.io const endpoint = new URL(this.customEndpoint); // hostname validation const hostnameParts = endpoint.hostname.split('.'); if (hostnameParts.length < 3) return false; - const isFedrampInstance = hostnameParts[1].includes('fedramp'); - const isFedrampDomain = hostnameParts[2].includes('snykgov') && hostnameParts[3].includes('io'); - return isFedrampDomain && isFedrampInstance; + const isFedrampDomain = `${hostnameParts[2]}.${hostnameParts[3]}`.includes('snykgov.io'); + return isFedrampDomain; } get snykOssApiEndpoint(): string { diff --git a/src/test/integration/analytics.test.ts b/src/test/integration/analytics.test.ts index 1975e4834..8edadf5bf 100644 --- a/src/test/integration/analytics.test.ts +++ b/src/test/integration/analytics.test.ts @@ -36,7 +36,7 @@ suite('Analytics', () => { }); test('"Welcome Is Viewed" not tracked if using fedramp endpoint', async () => { - await configuration.setEndpoint('https://api.fedramp.snykgov.io'); + await configuration.setEndpoint('https://api.feddramp.snykgov.io'); await vscode.commands.executeCommand('workbench.action.toggleSidebarVisibility'); await vscode.commands.executeCommand(VSCODE_VIEW_CONTAINER_COMMAND); diff --git a/src/test/unit/common/analytics/itly.test.ts b/src/test/unit/common/analytics/itly.test.ts index d49379162..02a6c5858 100644 --- a/src/test/unit/common/analytics/itly.test.ts +++ b/src/test/unit/common/analytics/itly.test.ts @@ -4,7 +4,7 @@ import { SnykConfiguration } from '../../../../snyk/common/configuration/snykCon import { User } from '../../../../snyk/common/user'; import { LoggerMock } from '../../mocks/logger.mock'; -suite.only('Iteratively', () => { +suite('Iteratively', () => { const snykConfig = {} as SnykConfiguration; const isDevelopment = false; diff --git a/src/test/unit/common/configuration.test.ts b/src/test/unit/common/configuration.test.ts index 456b5fb6f..05960ffff 100644 --- a/src/test/unit/common/configuration.test.ts +++ b/src/test/unit/common/configuration.test.ts @@ -211,4 +211,24 @@ suite('Configuration', () => { strictEqual(configuration.scanningMode, mode); }); }); + + suite('.isFedramp()', () => { + test('returns true for FEDRAMP URLs', () => { + const fedrampUrl = 'https://api.fedramp.snykgov.io'; + const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, fedrampUrl); + + const configuration = new Configuration({}, workspace); + + strictEqual(configuration.isFedramp, true); + }); + + test('returns false for non-FEDRAMP URLs', () => { + const nonFedrampUrl = 'https://api.snyk.io'; + const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, nonFedrampUrl); + + const configuration = new Configuration({}, workspace); + + strictEqual(configuration.isFedramp, false); + }); + }); });