telemetry redact refresh token
This commit is contained in:
1 parent
bd92fed0d0
commit
7c6df7173c
3 files changed
+70
-13
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import "pkg:/components/Telemetry/Sentry.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@suite
|
||||
class SentryRedactTests extends Rooibos.BaseTestSuite
|
||||
|
||||
@describe("Sentry.Redact")
|
||||
|
||||
@it("masks refresh_token in a JSON body, keeping the other fields")
|
||||
function jsonRefreshToken()
|
||||
body = `{"client_id":"pub-id","client_secret":"pub-secret","refresh_token":"1//0secret-Ab_c.d","grant_type":"refresh_token"}`
|
||||
expected = `{"client_id":"pub-id","client_secret":"pub-secret","refresh_token":"<REDACTED>","grant_type":"refresh_token"}`
|
||||
m.assertEqual(Sentry.Redact(body), expected)
|
||||
end function
|
||||
|
||||
@it("masks refresh_token inside a longer telemetered message, keeping the error and URL")
|
||||
function embeddedInMessage()
|
||||
message = "POST https://www.youtube.com/o/oauth2/token failed: HTTP 400" + Chr(10) + ` -d '{"refresh_token":"1//0secret","grant_type":"refresh_token"}'`
|
||||
expected = "POST https://www.youtube.com/o/oauth2/token failed: HTTP 400" + Chr(10) + ` -d '{"refresh_token":"<REDACTED>","grant_type":"refresh_token"}'`
|
||||
m.assertEqual(Sentry.Redact(message), expected)
|
||||
end function
|
||||
|
||||
@it("does not treat refresh_token used as a value as a key")
|
||||
function secretNameAsValue()
|
||||
body = `{"grant_type":"refresh_token"}`
|
||||
m.assertEqual(Sentry.Redact(body), body)
|
||||
end function
|
||||
|
||||
@it("masks an Authorization header")
|
||||
function authHeader()
|
||||
m.assertEqual(Sentry.Redact("visitorId: abc" + Chr(10) + "Authorization: Bearer ya29.secret"), "visitorId: abc" + Chr(10) + "Authorization: <REDACTED>")
|
||||
end function
|
||||
|
||||
@it("leaves a body without secrets untouched")
|
||||
function noSecrets()
|
||||
body = `{"screen_ids":"abc","count":0}`
|
||||
m.assertEqual(Sentry.Redact(body), body)
|
||||
end function
|
||||
|
||||
@it("passes non-string input through unchanged")
|
||||
function nonString()
|
||||
m.assertInvalid(Sentry.Redact(invalid))
|
||||
m.assertEqual(Sentry.Redact(42), 42)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user