1Password/spg

CSAll and CSRandom never capitalize first word

jpgoldberg opened this issue · 4 comments

@Sc00bz's fix #8, fixes an off by one bug in the use of the CSAll and CSRandom capitalization schemes.

I've started adding tests for this. And the current code is, indeed, failing a test of CSAll.

--- FAIL: TestWLCapAll (0.00s)
    wordlist_test.go:294: "pondered Dreary Many While Once" doesn't match ^(?:\p{Lu}\pL+)\Q \E(?:(?:\p{Lu}\pL+)\Q \E){4}(?:\p{Lu}\pL+)$
    wordlist_test.go:299: 1 lowercase words in "pondered Dreary Many While Once". Expected 0
    wordlist_test.go:303: 4 uppercase words in "pondered Dreary Many While Once". Expected 5

A test for CSRandom is statistical in nature, so may have to wait.

This bug is what comes of thinking at first we could use 1-indexed arrays. That was something we gave up on long ago, but clearly left some artifacts of that around.

A test for CSRandom could be generate 132 passwords of 5 words and make sure an uppercase and a lowercase appear at least once in each word position. Chances this test fails is 1 in 2^128.68.

Yeah. I was thinking of some test of that nature. (If you look at the existing CSRandom test, I do something similar.

Anyway, as I looked at it I started to wonder whether I could build the binomial distribution calculation into the test or whether I should just precompute and hard code things into the test. And then other things came up. So this test will have to wait.

Fixed with the merger of #8.