Skip to content

Commit 9f69ced

Browse files
authored
Merge pull request #3638 from snyk/chore/cliv2_add_kerberos_test
Chore/cliv2 add kerberos test
2 parents 2e5720c + 992d50c commit 9f69ced

File tree

1 file changed

+81
-5
lines changed

1 file changed

+81
-5
lines changed

cliv2/test/acceptance/proxy_authentication.spec.ts

+81-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { isCLIV2 } from '../../../test/jest/util/isCLIV2';
1313
import { unlink } from 'fs';
1414
import { execSync } from 'child_process';
15+
import * as os from 'os';
1516

1617
jest.setTimeout(1000 * 60);
1718

@@ -112,26 +113,36 @@ async function runCliWithProxy(
112113
): Promise<TestCLI> {
113114
let temp: string[] = [cmd, '--debug'];
114115
temp = temp.concat(args);
116+
117+
if (env['KRB5CCNAME'] == undefined) {
118+
env['KRB5CCNAME'] = 'FILE:' + path.join(scriptsPath, KRB5_CACHE_FILE);
119+
env['KRB5_CONFIG'] = path.join(scriptsPath, KRB5_CONFIG_FILE);
120+
}
121+
115122
const cli = await startSnykCLI(temp.join(' '), {
116123
env: {
117124
...env,
118125
SNYK_HTTP_PROTOCOL_UPGRADE: '0',
119-
KRB5CCNAME: 'FILE:' + path.join(scriptsPath, KRB5_CACHE_FILE),
120-
KRB5_CONFIG: path.join(scriptsPath, KRB5_CONFIG_FILE),
121126
},
122127
});
123128
return cli;
124129
}
125130

126-
describe('Proxy Authentication', () => {
131+
function canTestRun(): boolean {
127132
if (!isCLIV2() || !isDockerAvailable()) {
128133
// eslint-disable-next-line jest/no-focused-tests
129134
it.only('These tests are currently limited to certain environments.', () => {
130135
console.warn(
131136
'Skipping CLIv2 test. These tests are limited to environments that have docker and docker-compose installed.',
132137
);
133138
});
134-
} else {
139+
return false;
140+
}
141+
return true;
142+
}
143+
144+
describe('Proxy Authentication (all platforms)', () => {
145+
if (canTestRun()) {
135146
let server: FakeServer;
136147
let env: Record<string, string>;
137148
let project: TestProject;
@@ -180,7 +191,7 @@ describe('Proxy Authentication', () => {
180191
).toBeFalsy();
181192
});
182193

183-
it('successfully runs snyk test', async () => {
194+
it('successfully runs snyk test with proxy', async () => {
184195
const logOnEntry = await getProxyAccessLog();
185196

186197
// run snyk test
@@ -199,3 +210,68 @@ describe('Proxy Authentication', () => {
199210
});
200211
}
201212
});
213+
214+
describe('Proxy Authentication (Non-Windows)', () => {
215+
if (canTestRun() && !os.platform().includes('win32')) {
216+
let server: FakeServer;
217+
let env: Record<string, string>;
218+
let project: TestProject;
219+
220+
beforeAll(async () => {
221+
project = await createProjectFromWorkspace('npm-package');
222+
await startProxyEnvironment();
223+
224+
env = {
225+
...process.env,
226+
SNYK_API: SNYK_API,
227+
SNYK_TOKEN: '123456789',
228+
HTTP_PROXY: HTTP_PROXY,
229+
HTTPS_PROXY: HTTP_PROXY,
230+
};
231+
server = fakeServer(baseApi, env.SNYK_TOKEN);
232+
await server.listenPromise(port);
233+
});
234+
235+
afterEach(() => {
236+
server.restore();
237+
});
238+
239+
afterAll(async () => {
240+
await server.closePromise();
241+
await stopProxyEnvironment();
242+
unlink(path.join(scriptsPath, KRB5_CACHE_FILE), () => {});
243+
unlink(path.join(scriptsPath, KRB5_CONFIG_FILE), () => {});
244+
});
245+
246+
it('fail to run snyk test with proxy due to incorrect cache configuration', async () => {
247+
const logOnEntry = await getProxyAccessLog();
248+
249+
// run snyk test
250+
const args: string[] = [project.path()];
251+
env['KRB5CCNAME'] = 'MEMORY:' + path.join(scriptsPath, KRB5_CACHE_FILE); // specifying incorrect cache type memory
252+
env['KRB5_CONFIG'] = path.join(scriptsPath, KRB5_CONFIG_FILE);
253+
const cli = await runCliWithProxy(env, args);
254+
await expect(cli).toExitWith(2);
255+
256+
const logOnExit = await getProxyAccessLog();
257+
const additionalLogEntries = logOnExit.substring(logOnEntry.length);
258+
expect(additionalLogEntries.includes('TCP_DENIED/407')).toBeTruthy();
259+
});
260+
261+
it('fail to run snyk test with proxy due to incorrect config file', async () => {
262+
const logOnEntry = await getProxyAccessLog();
263+
264+
// run snyk test
265+
const args: string[] = [project.path()];
266+
env['KRB5CCNAME'] = 'FILE:' + path.join(scriptsPath, KRB5_CACHE_FILE);
267+
env['KRB5_CONFIG'] =
268+
path.join(scriptsPath, KRB5_CONFIG_FILE) + '_not_existing'; // specifying incorrect config location
269+
const cli = await runCliWithProxy(env, args);
270+
await expect(cli).toExitWith(2);
271+
272+
const logOnExit = await getProxyAccessLog();
273+
const additionalLogEntries = logOnExit.substring(logOnEntry.length);
274+
expect(additionalLogEntries.includes('TCP_DENIED/407')).toBeTruthy();
275+
});
276+
}
277+
});

0 commit comments

Comments
 (0)