Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: user journey tests for Go based snyk code test [CLI-225] #5172

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
def598e
test: adding code test native workflow acceptance test (WIP)
j-luong Apr 16, 2024
4fb77d3
test: user journey tests for Go based snyk code
j-luong Apr 17, 2024
035d083
test: split snyk code tests between user journey/integration tests
j-luong Apr 17, 2024
3be05d5
test: split user journey (e2e) out to separate file
thisislawatts May 2, 2024
a714c5e
test: split user journey (e2e) out to separate file
thisislawatts May 2, 2024
d60ebd5
test: experimental
thisislawatts May 6, 2024
9cb4948
test: run all tests
thisislawatts May 29, 2024
b1a20ed
chore(deps): remove unused nock
thisislawatts May 30, 2024
0f5707a
test: remove unused var
thisislawatts May 30, 2024
6e835cf
test: focus test cases for stability
thisislawatts May 30, 2024
76032ad
test: passing happy case
thisislawatts May 31, 2024
e3cd196
test: passing happy case
thisislawatts May 31, 2024
012e126
test: all tests are passing
thisislawatts May 31, 2024
12c6078
test: failure for empty project
thisislawatts May 31, 2024
848a50c
test: all tests are passing
thisislawatts May 31, 2024
059ffe1
test: add validation for local code engine behaviour
thisislawatts May 31, 2024
acc30b9
test: remove e2e spec
thisislawatts May 31, 2024
4735ef7
chore: remove local link
thisislawatts May 31, 2024
7a55dd3
test: relabel suite
thisislawatts May 31, 2024
9a06da0
test: introduce e2e verification of happy path
thisislawatts May 31, 2024
8531505
test: skip local engine tests until native workflow supports it
thisislawatts May 31, 2024
42069f9
test: add journey tests
mgyorke Jun 7, 2024
1a50320
test: fix analytics tests
mgyorke Jun 10, 2024
cc1946d
test: added empty file
mgyorke Jun 10, 2024
c07290c
fix: revert unintended changes
mgyorke Jun 10, 2024
7b725f7
fix: include empty folder for testing
mgyorke Jun 10, 2024
779f447
test: wip integration tests
mgyorke Jun 11, 2024
9d0cfbb
test(code): WIP clean-up code acceptance tests
j-luong Jun 11, 2024
e5937dc
test(code): WIP adding some golang/native snyk code tests
j-luong Jun 11, 2024
5f342e2
test: WIP fixes integration tests on native workflow
mgyorke Jun 14, 2024
018c0f4
test: skip lce on native and small code cleanup
mgyorke Jun 14, 2024
6c5233e
test: fixed warnings and remove unused code from dev
mgyorke Jun 14, 2024
08662f8
test: use environment variables for credentials and endpoint
mgyorke Jun 14, 2024
521dd24
test: remove dev debug logging
mgyorke Jun 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions test/acceptance/deepcode-fake-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const fakeDeepCodeServer = (): FakeDeepCodeServer => {
};

const popRequest = () => {
return requests.pop()!;
const request = requests?.pop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these small changes are pedantic and unrelated to the work but we get rid of a few linting warnings.

if (request) return request;
else throw new Error('No request found in requests array');
};

const popRequests = (num: number) => {
Expand Down Expand Up @@ -85,6 +87,7 @@ export const fakeDeepCodeServer = (): FakeDeepCodeServer => {
};

const app = express();

app.use((req, res, next) => {
requests.push(req);
next();
Expand Down Expand Up @@ -179,7 +182,7 @@ export const fakeDeepCodeServer = (): FakeDeepCodeServer => {
getRequests,
popRequest,
popRequests,
setCustomResponse: setCustomResponse,
setCustomResponse,
setFiltersResponse,
setSarifResponse,
setNextResponse,
Expand Down
97 changes: 95 additions & 2 deletions test/acceptance/fake-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export const fakeServer = (basePath: string, snykToken: string): FakeServer => {
};

const popRequest = () => {
return requests.pop()!;
const request = requests?.pop();
if (request) return request;
else throw new Error('No request found in requests array');
};

const popRequests = (num: number) => {
Expand Down Expand Up @@ -225,6 +227,89 @@ export const fakeServer = (basePath: string, snykToken: string): FakeServer => {
}
});

// needed for code-client-go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating if we should move should move these mock responses into a separate file.

app.get('/deeproxy/filters', (req, res) => {
res.status(200);
if (customResponse) {
res.send(customResponse);
}
res.send({});
});

// needed for code-client-go
app.post('/deeproxy/bundle', (req, res) => {
res.status(200);
res.send({
bundleHash:
'faa6b7161c14f933ef4ca79a18ad9283eab362d5e6d3a977125eb95b37c377d8',
missingFiles: [],
});
});

// needed for code-client-go
app.post(`/api/rest/orgs/:orgId/scans`, (req, res) => {
res.status(201);
res.send({ data: { id: 'a6fb2742-b67f-4dc3-bb27-42b67f1dc344' } });
});

// needed for code-client-go
app.get(`/api/rest/orgs/:orgId/scans/:id`, (req, res) => {
res.status(200);
res.send({
data: {
attributes: {
status: 'done',
components: [
{ findings_url: 'http://localhost:12345/api/code_mock_stream' },
],
},
id: 'a6fb2742-b67f-4dc3-bb27-42b67f1dc344',
},
});
});

app.get(`/api/code_mock_stream`, (req, res) => {
res.status(200);
res.send({
$schema:
'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json',
version: '2.1.0',
runs: [
{
tool: {
driver: {
name: 'SnykCode',
semanticVersion: '1.0.0',
version: '1.0.0',
rules: [],
},
},
results: [
{
ruleId: 'javascript/DisablePoweredBy',
ruleIndex: 1,
level: 'warning',
},
],
properties: {
coverage: [
{
files: 8,
isSupported: true,
lang: 'JavaScript',
},
{
files: 1,
isSupported: true,
lang: 'HTML',
},
],
},
},
],
});
});

app.post(basePath + '/vuln/:registry', (req, res, next) => {
const vulnerabilities = [];
if (req.query.org && req.query.org === 'missing-org') {
Expand Down Expand Up @@ -611,6 +696,14 @@ export const fakeServer = (basePath: string, snykToken: string): FakeServer => {
},
);

// needed for code-client-go
app.post(
basePath.replace('v1', 'hidden') + `/orgs/:orgId/workspaces`,
(req, res) => {
res.status(201).send({});
},
);

app.post(`/rest/orgs/:orgId/sbom_tests`, (req, res) => {
const response = {
data: {
Expand Down Expand Up @@ -861,7 +954,7 @@ export const fakeServer = (basePath: string, snykToken: string): FakeServer => {
getRequests,
popRequest,
popRequests,
setCustomResponse: setCustomResponse,
setCustomResponse,
setLocalCodeEngineConfiguration,
setNextResponse,
setNextStatusCode,
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/sast/no-vulnerabilities/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const message: string = 'Hello, World!';
console.log(message);
1 change: 1 addition & 0 deletions test/fixtures/sast/unsupported-files/.gitinclude
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# git include me