Skip to content

Commit c017f71

Browse files
authored
Merge pull request serverless#336 from sjoshi10/master
use sha256 instead of md5
2 parents 081dcd7 + 51e2e78 commit c017f71

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

lib/pip.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { buildImage, getBindPath, getDockerUid } = require('./docker');
99
const { getStripCommand, getStripMode, deleteFiles } = require('./slim');
1010
const {
1111
checkForAndDeleteMaxCacheVersions,
12-
md5Path,
12+
sha256Path,
1313
getRequirementsWorkingPath,
1414
getUserCachePath
1515
} = require('./shared');
@@ -474,7 +474,7 @@ function installRequirementsIfNeeded(
474474
}
475475

476476
// Then generate our MD5 Sum of this requirements file to determine where it should "go" to and/or pull cache from
477-
const reqChecksum = md5Path(slsReqsTxt);
477+
const reqChecksum = sha256Path(slsReqsTxt);
478478

479479
// Then figure out where this cache should be, if we're caching, if we're in a module, etc
480480
const workingReqsFolder = getRequirementsWorkingPath(

lib/shared.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const Appdir = require('appdirectory');
22
const rimraf = require('rimraf');
3-
const md5File = require('md5-file');
43
const glob = require('glob-all');
54
const path = require('path');
65
const fse = require('fs-extra');
6+
const sha256File = require('sha256-file');
77

88
/**
99
* This helper will check if we're using static cache and have max
@@ -100,13 +100,13 @@ function getUserCachePath(options) {
100100
* @param {string} fullpath
101101
* @return {string}
102102
*/
103-
function md5Path(fullpath) {
104-
return md5File.sync(fullpath);
103+
function sha256Path(fullpath) {
104+
return sha256File(fullpath);
105105
}
106106

107107
module.exports = {
108108
checkForAndDeleteMaxCacheVersions,
109109
getRequirementsWorkingPath,
110110
getUserCachePath,
111-
md5Path
111+
sha256Path
112112
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
"lodash.set": "^4.3.2",
6161
"lodash.uniqby": "^4.0.0",
6262
"lodash.values": "^4.3.0",
63-
"md5-file": "^4.0.0",
6463
"rimraf": "^2.6.2",
65-
"shell-quote": "^1.6.1"
64+
"shell-quote": "^1.6.1",
65+
"sha256-file": "1.0.0"
6666
},
6767
"eslintConfig": {
6868
"extends": "eslint:recommended",

test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
const { quote } = require('shell-quote');
1515
const { sep } = require('path');
1616

17-
const { getUserCachePath, md5Path } = require('./lib/shared');
17+
const { getUserCachePath, sha256Path } = require('./lib/shared');
1818

1919
const initialWorkingDir = process.cwd();
2020

@@ -1679,7 +1679,7 @@ test('py3.6 uses static and download cache', t => {
16791679
npm(['i', path]);
16801680
sls(['--useDownloadCache=true', '--useStaticCache=true', 'package']);
16811681
const cachepath = getUserCachePath();
1682-
const cacheFolderHash = md5Path('.serverless/requirements.txt');
1682+
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
16831683
t.true(
16841684
pathExistsSync(`${cachepath}${sep}downloadCacheslspyc${sep}http`),
16851685
'http exists in download-cache'
@@ -1704,7 +1704,7 @@ test(
17041704
'package'
17051705
]);
17061706
const cachepath = getUserCachePath();
1707-
const cacheFolderHash = md5Path('.serverless/requirements.txt');
1707+
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
17081708
t.true(
17091709
pathExistsSync(`${cachepath}${sep}downloadCacheslspyc${sep}http`),
17101710
'http exists in download-cache'
@@ -1724,7 +1724,7 @@ test('py3.6 uses static cache', t => {
17241724
npm(['i', path]);
17251725
sls(['--useStaticCache=true', 'package']);
17261726
const cachepath = getUserCachePath();
1727-
const cacheFolderHash = md5Path('.serverless/requirements.txt');
1727+
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
17281728
t.true(
17291729
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
17301730
'flask exists in static-cache'
@@ -1758,7 +1758,7 @@ test('py3.6 uses static cache with cacheLocation option', t => {
17581758
npm(['i', path]);
17591759
const cachepath = '.requirements-cache';
17601760
sls(['--useStaticCache=true', `--cacheLocation=${cachepath}`, 'package']);
1761-
const cacheFolderHash = md5Path('.serverless/requirements.txt');
1761+
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
17621762
t.true(
17631763
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
17641764
'flask exists in static-cache'
@@ -1785,7 +1785,7 @@ test(
17851785
'package'
17861786
]);
17871787
const cachepath = getUserCachePath();
1788-
const cacheFolderHash = md5Path('.serverless/requirements.txt');
1788+
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
17891789
t.true(
17901790
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
17911791
'flask exists in static-cache'

0 commit comments

Comments
 (0)