ssbc / ssb-keys

keyfile operations for ssb
36 stars 26 forks source link

test loadOrCreate, getTag, unboxKey, unboxBody #75

Closed staltz closed 4 years ago

staltz commented 4 years ago

Previously, public APIs unboxKey, unboxBody, getTag were untested, this PR adds some basic tests for those. Also, loadOrCreate got more tests for various cases when it loads or when it creates.

Code coverage before

------------|---------|----------|---------|---------|----------------------------------------
File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                      
------------|---------|----------|---------|---------|----------------------------------------
All files   |   81.41 |       68 |   86.05 |   87.65 |                                        
 index.js   |      75 |    68.52 |      70 |   79.35 | 42,66-68,73-76,101,145,153-155,159-166 
 sodium.js  |     100 |    83.33 |     100 |     100 | 10                                     
 storage.js |   86.44 |    63.64 |     100 |      96 | 64,76                                  
 util.js    |   91.67 |    66.67 |     100 |     100 | 6-39,42                                
------------|---------|----------|---------|---------|----------------------------------------

Code coverage after

(Hint, only index.js coverage changed)

------------|---------|----------|---------|---------|-------------------
File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------|---------|----------|---------|---------|-------------------
All files   |   90.45 |       74 |     100 |   97.06 |                   
 index.js   |   90.74 |    77.78 |     100 |   96.74 | 42,101,166        
 sodium.js  |     100 |    83.33 |     100 |     100 | 10                
 storage.js |   88.14 |    68.18 |     100 |      96 | 64,76             
 util.js    |   91.67 |    66.67 |     100 |     100 | 6-39,42           
------------|---------|----------|---------|---------|-------------------
davegomez commented 4 years ago

@staltz should we include an assertion to verify the sigil and the tag are properly appended to the id?

"id": "@YSa2zbx07RNKQrrFX1vS5mFN+Pbnul61hd9GGymao1o=.ed25519"
       ^                                            ^^^^^^^^
staltz commented 4 years ago

@davegomez Yes, that can be done in a separate PR.

christianbundy commented 4 years ago

This is fantastic, thanks for using the code cov here.

staltz commented 4 years ago

(I deleted a comment from davegomez just now because it seemed like a mistake. The comment came from his email-to-GitHub interface, contained no message content (maybe he pressed something accidentally), but in the footer of the message there was an unsubscribe link with an auth token in the URL, that auth token is why I decided to delete the message to protect him from that data leaking publicly)

davegomez commented 4 years ago

😮 indeed was a mistake and didn't notice. Thank you @staltz