Skip to content

Commit

Permalink
fix: HEAD-679 only check snykgov.io domain to check if fedramp (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-luong authored Sep 4, 2023
1 parent 5fa297c commit 3f47e04
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/common/analytics/itly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 20 additions & 0 deletions src/test/unit/common/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 3f47e04

Please sign in to comment.