I've always wanted to apply strong type systems to this problem – wrapping sensitive data in types that do not have the ability to be printed to logs would theoretically allow you to know after type-checking that passwords can't be output to logs. However again I think this is wishful thinking as a password needs to be sent somewhere at some point, and that creates places where issues can occur.
There are alternatives to avoid this, on the same model of SSH key authentication where the secret stays on the client-side.
Nothing prevents them from using a password to derive a private key using PBKDF2 in client-side and answer to a specific challenge.
Our tests would set up the app's full context, get a hook into the logging framework to watch for log statements, then make requests to the service containing a set of dummy credentials, like { username: "foo", password: "bar" }. If a log statement containing "foo" or "bar" was detected the test failed.
It's not going to catch every type of issue, but at least some potential footguns can be preventing this way.
This way it would blow up on the test that is leaking the credential so you could track it right down and it would transparently apply to all current and future unit tests without any more effort.
Anybody ever do something like that? How effective it would be probably depends on unit test coverage.
You could also probably just do the same thing in prod with a dummy user.