我一直试图运行integ测试,但遇到了以下错误:
2022-03-26T18:51:12.446Z cypress:network:agent got family { family: 4, href: 'https://wepapi.com/api/session-status' }
1) "before all" hook for "should login"
0 passing (345ms)
1 failing
1) Login
"before all" hook for "should login":
TypeError: crypto.createHmac is not a function
Because this error occurred during a `before all` hook we are skipping all of the remaining tests.
我们正在使用Crypto来生成Auth版本。
import Crypto from 'crypto';
import fs from 'fs';
export const getSha256FromFile = (filePath: string): string =>
Crypto
.createHash('sha256')
.update(fs.readFileSync(filePath))
.digest('hex')
在auth Lambda文件中:
const codeSha256 = getSha256FromFile(AUTH_LAMBDA_CODE_FILE);
this.version = authLambda.addVersion(
`AuthLambdaVersion_${codeSha256}`,
codeSha256
我甚至没有使用crypto.createHmac函数。不知道是怎么回事。
更新
我刚刚意识到我们正在使用AWS4符号功能来签署请求。就像这样:
aws4.sign(requestOptions, {
secretAccessKey: "<your-secret-access-key>",
accessKeyId: "<your-access-key-id>",
sessionToken: "<your-session-token>"
})
而符号功能使用密码functions.which就会产生这个错误。但我还是不知道该怎么解决
发布于 2022-03-28 15:01:16
导入crypto
模块的正确方法如下:
import * as crypto from "crypto"
或者您可以直接导入函数
import { createHmac } from "crypto"
https://stackoverflow.com/questions/71631217
复制相似问题