From ec02e8a0ada7a8f6c71a91df164db8c25bbbb7b4 Mon Sep 17 00:00:00 2001 From: dcode Date: Wed, 12 Feb 2025 15:48:48 +0100 Subject: [PATCH] Fix tests --- tests/index.js | 44 ++++++++----- tests/quickbrown.txt | 150 ------------------------------------------- 2 files changed, 28 insertions(+), 166 deletions(-) delete mode 100644 tests/quickbrown.txt diff --git a/tests/index.js b/tests/index.js index f7a16e6..15d9099 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,13 +1,7 @@ -import path from "node:path"; -import fs from "node:fs"; import assert from "node:assert"; -import { fileURLToPath } from "node:url"; - -import binding from "bcrypt"; +import bcryptcpp from "bcrypt"; import bcrypt from "../index.js"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - const tests = [ function encodeBase64(done) { var str = bcrypt.encodeBase64( @@ -177,27 +171,45 @@ const tests = [ }, ); }, - function compat_quickbrown(done) { - var pass = fs.readFileSync(path.join(__dirname, "quickbrown.txt")) + "", - salt = bcrypt.genSaltSync(), - hash1 = binding.hashSync(pass, salt), - hash2 = bcrypt.hashSync(pass, salt); - assert.equal(hash1, hash2); + function compat_hash(done) { + var pass = [ + " space ", + "Heizölrückstoßabdämpfung", + "Ξεσκεπάζω τὴν ψυχοφθόρα βδελυγμία", + "El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y ", + "Où l'obèse jury mûr", + "Úrmhac na hÓighe Beannaithe", + "Árvíztűrő tükörfúrógép", + "Sævör grét áðan því úlpan var ónýt", + "わかよたれそつねならむ", + "ケフコエテ アサキユメミシ", + "דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה", + "Pchnąć w tę łódź jeża lub ośm skrzyń fig", + "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!", + "๏ เป็นมนุษย์สุดประเสริฐเลิศคุณค่า", + "Pijamalı hasta, yağız şoföre çabucak güvendi.", + ]; + for (var i = 0; i < pass.length; i++) { + var salt = bcrypt.genSaltSync(), + hash1 = bcryptcpp.hashSync(pass[i], salt), + hash2 = bcrypt.hashSync(pass[i], salt); + assert.equal(hash1, hash2); + } done(); }, function compat_roundsOOB(done) { var salt1 = bcrypt.genSaltSync(0), // $10$ like not set - salt2 = binding.genSaltSync(0); + salt2 = bcryptcpp.genSaltSync(0); assert.strictEqual(salt1.substring(0, 7), "$2b$10$"); assert.strictEqual(salt2.substring(0, 7), "$2b$10$"); salt1 = bcrypt.genSaltSync(3); // $04$ is lower cap - salt2 = bcrypt.genSaltSync(3); + salt2 = bcryptcpp.genSaltSync(3); assert.strictEqual(salt1.substring(0, 7), "$2b$04$"); assert.strictEqual(salt2.substring(0, 7), "$2b$04$"); salt1 = bcrypt.genSaltSync(32); // $31$ is upper cap - salt2 = bcrypt.genSaltSync(32); + salt2 = bcryptcpp.genSaltSync(32); assert.strictEqual(salt1.substring(0, 7), "$2b$31$"); assert.strictEqual(salt2.substring(0, 7), "$2b$31$"); diff --git a/tests/quickbrown.txt b/tests/quickbrown.txt deleted file mode 100644 index 81e850f..0000000 --- a/tests/quickbrown.txt +++ /dev/null @@ -1,150 +0,0 @@ -Sentences that contain all letters commonly used in a language --------------------------------------------------------------- - -Markus Kuhn -- 2012-04-11 - -This is an example of a plain-text file encoded in UTF-8. - - -Danish (da) ---------- - - Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen - Wolther spillede på xylofon. - (= Quiz contestants were eating strawbery with cream while Wolther - the circus clown played on xylophone.) - -German (de) ------------ - - Falsches Üben von Xylophonmusik quält jeden größeren Zwerg - (= Wrongful practicing of xylophone music tortures every larger dwarf) - - Zwölf Boxkämpfer jagten Eva quer über den Sylter Deich - (= Twelve boxing fighters hunted Eva across the dike of Sylt) - - Heizölrückstoßabdämpfung - (= fuel oil recoil absorber) - (jqvwxy missing, but all non-ASCII letters in one word) - -Greek (el) ----------- - - Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο - (= No more shall I see acacias or myrtles in the golden clearing) - - Ξεσκεπάζω τὴν ψυχοφθόρα βδελυγμία - (= I uncover the soul-destroying abhorrence) - -English (en) ------------- - - The quick brown fox jumps over the lazy dog - -Spanish (es) ------------- - - El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y - frío, añoraba a su querido cachorro. - (Contains every letter and every accent, but not every combination - of vowel + acute.) - -French (fr) ------------ - - Portez ce vieux whisky au juge blond qui fume sur son île intérieure, à - côté de l'alcôve ovoïde, où les bûches se consument dans l'âtre, ce - qui lui permet de penser à la cænogenèse de l'être dont il est question - dans la cause ambiguë entendue à Moÿ, dans un capharnaüm qui, - pense-t-il, diminue çà et là la qualité de son œuvre. - - l'île exiguë - Où l'obèse jury mûr - Fête l'haï volapük, - Âne ex aéquo au whist, - Ôtez ce vœu déçu. - - Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en - canoë au delà des îles, près du mälström où brûlent les novæ. - -Irish Gaelic (ga) ------------------ - - D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh - -Hungarian (hu) --------------- - - Árvíztűrő tükörfúrógép - (= flood-proof mirror-drilling machine, only all non-ASCII letters) - -Icelandic (is) --------------- - - Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa - - Sævör grét áðan því úlpan var ónýt - (some ASCII letters missing) - -Japanese (jp) -------------- - - Hiragana: (Iroha) - - いろはにほへとちりぬるを - わかよたれそつねならむ - うゐのおくやまけふこえて - あさきゆめみしゑひもせす - - Katakana: - - イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム - ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン - -Hebrew (iw) ------------ - - ? דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה - -Polish (pl) ------------ - - Pchnąć w tę łódź jeża lub ośm skrzyń fig - (= To push a hedgehog or eight bins of figs in this boat) - -Russian (ru) ------------- - - В чащах юга жил бы цитрус? Да, но фальшивый экземпляр! - (= Would a citrus live in the bushes of south? Yes, but only a fake one!) - - Съешь же ещё этих мягких французских булок да выпей чаю - (= Eat some more of these fresh French loafs and have some tea) - -Thai (th) ---------- - - [--------------------------|------------------------] - ๏ เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน - จงฝ่าฟันพัฒนาวิชาการ อย่าล้างผลาญฤๅเข่นฆ่าบีฑาใคร - ไม่ถือโทษโกรธแช่งซัดฮึดฮัดด่า หัดอภัยเหมือนกีฬาอัชฌาสัย - ปฏิบัติประพฤติกฎกำหนดใจ พูดจาให้จ๊ะๆ จ๋าๆ น่าฟังเอย ฯ - - [The copyright for the Thai example is owned by The Computer - Association of Thailand under the Royal Patronage of His Majesty the - King.] - -Turkish (tr) ------------- - - Pijamalı hasta, yağız şoföre çabucak güvendi. - (=Patient with pajamas, trusted swarthy driver quickly) - - -Special thanks to the people from all over the world who contributed -these sentences since 1999. - -A much larger collection of such pangrams is now available at - - http://en.wikipedia.org/wiki/List_of_pangrams -