Skip to content

Commit 71d0c0a

Browse files
committed
test: validate volume mounts in config and at runtime
1 parent c84074d commit 71d0c0a

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

test/helpers/deployment.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,51 @@ export function validateSecureConfiguration(test: tap, deployment: V1Deployment)
4040
);
4141
}
4242

43+
export function validateVolumeMounts(test: tap, deployment: V1Deployment) {
44+
if (
45+
!deployment.spec ||
46+
!deployment.spec.template.spec ||
47+
!deployment.spec.template.spec.containers ||
48+
deployment.spec.template.spec.containers.length === 0 ||
49+
!deployment.spec.template.spec.containers[0].volumeMounts
50+
) {
51+
test.fail('bad container spec or missing volumeMounts');
52+
return;
53+
}
54+
55+
const volumeMounts = deployment.spec.template.spec.containers[0].volumeMounts;
56+
57+
const temporaryStorageMount = volumeMounts.find(
58+
(mount) => mount.name === 'temporary-storage',
59+
);
60+
if (!temporaryStorageMount) {
61+
test.fail('missing deployment mount "temporary-storage"');
62+
return;
63+
}
64+
65+
test.same(
66+
temporaryStorageMount.mountPath,
67+
'/var/tmp',
68+
'deployment file mounts temporary storage at the expected path',
69+
);
70+
71+
const dockerConfigMount = volumeMounts.find(
72+
(mount) => mount.name === 'docker-config',
73+
);
74+
if (!dockerConfigMount) {
75+
test.fail('missing deployment mount "docker-config"');
76+
return;
77+
}
78+
79+
test.same(
80+
dockerConfigMount.readOnly,
81+
true,
82+
'docker-config is a read-only mount',
83+
);
84+
85+
test.same(
86+
dockerConfigMount.mountPath,
87+
'/root/.docker',
88+
'docker-config mount path is as expected',
89+
);
90+
}

test/integration/kubernetes.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
validateHomebaseStoredMetadata,
1010
getHomebaseResponseBody,
1111
} from '../helpers/homebase';
12-
import { validateSecureConfiguration } from '../helpers/deployment';
12+
import { validateSecureConfiguration, validateVolumeMounts } from '../helpers/deployment';
1313

1414
let integrationId: string;
1515

@@ -178,4 +178,5 @@ tap.test('snyk-monitor secure configuration is as expected', async (t) => {
178178
const deployment = response.body;
179179

180180
validateSecureConfiguration(t, deployment);
181+
validateVolumeMounts(t, deployment);
181182
});

test/unit/deployment-files.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { parse } from 'yaml';
33
import { readFileSync } from 'fs';
44
import { V1Deployment } from '@kubernetes/client-node';
55
import * as snykConfig from '../../src/common/config';
6-
import { validateSecureConfiguration } from '../helpers/deployment';
6+
import { validateSecureConfiguration, validateVolumeMounts } from '../helpers/deployment';
77

88
/**
99
* Note that these checks are also performed at runtime on the deployed snyk-monitor, see the integration tests.
@@ -19,5 +19,6 @@ tap.test('ensure the security properties of the deployment files are unchanged',
1919
const deployment: V1Deployment = parse(fileContent);
2020

2121
validateSecureConfiguration(t, deployment);
22+
validateVolumeMounts(t, deployment);
2223
}
2324
});

0 commit comments

Comments
 (0)