aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/spec/tests.js96
1 files changed, 51 insertions, 45 deletions
diff --git a/tests/spec/tests.js b/tests/spec/tests.js
index 73e3087..58318db 100644
--- a/tests/spec/tests.js
+++ b/tests/spec/tests.js
@@ -3130,7 +3130,7 @@ it("Shows the number of bits of entropy for 4 bits of binary", function(done) {
3130 testEntropyBits(done, "0000", "4"); 3130 testEntropyBits(done, "0000", "4");
3131}); 3131});
3132it("Shows the number of bits of entropy for 1 character of base 6 (dice)", function(done) { 3132it("Shows the number of bits of entropy for 1 character of base 6 (dice)", function(done) {
3133 // 6 in card is 0 in base 6, 0 in base 6 is 2.6 bits (rounded down to 2 bits) 3133 // 6 in card is 0 in base 6, 0 is mapped to 00 by entropy.js
3134 testEntropyBits(done, "6", "2"); 3134 testEntropyBits(done, "6", "2");
3135}); 3135});
3136it("Shows the number of bits of entropy for 1 character of base 10 with 3 bits", function(done) { 3136it("Shows the number of bits of entropy for 1 character of base 10 with 3 bits", function(done) {
@@ -3138,13 +3138,15 @@ it("Shows the number of bits of entropy for 1 character of base 10 with 3 bits",
3138 testEntropyBits(done, "7", "3"); 3138 testEntropyBits(done, "7", "3");
3139}); 3139});
3140it("Shows the number of bits of entropy for 1 character of base 10 with 4 bis", function(done) { 3140it("Shows the number of bits of entropy for 1 character of base 10 with 4 bis", function(done) {
3141 testEntropyBits(done, "8", "4"); 3141 // 8 in base 10 is mapped to 0 by entropy.js
3142 testEntropyBits(done, "8", "1");
3142}); 3143});
3143it("Shows the number of bits of entropy for 1 character of hex", function(done) { 3144it("Shows the number of bits of entropy for 1 character of hex", function(done) {
3144 testEntropyBits(done, "F", "4"); 3145 testEntropyBits(done, "F", "4");
3145}); 3146});
3146it("Shows the number of bits of entropy for 2 characters of base 10", function(done) { 3147it("Shows the number of bits of entropy for 2 characters of base 10", function(done) {
3147 testEntropyBits(done, "29", "6"); 3148 // 2 as base 10 is binary 010, 9 is mapped to binary 1 by entropy.js
3149 testEntropyBits(done, "29", "4");
3148}); 3150});
3149it("Shows the number of bits of entropy for 2 characters of hex", function(done) { 3151it("Shows the number of bits of entropy for 2 characters of hex", function(done) {
3150 testEntropyBits(done, "0A", "8"); 3152 testEntropyBits(done, "0A", "8");
@@ -3169,17 +3171,17 @@ it("Shows the number of bits of entropy for 4 characters of hex with leading zer
3169 testEntropyBits(done, "000A", "16"); 3171 testEntropyBits(done, "000A", "16");
3170}); 3172});
3171it("Shows the number of bits of entropy for 4 characters of base 6", function(done) { 3173it("Shows the number of bits of entropy for 4 characters of base 6", function(done) {
3172 testEntropyBits(done, "5555", "11"); 3174 // 5 in base 6 is mapped to binary 1
3175 testEntropyBits(done, "5555", "4");
3173}); 3176});
3174it("Shows the number of bits of entropy for 4 characters of base 6 dice", function(done) { 3177it("Shows the number of bits of entropy for 4 characters of base 6 dice", function(done) {
3175 // uses dice, so entropy is actually 0000 in base 6, which is 4 lots of 3178 // uses dice, so entropy is actually 0000 in base 6, which is 4 lots of
3176 // 2.58 bits, which is 10.32 bits (rounded down to 10 bits) 3179 // binary 00
3177 testEntropyBits(done, "6666", "10"); 3180 testEntropyBits(done, "6666", "8");
3178}); 3181});
3179it("Shows the number of bits of entropy for 4 charactes of base 10", function(done) { 3182it("Shows the number of bits of entropy for 4 charactes of base 10", function(done) {
3180 // Uses base 10, which is 4 lots of 3.32 bits, which is 13.3 bits (rounded 3183 // 2 in base 10 is binary 010 and 7 is binary 111 so is 4 events of 3 bits
3181 // down to 13) 3184 testEntropyBits(done, "2227", "12");
3182 testEntropyBits(done, "2227", "13");
3183}); 3185});
3184it("Shows the number of bits of entropy for 4 characters of hex with 2 leading zeros", function(done) { 3186it("Shows the number of bits of entropy for 4 characters of hex with 2 leading zeros", function(done) {
3185 testEntropyBits(done, "222F", "16"); 3187 testEntropyBits(done, "222F", "16");
@@ -3188,13 +3190,16 @@ it("Shows the number of bits of entropy for 4 characters of hex starting with F"
3188 testEntropyBits(done, "FFFF", "16"); 3190 testEntropyBits(done, "FFFF", "16");
3189}); 3191});
3190it("Shows the number of bits of entropy for 10 characters of base 10", function(done) { 3192it("Shows the number of bits of entropy for 10 characters of base 10", function(done) {
3191 // 10 events at 3.32 bits per event 3193 // 10 events with 3 bits for each event
3192 testEntropyBits(done, "0000101017", "33"); 3194 testEntropyBits(done, "0000101017", "30");
3195});
3196it("Shows the number of bits of entropy for 10 characters of base 10 account for bias", function(done) {
3197 // 9 events with 3 bits per event and 1 event with 1 bit per event
3198 testEntropyBits(done, "0000101018", "28");
3193}); 3199});
3194it("Shows the number of bits of entropy for a full deck of cards", function(done) { 3200it("Shows the number of bits of entropy for a full deck of cards", function(done) {
3195 // cards are not replaced, so a full deck is not 52^52 entropy which is 296 3201 // removing bias is 32*5 + 16*4 + 4*2
3196 // bits, it's 52!, which is 225 bits 3202 testEntropyBits(done, "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", "232");
3197 testEntropyBits(done, "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", "225");
3198}); 3203});
3199 3204
3200it("Shows details about the entered entropy", function(done) { 3205it("Shows details about the entered entropy", function(done) {
@@ -3320,7 +3325,7 @@ it("Shows details about the entered entropy", function(done) {
3320 entropy: "7d", 3325 entropy: "7d",
3321 type: "card", 3326 type: "card",
3322 events: "1", 3327 events: "1",
3323 bits: "4", 3328 bits: "5",
3324 words: 0, 3329 words: 0,
3325 strength: "less than a second", 3330 strength: "less than a second",
3326 } 3331 }
@@ -3332,7 +3337,7 @@ it("Shows details about the entered entropy", function(done) {
3332 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", 3337 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3333 type: "card (full deck)", 3338 type: "card (full deck)",
3334 events: "52", 3339 events: "52",
3335 bits: "225", 3340 bits: "232",
3336 words: 21, 3341 words: 21,
3337 strength: "centuries", 3342 strength: "centuries",
3338 } 3343 }
@@ -3344,7 +3349,7 @@ it("Shows details about the entered entropy", function(done) {
3344 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d", 3349 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d",
3345 type: "card (full deck, 1 duplicate: 3d)", 3350 type: "card (full deck, 1 duplicate: 3d)",
3346 events: "53", 3351 events: "53",
3347 bits: "254", 3352 bits: "237",
3348 words: 21, 3353 words: 21,
3349 strength: "centuries", 3354 strength: "centuries",
3350 } 3355 }
@@ -3356,7 +3361,7 @@ it("Shows details about the entered entropy", function(done) {
3356 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d", 3361 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d",
3357 type: "card (2 duplicates: 3d 4d, 1 missing: KS)", 3362 type: "card (2 duplicates: 3d 4d, 1 missing: KS)",
3358 events: "53", 3363 events: "53",
3359 bits: "254", 3364 bits: "240",
3360 words: 21, 3365 words: 21,
3361 strength: "centuries", 3366 strength: "centuries",
3362 } 3367 }
@@ -3368,8 +3373,8 @@ it("Shows details about the entered entropy", function(done) {
3368 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d", 3373 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d",
3369 type: "card (4 duplicates: 3d 4d 5d..., 1 missing: KS)", 3374 type: "card (4 duplicates: 3d 4d 5d..., 1 missing: KS)",
3370 events: "55", 3375 events: "55",
3371 bits: "264", 3376 bits: "250",
3372 words: 24, 3377 words: 21,
3373 strength: "centuries", 3378 strength: "centuries",
3374 } 3379 }
3375 ); 3380 );
@@ -3377,13 +3382,12 @@ it("Shows details about the entered entropy", function(done) {
3377it("Shows details about the entered entropy", function(done) { 3382it("Shows details about the entered entropy", function(done) {
3378 testEntropyFeedback(done, 3383 testEntropyFeedback(done,
3379 // Next test was throwing uncaught error in zxcvbn 3384 // Next test was throwing uncaught error in zxcvbn
3380 // Also tests 451 bits, ie Math.log2(52!)*2 = 225.58 * 2
3381 { 3385 {
3382 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", 3386 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3383 type: "card (full deck, 52 duplicates: ac 2c 3c...)", 3387 type: "card (full deck, 52 duplicates: ac 2c 3c...)",
3384 events: "104", 3388 events: "104",
3385 bits: "499", 3389 bits: "464",
3386 words: 45, 3390 words: 42,
3387 strength: "centuries", 3391 strength: "centuries",
3388 } 3392 }
3389 ); 3393 );
@@ -3395,7 +3399,7 @@ it("Shows details about the entered entropy", function(done) {
3395 entropy: "asAS", 3399 entropy: "asAS",
3396 type: "card (1 duplicate: AS)", 3400 type: "card (1 duplicate: AS)",
3397 events: "2", 3401 events: "2",
3398 bits: "9", 3402 bits: "8",
3399 words: 0, 3403 words: 0,
3400 strength: "less than a second", 3404 strength: "less than a second",
3401 } 3405 }
@@ -3407,7 +3411,7 @@ it("Shows details about the entered entropy", function(done) {
3407 entropy: "ASas", 3411 entropy: "ASas",
3408 type: "card (1 duplicate: as)", 3412 type: "card (1 duplicate: as)",
3409 events: "2", 3413 events: "2",
3410 bits: "9", 3414 bits: "8",
3411 words: 0, 3415 words: 0,
3412 strength: "less than a second", 3416 strength: "less than a second",
3413 } 3417 }
@@ -3420,8 +3424,8 @@ it("Shows details about the entered entropy", function(done) {
3420 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", 3424 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3421 type: "card (1 missing: 9C)", 3425 type: "card (1 missing: 9C)",
3422 events: "51", 3426 events: "51",
3423 bits: "221", 3427 bits: "227",
3424 words: 18, 3428 words: 21,
3425 strength: "centuries", 3429 strength: "centuries",
3426 } 3430 }
3427 ); 3431 );
@@ -3432,7 +3436,7 @@ it("Shows details about the entered entropy", function(done) {
3432 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", 3436 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3433 type: "card (2 missing: 9C 5D)", 3437 type: "card (2 missing: 9C 5D)",
3434 events: "50", 3438 events: "50",
3435 bits: "216", 3439 bits: "222",
3436 words: 18, 3440 words: 18,
3437 strength: "centuries", 3441 strength: "centuries",
3438 } 3442 }
@@ -3444,7 +3448,7 @@ it("Shows details about the entered entropy", function(done) {
3444 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjd kdah2h3h 5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", 3448 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjd kdah2h3h 5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
3445 type: "card (4 missing: 9C 5D QD...)", 3449 type: "card (4 missing: 9C 5D QD...)",
3446 events: "48", 3450 events: "48",
3447 bits: "208", 3451 bits: "212",
3448 words: 18, 3452 words: 18,
3449 strength: "centuries", 3453 strength: "centuries",
3450 } 3454 }
@@ -3457,20 +3461,21 @@ it("Shows details about the entered entropy", function(done) {
3457 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d 8d9d jd kdah2h3h 5h6h7h8h9hthjhqhkh 2s3s4s5s6s7s8s9stsjsqsks", 3461 entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d 8d9d jd kdah2h3h 5h6h7h8h9hthjhqhkh 2s3s4s5s6s7s8s9stsjsqsks",
3458 type: "card", 3462 type: "card",
3459 events: "45", 3463 events: "45",
3460 bits: "195", 3464 bits: "198",
3461 words: 18, 3465 words: 18,
3462 strength: "centuries", 3466 strength: "centuries",
3463 } 3467 }
3464 ); 3468 );
3465}); 3469});
3466it("Shows details about the entered entropy", function(done) { 3470it("Shows details about the entered entropy", function(done) {
3471 // multiple decks does not affect the bits per event
3472 // since the bits are hardcoded in entropy.js
3467 testEntropyFeedback(done, 3473 testEntropyFeedback(done,
3468 // Multiple decks of cards increases bits per event
3469 { 3474 {
3470 entropy: "3d", 3475 entropy: "3d",
3471 events: "1", 3476 events: "1",
3472 bits: "4", 3477 bits: "5",
3473 bitsPerEvent: "4.34", 3478 bitsPerEvent: "4.46",
3474 } 3479 }
3475 ); 3480 );
3476}); 3481});
@@ -3479,8 +3484,8 @@ it("Shows details about the entered entropy", function(done) {
3479 { 3484 {
3480 entropy: "3d3d", 3485 entropy: "3d3d",
3481 events: "2", 3486 events: "2",
3482 bits: "9", 3487 bits: "10",
3483 bitsPerEvent: "4.80", 3488 bitsPerEvent: "4.46",
3484 } 3489 }
3485 ); 3490 );
3486}); 3491});
@@ -3490,7 +3495,7 @@ it("Shows details about the entered entropy", function(done) {
3490 entropy: "3d3d3d", 3495 entropy: "3d3d3d",
3491 events: "3", 3496 events: "3",
3492 bits: "15", 3497 bits: "15",
3493 bitsPerEvent: "5.01", 3498 bitsPerEvent: "4.46",
3494 } 3499 }
3495 ); 3500 );
3496}); 3501});
@@ -3500,7 +3505,7 @@ it("Shows details about the entered entropy", function(done) {
3500 entropy: "3d3d3d3d", 3505 entropy: "3d3d3d3d",
3501 events: "4", 3506 events: "4",
3502 bits: "20", 3507 bits: "20",
3503 bitsPerEvent: "5.14", 3508 bitsPerEvent: "4.46",
3504 } 3509 }
3505 ); 3510 );
3506}); 3511});
@@ -3509,8 +3514,8 @@ it("Shows details about the entered entropy", function(done) {
3509 { 3514 {
3510 entropy: "3d3d3d3d3d", 3515 entropy: "3d3d3d3d3d",
3511 events: "5", 3516 events: "5",
3512 bits: "26", 3517 bits: "25",
3513 bitsPerEvent: "5.22", 3518 bitsPerEvent: "4.46",
3514 } 3519 }
3515 ); 3520 );
3516}); 3521});
@@ -3519,8 +3524,8 @@ it("Shows details about the entered entropy", function(done) {
3519 { 3524 {
3520 entropy: "3d3d3d3d3d3d", 3525 entropy: "3d3d3d3d3d3d",
3521 events: "6", 3526 events: "6",
3522 bits: "31", 3527 bits: "30",
3523 bitsPerEvent: "5.28", 3528 bitsPerEvent: "4.46",
3524 } 3529 }
3525 ); 3530 );
3526}); 3531});
@@ -3529,8 +3534,8 @@ it("Shows details about the entered entropy", function(done) {
3529 { 3534 {
3530 entropy: "3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d", 3535 entropy: "3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d",
3531 events: "33", 3536 events: "33",
3532 bits: "184", 3537 bits: "165",
3533 bitsPerEvent: "5.59", 3538 bitsPerEvent: "4.46",
3534 strength: 'less than a second - Repeats like "abcabcabc" are only slightly harder to guess than "abc"', 3539 strength: 'less than a second - Repeats like "abcabcabc" are only slightly harder to guess than "abc"',
3535 } 3540 }
3536 ); 3541 );
@@ -3581,10 +3586,11 @@ it('Converts very long entropy to very long mnemonics', function(done) {
3581// https://bip32jp.github.io/english/index.html 3586// https://bip32jp.github.io/english/index.html
3582// NOTES: 3587// NOTES:
3583// Is incompatible with: 3588// Is incompatible with:
3589// base 6
3584// base 20 3590// base 20
3585it('Is compatible with bip32jp.github.io', function(done) { 3591it('Is compatible with bip32jp.github.io', function(done) {
3586 var entropy = "543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543"; 3592 var entropy = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
3587 var expectedPhrase = "train then jungle barely whip fiber purpose puppy eagle cloud clump hospital robot brave balcony utility detect estate old green desk skill multiply virus"; 3593 var expectedPhrase = "primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary foster";
3588 driver.findElement(By.css('.use-entropy')) 3594 driver.findElement(By.css('.use-entropy'))
3589 .click(); 3595 .click();
3590 driver.findElement(By.css('.entropy')) 3596 driver.findElement(By.css('.entropy'))