Skip to content

Commit def6a75

Browse files
committed
chore: fix integration & system tests
1 parent 8c72459 commit def6a75

File tree

5 files changed

+115
-137
lines changed

5 files changed

+115
-137
lines changed

.circleci/config/commands/setup_node16.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ steps:
55
export NVM_DIR="/opt/circleci/.nvm"
66
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
77
nvm install v16
8-
npm install
8+
npm ci
99
echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
1010
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
1111
echo 'nvm alias default v16' >> $BASH_ENV

.circleci/config/jobs/@jobs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ eks_integration_tests:
175175
- run:
176176
name: Integration tests EKS
177177
command: |
178-
npm install &&
178+
npm ci &&
179179
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
180180
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:eks:yaml
181181
- run:
@@ -202,7 +202,7 @@ aks_integration_tests:
202202
- run:
203203
name: Integration tests AKS
204204
command: |
205-
npm install &&
205+
npm ci &&
206206
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
207207
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:aks:yaml
208208
- run:
@@ -228,7 +228,7 @@ tag_and_push:
228228
- run:
229229
name: Tag and push
230230
command: |
231-
npm install &&
231+
npm ci &&
232232
docker login --username ${DOCKERHUB_USER} --password ${DOCKERHUB_PASSWORD} &&
233233
unset CIRCLE_PULL_REQUEST &&
234234
unset CI_PULL_REQUEST &&

test/fixtures/java-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
imagePullSecrets:
1919
- name: docker-io
2020
containers:
21-
- image: docker.io/library/java:latest
21+
- image: docker.io/library/openjdk:latest
2222
imagePullPolicy: Always
2323
name: java
2424
command: ['/bin/sleep']

