Skip to content

Commit 2c12a7a

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. This patch also adds minor debugging output, in case no requirements.txt is found.
1 parent 566a7fe commit 2c12a7a

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

lib/pip.js

+3
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ function installRequirementsIfNeeded(
492492

493493
// Skip requirements generation, if requirements file doesn't exist
494494
if (!requirementsFileExists(servicePath, options, fileName)) {
495+
serverless.cli.log(
496+
`Skipping generation of requirements: file ${fileName} not found`
497+
);
495498
return false;
496499
}
497500

test.js

+32-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,35 @@ 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(zipfiles.includes(`boto3/__init__.py`), 'boto3 is packaged via ssh');
425+
t.end();
426+
},
427+
{ skip: !canUseDocker() }
428+
);
429+
399430
test('py2.7 can package flask with default options', t => {
400431
process.chdir('tests/base');
401432
const path = npm(['pack', '../..']);

tests/base/requirements-w-git-ssh.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

tests/base/serverless.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ custom:
1010
pythonRequirements:
1111
zip: ${opt:zip, self:custom.defaults.zip}
1212
dockerizePip: ${opt:dockerizePip, self:custom.defaults.dockerizePip}
13+
dockerSsh: ${opt:dockerSsh, self:custom.defaults.dockerSsh}
1314
slim: ${opt:slim, self:custom.defaults.slim}
1415
slimPatterns: ${file(./slimPatterns.yml):slimPatterns, self:custom.defaults.slimPatterns}
1516
slimPatternsAppendDefaults: ${opt:slimPatternsAppendDefaults, self:custom.defaults.slimPatternsAppendDefaults}
@@ -24,6 +25,7 @@ custom:
2425
slimPatternsAppendDefaults: true
2526
zip: false
2627
dockerizePip: false
28+
dockerSsh: false
2729
individually: false
2830
useStaticCache: true
2931
useDownloadCache: true
@@ -49,5 +51,3 @@ functions:
4951
package:
5052
include:
5153
- 'fn2/**'
52-
53-

0 commit comments

Comments
 (0)