diff --git a/package-lock.json b/package-lock.json index 3f319ae..b5e6e7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -397,7 +397,7 @@ }, "babel-eslint": { "version": "8.2.3", - "resolved": "http://registry.npmjs.org/babel-eslint/-/babel-eslint-8.2.3.tgz", + "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.2.3.tgz", "integrity": "sha512-0HeSTtaXg/Em7FCUWxwOT+KeFSO1O7LuRuzhk7g+1BjwdlQGlHq4OyMi3GqGxrNfEq8jEi6Hmt5ylEQUhurgiQ==", "dev": true, "requires": { @@ -4163,7 +4163,7 @@ }, "should-equal": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/should-equal/-/should-equal-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/should-equal/-/should-equal-1.0.1.tgz", "integrity": "sha1-C26VFvJgGp+wuy3MNpr6HH4gCvc=", "dev": true, "requires": { diff --git a/src/http-middlewares/before/add-digest-auth-header.js b/src/http-middlewares/before/add-digest-auth-header.js index f778819..714e98f 100644 --- a/src/http-middlewares/before/add-digest-auth-header.js +++ b/src/http-middlewares/before/add-digest-auth-header.js @@ -1,11 +1,10 @@ 'use strict'; -const crypto = require('crypto'); const urllib = require('url'); - const fetch = require('node-fetch'); const { NotImplementedError } = require('../../errors'); +const { md5 } = require('../../tools/hashing'); // This function splits a comma-separated string described by RFC 2068 Section 2. // Ported from https://github.com/python/cpython/blob/f081fd83/Lib/urllib/request.py#L1399-L1440 @@ -80,12 +79,6 @@ const parseDictHeader = s => { return res; }; -const md5 = s => - crypto - .createHash('md5') - .update(s) - .digest('hex'); - const buildDigestHeader = (username, password, url, method, creds) => { if (creds.algorithm && creds.algorithm.toUpperCase() !== 'MD5') { throw new NotImplementedError( diff --git a/src/tools/create-app-tester.js b/src/tools/create-app-tester.js index 1a3b441..7d48f08 100644 --- a/src/tools/create-app-tester.js +++ b/src/tools/create-app-tester.js @@ -40,6 +40,8 @@ const createAppTester = appRaw => { const handler = createLambdaHandler(appRaw); const createHandlerPromise = promisifyHandler(handler); + const randomSeed = genId(); + return (methodOrFunc, bundle) => { bundle = bundle || {}; @@ -49,7 +51,10 @@ const createAppTester = appRaw => { command: 'execute', method, bundle, - storeKey: shouldPaginate(appRaw, method) ? `testKey-${genId()}` : null + storeKey: shouldPaginate(appRaw, method) + ? // this key will be consistent across runs but unique to each test so we don't lose cursors + `testKey-${method}-${randomSeed}` + : null }; if (process.env.LOG_TO_STDOUT) { diff --git a/src/tools/data.js b/src/tools/data.js index ed9c9ca..87013a0 100644 --- a/src/tools/data.js +++ b/src/tools/data.js @@ -174,15 +174,15 @@ const simpleTruncate = (string, length, suffix) => { const genId = () => parseInt(Math.random() * 100000000); module.exports = { - isPlainObj, - findMapDeep, - memoizedFindMapDeep, deepCopy, - jsonCopy, deepFreeze, - recurseReplace, - recurseExtract, + findMapDeep, flattenPaths, - simpleTruncate, - genId + genId, + isPlainObj, + jsonCopy, + memoizedFindMapDeep, + recurseExtract, + recurseReplace, + simpleTruncate }; diff --git a/src/tools/hashing.js b/src/tools/hashing.js index 0249011..debd9ee 100644 --- a/src/tools/hashing.js +++ b/src/tools/hashing.js @@ -22,7 +22,14 @@ const snipify = s => { return `:censored:${length}:${result.substr(0, 10)}:`; }; +const md5 = s => + crypto + .createHash('md5') + .update(s) + .digest('hex'); + module.exports = { hashify, + md5, snipify };