Skip to content

Commit e1d74fb

Browse files
committed
Add test to check whether the plugin mounts the entire ssh dir
This test makes sure the plugin actually mounts the SSH directory into the container, if the dockerizePip and dockerSsh are given. It does this by creating a new known_hosts file and placing the RSA fingerprint of Github inside, then installing a package via Git, which requires this fingerprint to be present in known_hosts. If it is not present, the process will fail.
1 parent 80faab9 commit e1d74fb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

test.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ const {
99
removeSync,
1010
readFileSync,
1111
copySync,
12+
ensureFileSync,
1213
writeFileSync,
1314
statSync,
1415
pathExistsSync
1516
} = require('fs-extra');
1617
const { quote } = require('shell-quote');
17-
const { sep } = require('path');
18+
const { sep, resolve } = require('path');
1819

1920
const { getUserCachePath, sha256Path } = require('./lib/shared');
2021

@@ -396,6 +397,38 @@ test(
396397
{ skip: !canUseDocker() }
397398
);
398399

400+
test(
401+
'dockerSsh mounts entire ssh folder into docker',
402+
t => {
403+
process.chdir('tests/base');
404+
const path = npm(['pack', '../..']);
405+
npm(['i', path]);
406+
// create a known_hosts file with the rsa fingerprint of github
407+
// the plugin should mount the entire .ssh directory into the container
408+
const known_hosts_file = resolve(process.env.HOME, `./.ssh/known_hosts`);
409+
ensureFileSync(known_hosts_file);
410+
writeFileSync(
411+
known_hosts_file,
412+
'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='
413+
);
414+
// verify this by installing a requirement via git+ssh
415+
sls([
416+
'--dockerizePip=true',
417+
'--dockerSsh=true',
418+
'--fileName=requirements-w-git-ssh.txt',
419+
'package'
420+
]);
421+
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
422+
// check if the requirement is actually in the archive
423+
t.true(
424+
zipfiles.includes(`boto3/__init__.py`),
425+
'boto3 is packaged via ssh'
426+
);
427+
t.end();
428+
},
429+
{ skip: !canUseDocker() }
430+
);
431+
399432
test('py2.7 can package flask with default options', t => {
400433
process.chdir('tests/base');
401434
const path = npm(['pack', '../..']);

tests/base/requirements-w-ssh-git.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flask
2+
bottle
3+
git+ssh://[email protected]/boto/boto3.git#egg=boto3

0 commit comments

Comments
 (0)