Log token with sha1
By logging the sha1 hash of the token, it can be tracked through different services. Closes-bug: #1329301 Change-Id: I9c338f6a418ab8dd34dbaaf918b0ea6e9cbe79d7
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import functools
|
import functools
|
||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
@@ -122,7 +123,10 @@ class Session(object):
|
|||||||
secure_headers = ('authorization', 'x-auth-token',
|
secure_headers = ('authorization', 'x-auth-token',
|
||||||
'x-subject-token',)
|
'x-subject-token',)
|
||||||
if header[0].lower() in secure_headers:
|
if header[0].lower() in secure_headers:
|
||||||
return (header[0], 'TOKEN_REDACTED')
|
token_hasher = hashlib.sha1()
|
||||||
|
token_hasher.update(header[1].encode('utf-8'))
|
||||||
|
token_hash = token_hasher.hexdigest()
|
||||||
|
return (header[0], '{SHA1}%s' % token_hash)
|
||||||
return header
|
return header
|
||||||
|
|
||||||
@utils.positional()
|
@utils.positional()
|
||||||
|
@@ -168,7 +168,7 @@ class SessionTests(utils.TestCase):
|
|||||||
# Assert that response headers contains actual values and
|
# Assert that response headers contains actual values and
|
||||||
# only debug logs has been masked
|
# only debug logs has been masked
|
||||||
for k, v in six.iteritems(security_headers):
|
for k, v in six.iteritems(security_headers):
|
||||||
self.assertIn('%s: TOKEN_REDACTED' % k, self.logger.output)
|
self.assertIn('%s: {SHA1}' % k, self.logger.output)
|
||||||
self.assertEqual(v, resp.headers[k])
|
self.assertEqual(v, resp.headers[k])
|
||||||
self.assertNotIn(v, self.logger.output)
|
self.assertNotIn(v, self.logger.output)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user