Handle invalid bcrypt salt errors in Bcrypt compare (#2615)
This commit is contained in:
parent
d6f087efad
commit
6f95a2e17d
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { isWorkerEnvironment } from "../Utils.mjs";
|
||||
|
||||
@ -43,11 +44,16 @@ class BcryptCompare extends Operation {
|
||||
async run(input, args) {
|
||||
const hash = args[0];
|
||||
|
||||
const match = await bcrypt.compare(input, hash, undefined, p => {
|
||||
// Progress callback
|
||||
if (isWorkerEnvironment())
|
||||
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
||||
});
|
||||
let match;
|
||||
try {
|
||||
match = await bcrypt.compare(input, hash, undefined, p => {
|
||||
// Progress callback
|
||||
if (isWorkerEnvironment())
|
||||
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
||||
});
|
||||
} catch (err) {
|
||||
throw new OperationError(err.toString());
|
||||
}
|
||||
|
||||
return match ? "Match: " + input : "No match";
|
||||
|
||||
|
||||
@ -993,6 +993,17 @@ TestRegister.addTests([
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bcrypt compare: invalid salt version",
|
||||
input: "password",
|
||||
expectedOutput: "Error: Invalid salt version: $a",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bcrypt compare",
|
||||
args: ["$ab$04$K.H1WlFDQ/iIo/PiprT/puwluJ5rzuSE5q8D/Fk3NuLgU2aXiGR9m"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Scrypt: RFC test vector 1",
|
||||
input: "",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user