Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

(fix) cursor reading didn't work in tests #125

Merged
merged 2 commits into from
Nov 7, 2018
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 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions src/http-middlewares/before/add-digest-auth-header.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion src/tools/create-app-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const createAppTester = appRaw => {
const handler = createLambdaHandler(appRaw);
const createHandlerPromise = promisifyHandler(handler);

const randomSeed = genId();

return (methodOrFunc, bundle) => {
bundle = bundle || {};

Expand All @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions src/tools/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
7 changes: 7 additions & 0 deletions src/tools/hashing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};