Skip to content

Commit

Permalink
test: fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed Jun 4, 2024
1 parent 2c3d742 commit d0abf1e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
10 changes: 0 additions & 10 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,6 @@ export class Configuration implements IConfiguration {

get snykCodeUrl(): string {
const authUrl = new URL(this.authHost);
<<<<<<< HEAD

if (Configuration.isSingleTenant(authUrl)) {
authUrl.pathname = authUrl.pathname.replace('api', '');
} else {
authUrl.host = `app.${authUrl.host}`;
}

=======
>>>>>>> 8683425 (f)
return `${authUrl.toString()}manage/snyk-code?from=vscode`;
}

Expand Down
26 changes: 20 additions & 6 deletions src/test/integration/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
import { deepStrictEqual, strictEqual } from 'assert';
import { FeaturesConfiguration } from '../../snyk/common/configuration/configuration';
import { configuration } from '../../snyk/common/configuration/instance';
import vscode from 'vscode';
import { ADVANCED_CUSTOM_ENDPOINT } from '../../snyk/common/constants/settings';
import SecretStorageAdapter from '../../snyk/common/vscode/secretStorage';
import { ExtensionContext } from '../../snyk/common/vscode/types';

suite('Configuration', () => {
test('configuration constants differ between DEV and PROD', () => {
process.env.SNYK_VSCE_DEVELOPMENT = '';
test('configuration constants differ between DEV and PROD', async () => {
await vscode.workspace.getConfiguration().update(ADVANCED_CUSTOM_ENDPOINT, '');
strictEqual(configuration.snykCodeBaseURL, 'https://deeproxy.snyk.io');
strictEqual(configuration.authHost, 'https://snyk.io');
strictEqual(configuration.snykCodeUrl, 'https://app.snyk.io/manage/snyk-code?from=vscode');
strictEqual(configuration.authHost, 'https://api.snyk.io');

process.env.SNYK_VSCE_DEVELOPMENT = '1';
await vscode.workspace.getConfiguration().update(ADVANCED_CUSTOM_ENDPOINT, 'https://api.snyk.io');
strictEqual(configuration.snykCodeBaseURL, 'https://deeproxy.snyk.io');
strictEqual(configuration.<<<snykCodeUrl, 'https://app.snyk.io/manage/snyk-code?from=vscode');
strictEqual(configuration.authHost, 'https://api.snyk.io');

await vscode.workspace.getConfiguration().update(ADVANCED_CUSTOM_ENDPOINT, 'https://api.dev.snyk.io');
strictEqual(configuration.snykCodeBaseURL, 'https://deeproxy.dev.snyk.io');
strictEqual(configuration.authHost, 'https://dev.snyk.io');
strictEqual(configuration.snykCodeUrl, 'https://app.dev.snyk.io/manage/snyk-code?from=vscode');
strictEqual(configuration.authHost, 'https://api.dev.snyk.io');
});

test('configuration change is reflected', async () => {
test.only('configuration change is reflected', async () => {
const token = 'fake-token';
const featuresConfig = {
ossEnabled: true,
codeSecurityEnabled: true,
codeQualityEnabled: false,
} as FeaturesConfiguration;

const ext = vscode.extensions.getExtension('snyk-security.snyk-vulnerability-scanner');
ext!.activate();

await configuration.setToken(token);
await configuration.setFeaturesConfiguration(featuresConfig);

Expand Down
10 changes: 5 additions & 5 deletions src/test/unit/common/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ suite('Configuration', () => {
});

test('Snyk Code: base url respects single tenant endpoint configuration', () => {
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, 'https://app.custom.snyk.io/api');
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, 'https://api.custom.snyk.io');
const configuration = new Configuration({}, workspace);

strictEqual(configuration.snykCodeBaseURL, 'https://deeproxy.custom.snyk.io');
});

test('Snyk Code: code url respects custom endpoint configuration', () => {
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, 'https://custom.endpoint.com/api');
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, 'https://custom.endpoint.com');
const configuration = new Configuration({}, workspace);

strictEqual(configuration.snykCodeUrl, 'https://app.custom.endpoint.com/manage/snyk-code?from=vscode');
});

test('Snyk Code: code url respects single tenant endpoint configuration', () => {
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, 'https://app.custom.snyk.io/api');
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, 'https://api.custom.snyk.io');
const configuration = new Configuration({}, workspace);

strictEqual(configuration.snykCodeUrl, 'https://app.custom.snyk.io/manage/snyk-code?from=vscode');
Expand Down Expand Up @@ -166,11 +166,11 @@ suite('Configuration', () => {

const configuration = new Configuration({}, workspace);

strictEqual(configuration.snykOssApiEndpoint, 'https://snyk.io/api/v1');
strictEqual(configuration.snykApiEndpoint, 'https://api.snyk.io/v1');
});

test('Snyk OSS: API endpoint returns custom endpoint when set', () => {
const customEndpoint = 'http://custom.endpoint.com/api';
const customEndpoint = 'http://custom.endpoint.com';
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, customEndpoint);

const configuration = new Configuration({}, workspace);
Expand Down

0 comments on commit d0abf1e

Please sign in to comment.