MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.63k stars 138 forks source link

feat/logging-take-2 #159

Closed MasterKale closed 3 years ago

MasterKale commented 3 years ago

Taking another stab at implementing logging output in MetadataService, this time using the debug library directly.

Here's what it looks like when the example project adds the new DEBUG=SimpleWebAuthn:* environment variable:

πŸš€ Server ready at http://localhost:8000 (127.0.0.1:8000)
  SimpleWebAuthn:MetadataService MetadataService is REFRESHING +0ms
  SimpleWebAuthn:MetadataService Cached 21 local statements +0ms
  SimpleWebAuthn:MetadataService Could not download BLOB from https://mds3.certinfra.fidoalliance.org/execute/07f2d7b0561be25d17830ccb0a28bfb3ffb661e40c2531805a5701a54ea53737: Error: BLOB certificate path could not be validated: Subject issuer did not match issuer subject
    at BaseMetadataService.downloadBlob (/Users/matt/Repos/simplewebauthn/packages/server/src/services/metadataService.ts:236:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async BaseMetadataService.initialize (/Users/matt/Repos/simplewebauthn/packages/server/src/services/metadataService.ts:115:11) +583ms
  SimpleWebAuthn:MetadataService Could not download BLOB from https://mds3.certinfra.fidoalliance.org/execute/14dfc54b3a0d921dd77d90d8c9143ba5c77ebe5bbc0aed0424f16454356f0b9c: Error: BLOB signature could not be verified
    at BaseMetadataService.downloadBlob (/Users/matt/Repos/simplewebauthn/packages/server/src/services/metadataService.ts:251:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async BaseMetadataService.initialize (/Users/matt/Repos/simplewebauthn/packages/server/src/services/metadataService.ts:115:11) +1s
  SimpleWebAuthn:MetadataService Could not download BLOB from https://mds3.certinfra.fidoalliance.org/execute/8165f3b81c69edc164898800338913c0950751e22e5e4e0818f6b375b49518ed: Error: BLOB certificate path could not be validated: Found revoked certificate in certificate path
    at BaseMetadataService.downloadBlob (/Users/matt/Repos/simplewebauthn/packages/server/src/services/metadataService.ts:236:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async BaseMetadataService.initialize (/Users/matt/Repos/simplewebauthn/packages/server/src/services/metadataService.ts:115:11) +1s
  SimpleWebAuthn:MetadataService Could not download BLOB from https://mds3.certinfra.fidoalliance.org/execute/defec195094d0400ef9979aae517e188ef7bb215d25c71a668375313157e6e8f: Error: BLOB certificate path could not be validated: Subject issuer did not match issuer subject
    at BaseMetadataService.downloadBlob (/Users/matt/Repos/simplewebauthn/packages/server/src/services/metadataService.ts:236:13)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async BaseMetadataService.initialize (/Users/matt/Repos/simplewebauthn/packages/server/src/services/metadataService.ts:115:11) +400ms
  SimpleWebAuthn:MetadataService Cached 100 statements from 1 metadata servers +0ms
  SimpleWebAuthn:MetadataService MetadataService is READY +0ms
πŸ” FIDO Conformance routes ready

And if the console supports colors then it looks even nicer:

Screen Shot 2021-09-09 at 9 52 59 PM

I'm pretty satisfied with how simple this will make it for library consumers to get logging output out of this library, so after this merges I'll consider adding more logging to other parts of the library to help with debugging if an errors occur. That'll likely involve a follow-up diff.