Skip to content

Commit 43d0469

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 43d0469

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

test.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ const {
99
removeSync,
1010
readFileSync,
1111
copySync,
12+
ensureFileSync,
13+
appendFileSync,
1214
writeFileSync,
1315
statSync,
1416
pathExistsSync
1517
} = require('fs-extra');
1618
const { quote } = require('shell-quote');
17-
const { sep } = require('path');
19+
const { sep, resolve } = require('path');
1820

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

@@ -396,6 +398,38 @@ test(
396398
{ skip: !canUseDocker() }
397399
);
398400

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

0 commit comments

Comments
 (0)