Skip to content

use sha256 instead of md5 #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { buildImage, getBindPath, getDockerUid } = require('./docker');
const { getStripCommand, getStripMode, deleteFiles } = require('./slim');
const {
checkForAndDeleteMaxCacheVersions,
md5Path,
sha256Path,
getRequirementsWorkingPath,
getUserCachePath
} = require('./shared');
Expand Down Expand Up @@ -474,7 +474,7 @@ function installRequirementsIfNeeded(
}

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

// Then figure out where this cache should be, if we're caching, if we're in a module, etc
const workingReqsFolder = getRequirementsWorkingPath(
Expand Down
8 changes: 4 additions & 4 deletions lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const Appdir = require('appdirectory');
const rimraf = require('rimraf');
const md5File = require('md5-file');
const glob = require('glob-all');
const path = require('path');
const fse = require('fs-extra');
const sha256File = require('sha256-file');

/**
* This helper will check if we're using static cache and have max
Expand Down Expand Up @@ -100,13 +100,13 @@ function getUserCachePath(options) {
* @param {string} fullpath
* @return {string}
*/
function md5Path(fullpath) {
return md5File.sync(fullpath);
function sha256Path(fullpath) {
return sha256File(fullpath);
}

module.exports = {
checkForAndDeleteMaxCacheVersions,
getRequirementsWorkingPath,
getUserCachePath,
md5Path
sha256Path
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
"lodash.set": "^4.3.2",
"lodash.uniqby": "^4.0.0",
"lodash.values": "^4.3.0",
"md5-file": "^4.0.0",
"rimraf": "^2.6.2",
"shell-quote": "^1.6.1"
"shell-quote": "^1.6.1",
"sha256-file": "1.0.0"
},
"eslintConfig": {
"extends": "eslint:recommended",
Expand Down
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
const { quote } = require('shell-quote');
const { sep } = require('path');

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

const initialWorkingDir = process.cwd();

Expand Down Expand Up @@ -1679,7 +1679,7 @@ test('py3.6 uses static and download cache', t => {
npm(['i', path]);
sls(['--useDownloadCache=true', '--useStaticCache=true', 'package']);
const cachepath = getUserCachePath();
const cacheFolderHash = md5Path('.serverless/requirements.txt');
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
t.true(
pathExistsSync(`${cachepath}${sep}downloadCacheslspyc${sep}http`),
'http exists in download-cache'
Expand All @@ -1704,7 +1704,7 @@ test(
'package'
]);
const cachepath = getUserCachePath();
const cacheFolderHash = md5Path('.serverless/requirements.txt');
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
t.true(
pathExistsSync(`${cachepath}${sep}downloadCacheslspyc${sep}http`),
'http exists in download-cache'
Expand All @@ -1724,7 +1724,7 @@ test('py3.6 uses static cache', t => {
npm(['i', path]);
sls(['--useStaticCache=true', 'package']);
const cachepath = getUserCachePath();
const cacheFolderHash = md5Path('.serverless/requirements.txt');
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
t.true(
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
'flask exists in static-cache'
Expand Down Expand Up @@ -1758,7 +1758,7 @@ test('py3.6 uses static cache with cacheLocation option', t => {
npm(['i', path]);
const cachepath = '.requirements-cache';
sls(['--useStaticCache=true', `--cacheLocation=${cachepath}`, 'package']);
const cacheFolderHash = md5Path('.serverless/requirements.txt');
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
t.true(
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
'flask exists in static-cache'
Expand All @@ -1785,7 +1785,7 @@ test(
'package'
]);
const cachepath = getUserCachePath();
const cacheFolderHash = md5Path('.serverless/requirements.txt');
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
t.true(
pathExistsSync(`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}flask`),
'flask exists in static-cache'
Expand Down