test/helpers/kubernetes-upstream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const UPSTREAM_POLLING_CONFIGURATION = {
1919
export async function getUpstreamResponseBody(
2020
relativeUrl: string,
2121
): Promise<any> {
22-
const url = `https://${config.INTERNAL_PROXY_CREDENTIALS}@kubernetes-upstream-int.dev.snyk.io/${relativeUrl}`;
22+
const url = `https://${config.INTERNAL_PROXY_CREDENTIALS}@kubernetes-upstream-int.${config.INTERNAL_PROXY_HOST}/${relativeUrl}`;
2323
const upstreamResponse = await needle('get', url, null);
2424
const responseBody = upstreamResponse.body;
2525
return responseBody;

test/system/kind.spec.ts

Lines changed: 109 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ afterAll(async () => {
5151
// TODO cleanup the images we saved to /var/tmp?
5252
});
5353

54-
test('Kubernetes-Monitor with KinD', async (jestDoneCallback) => {
54+
test('Kubernetes-Monitor with KinD', async () => {
5555
const emptyDirSyncStub = jest
5656
.spyOn(fsExtra, 'emptyDirSync')
5757
.mockReturnValue({});
@@ -118,18 +118,14 @@ test('Kubernetes-Monitor with KinD', async (jestDoneCallback) => {
118118
.reply(
119119
200,
120120
(uri, requestBody: transmitterTypes.IWorkloadEventsPolicyPayload) => {
121-
try {
122-
expect(
123-
requestBody,
124-
).toEqual<transmitterTypes.IWorkloadEventsPolicyPayload>({
125-
agentId,
126-
cluster: expect.any(String),
127-
userLocator: expect.any(String),
128-
policy: regoPolicyContents,
129-
});
130-
} catch (error) {
131-
jestDoneCallback(error);
132-
}
121+
expect(
122+
requestBody,
123+
).toEqual<transmitterTypes.IWorkloadEventsPolicyPayload>({
124+
agentId,
125+
cluster: expect.any(String),
126+
userLocator: expect.any(String),
127+
policy: regoPolicyContents,
128+
});
133129
},
134130
);
135131

@@ -139,19 +135,15 @@ test('Kubernetes-Monitor with KinD', async (jestDoneCallback) => {
139135
.reply(
140136
200,
141137
(uri, requestBody: transmitterTypes.IClusterMetadataPayload) => {
142-
try {
143-
expect(requestBody).toEqual<
144-
Partial<transmitterTypes.IClusterMetadataPayload>
145-
>({
146-
agentId,
147-
cluster: expect.any(String),
148-
userLocator: expect.any(String),
149-
// also should have version here but due to test limitation it is undefined
150-
// as it is injected as an environment variable via the Helm chart
151-
});
152-
} catch (error) {
153-
jestDoneCallback(error);
154-
}
138+
expect(requestBody).toEqual<
139+
Partial<transmitterTypes.IClusterMetadataPayload>
140+
>({
141+
agentId,
142+
cluster: expect.any(String),
143+
userLocator: expect.any(String),
144+
// also should have version here but due to test limitation it is undefined
145+
// as it is injected as an environment variable via the Helm chart
146+
});
155147
},
156148
);
157149

@@ -179,44 +171,38 @@ test('Kubernetes-Monitor with KinD', async (jestDoneCallback) => {
179171
.reply(
180172
200,
181173
(uri, requestBody: transmitterTypes.IWorkloadMetadataPayload) => {
182-
try {
183-
expect(
184-
requestBody,
185-
).toEqual<transmitterTypes.IWorkloadMetadataPayload>({
186-
workloadLocator: {
187-
cluster: expect.any(String),
188-
name: expect.any(String),
189-
namespace: expect.any(String),
190-
type: expect.any(String),
191-
userLocator: expect.any(String),
192-
},
193-
workloadMetadata: expect.objectContaining({
194-
annotations: expect.any(Object),
195-
labels: expect.any(Object),
196-
revision: expect.any(Number),
197-
specAnnotations: expect.any(Object),
198-
specLabels: expect.any(Object),
199-
podSpec: expect.objectContaining({
200-
containers: expect.arrayContaining([
201-
expect.objectContaining({
202-
resources: expect.objectContaining({
203-
limits: { cpu: '1', memory: '1Gi' },
204-
}),
205-
securityContext: expect.objectContaining({
206-
privileged: false,
207-
capabilities: expect.objectContaining({
208-
drop: ['ALL'],
209-
}),
174+
expect(requestBody).toEqual<transmitterTypes.IWorkloadMetadataPayload>({
175+
workloadLocator: {
176+
cluster: expect.any(String),
177+
name: expect.any(String),
178+
namespace: expect.any(String),
179+
type: expect.any(String),
180+
userLocator: expect.any(String),
181+
},
182+
workloadMetadata: expect.objectContaining({
183+
annotations: expect.any(Object),
184+
labels: expect.any(Object),
185+
revision: expect.any(Number),
186+
specAnnotations: expect.any(Object),
187+
specLabels: expect.any(Object),
188+
podSpec: expect.objectContaining({
189+
containers: expect.arrayContaining([
190+
expect.objectContaining({
191+
resources: expect.objectContaining({
192+
limits: { cpu: '1', memory: '1Gi' },
193+
}),
194+
securityContext: expect.objectContaining({
195+
privileged: false,
196+
capabilities: expect.objectContaining({
197+
drop: ['ALL'],
210198
}),
211199
}),
212-
]),
213-
}),
200+
}),
201+
]),
214202
}),
215-
agentId,
216-
});
217-
} catch (error) {
218-
jestDoneCallback(error);
219-
}
203+
}),
204+
agentId,
205+
});
220206
},
221207
);
222208

@@ -241,56 +227,55 @@ test('Kubernetes-Monitor with KinD', async (jestDoneCallback) => {
241227
.times(1)
242228
// Reply with an error (500) so that we can see that snyk-monitor falls back to sending to the /dependency-graph API.
243229
.reply(500, (uri, requestBody: transmitterTypes.ScanResultsPayload) => {
244-
try {
245-
expect(requestBody).toEqual<transmitterTypes.ScanResultsPayload>({
246-
agentId,
247-
telemetry: {
248-
enqueueDurationMs: expect.any(Number),
249-
imagePullDurationMs: expect.any(Number),
250-
imageScanDurationMs: expect.any(Number),
251-
imageSizeBytes: expect.any(Number),
252-
queueSize: expect.any(Number),
230+
expect(requestBody).toEqual<transmitterTypes.ScanResultsPayload>({
231+
agentId,
232+
telemetry: {
233+
enqueueDurationMs: expect.any(Number),
234+
imagePullDurationMs: expect.any(Number),
235+
imageScanDurationMs: expect.any(Number),
236+
imageSizeBytes: expect.any(Number),
237+
queueSize: expect.any(Number),
238+
},
239+
imageLocator: expect.objectContaining({
240+
imageId: expect.any(String),
241+
}),
242+
scanResults: [
243+
{
244+
facts: expect.arrayContaining([
245+
{ type: 'depGraph', data: expect.any(Object) },
246+
{ type: 'keyBinariesHashes', data: expect.any(Array) },
247+
{ type: 'imageId', data: expect.any(String) },
248+
{ type: 'imageLayers', data: expect.any(Array) },
249+
{ type: 'rootFs', data: expect.any(Array) },
250+
{ type: 'imageOsReleasePrettyName', data: expect.any(String) },
251+
]),
252+
target: { image: 'docker-image|docker.io/library/openjdk' },
253+
identity: { type: 'rpm', args: { platform: 'linux/amd64' } },
253254
},
254-
imageLocator: expect.objectContaining({
255-
imageId: expect.any(String),
256-
}),
257-
scanResults: [
258-
{
259-
facts: expect.arrayContaining([
260-
{ type: 'depGraph', data: expect.any(Object) },
261-
{ type: 'keyBinariesHashes', data: expect.any(Array) },
262-
{ type: 'imageId', data: expect.any(String) },
263-
{ type: 'imageLayers', data: expect.any(Array) },
264-
{ type: 'rootFs', data: expect.any(Array) },
265-
{ type: 'imageOsReleasePrettyName', data: expect.any(String) },
266-
]),
267-
target: { image: 'docker-image|docker.io/library/java' },
268-
identity: { type: 'deb', args: { platform: 'linux/amd64' } },
269-
},
270-
{
271-
facts: [
272-
{ type: 'jarFingerprints', data: expect.any(Object) },
273-
{ type: 'imageId', data: expect.any(String) },
274-
],
275-
identity: {
276-
type: 'maven',
277-
targetFile: '/usr/share/ca-certificates-java',
278-
},
279-
target: { image: 'docker-image|docker.io/library/java' },
255+
{
256+
facts: [
257+
{ type: 'jarFingerprints', data: expect.any(Object) },
258+
{ type: 'imageId', data: expect.any(String) },
259+
],
260+
identity: {
261+
type: 'maven',
262+
targetFile: '/usr/share/ca-certificates-java',
280263
},
281-
{
282-
facts: [
283-
{ type: 'jarFingerprints', data: expect.any(Object) },
284-
{ type: 'imageId', data: expect.any(String) },
285-
],
286-
identity: { type: 'maven', targetFile: '/usr/share/java' },
287-
target: { image: 'docker-image|docker.io/library/java' },
264+
target: { image: 'docker-image|docker.io/library/openjdk' },
265+
},
266+
{
267+
facts: [
268+
{ type: 'jarFingerprints', data: expect.any(Object) },
269+
{ type: 'imageId', data: expect.any(String) },
270+
],
271+
identity: {
272+
type: 'maven',
273+
targetFile: '/usr/java/openjdk-18/lib',
288274
},
289-
],
290-
});
291-
} catch (error) {
292-
jestDoneCallback(error);
293-
}
275+
target: { image: 'docker-image|docker.io/library/openjdk' },
276+
},
277+
],
278+
});
294279
});
295280

296281
nock('https://kubernetes-upstream.snyk.io')
@@ -299,30 +284,23 @@ test('Kubernetes-Monitor with KinD', async (jestDoneCallback) => {
299284
.reply(
300285
200,
301286
(uri, requestBody: transmitterTypes.IDependencyGraphPayload) => {
302-
try {
303-
expect(requestBody).toEqual<transmitterTypes.IDependencyGraphPayload>(
304-
{
305-
agentId,
306-
dependencyGraph: expect.stringContaining(
307-
'docker-image|docker.io/library/java',
308-
),
309-
imageLocator: {
310-
userLocator: expect.any(String),
311-
cluster: expect.any(String),
312-
imageId: expect.any(String),
313-
name: expect.any(String),
314-
namespace: expect.any(String),
315-
type: expect.any(String),
316-
imageWithDigest: expect.any(String),
317-
},
318-
},
319-
);
287+
expect(requestBody).toEqual<transmitterTypes.IDependencyGraphPayload>({
288+
agentId,
289+
dependencyGraph: expect.stringContaining(
290+
'docker-image|docker.io/library/openjdk',
291+
),
292+
imageLocator: {
293+
userLocator: expect.any(String),
294+
cluster: expect.any(String),
295+
imageId: expect.any(String),
296+
name: expect.any(String),
297+
namespace: expect.any(String),
298+
type: expect.any(String),
299+
imageWithDigest: expect.any(String),
300+
},
301+
});
320302

321-
expect(retryKubernetesApiRequestMock).toHaveBeenCalled();
322-
jestDoneCallback();
323-
} catch (error) {
324-
jestDoneCallback(error);
325-
}
303+
expect(retryKubernetesApiRequestMock).toHaveBeenCalled();
326304
},
327305
);
328306

0 commit comments

Comments
 (0)