Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -596,16 +596,20 @@ def test_logging_enabled(self, client, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
# the body of the request should be JSON
body = json.loads(section)
if body["provider"] == "Test":
mock_handler.close()
return
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON
pass

mock_handler.close()
assert False, "Expected request body wasn't logged"

@logging_disabled()
Expand All @@ -622,15 +626,21 @@ def test_logging_disabled(self, client, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
assert body["provider"] != "Test", "Client request body was logged"
# the body of the request should be JSON
body = json.loads(section)
if body["provider"] == "Test":
mock_handler.close()
assert False, "Client request body was logged"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this line follow with return instead of closing the handler again in line642?

Copy link
Member Author

@mccoyp mccoyp Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert False will stop execution of the test, so we won't reach line 642 if we get here -- which is why we have this second mock_handler.close() preceding the assert False

except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON
pass

mock_handler.close()

@only_2016_10_01()
@client_setup
def test_models(self, client, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,16 +602,20 @@ async def test_logging_enabled(self, client, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
# the body of the request should be JSON
body = json.loads(section)
if body["provider"] == "Test":
mock_handler.close()
return
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON
pass

mock_handler.close()
assert False, "Expected request body wasn't logged"

@logging_disabled()
Expand All @@ -628,15 +632,21 @@ async def test_logging_disabled(self, client, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
assert body["provider"] != "Test", "Client request body was logged"
# the body of the request should be JSON
body = json.loads(section)
if body["provider"] == "Test":
mock_handler.close()
assert False, "Client request body was logged"
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON
pass

mock_handler.close()

@all_api_versions()
@client_setup
async def test_get_certificate_version(self, client, **kwargs):
Expand Down
28 changes: 19 additions & 9 deletions sdk/keyvault/azure-keyvault-keys/tests/test_key_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,21 @@ def test_logging_enabled(self, client, is_hsm, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
# the body of the request should be JSON
body = json.loads(section)
expected_kty = "RSA-HSM" if is_hsm else "RSA"
if body["kty"] == expected_kty:
mock_handler.close()
return
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON or has no kty property
pass

mock_handler.close()
assert False, "Expected request body wasn't logged"

@logging_disabled()
Expand All @@ -453,16 +457,22 @@ def test_logging_disabled(self, client, is_hsm, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
# the body of the request should be JSON
body = json.loads(section)
expected_kty = "RSA-HSM" if is_hsm else "RSA"
assert body["kty"] != expected_kty, "Client request body was logged"
if body["kty"] == expected_kty:
mock_handler.close()
assert False, "Client request body was logged"
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON or has no kty property
pass

mock_handler.close()

@only_hsm_7_3_preview()
@client_setup
def test_get_random_bytes(self, client, **kwargs):
Expand Down
28 changes: 19 additions & 9 deletions sdk/keyvault/azure-keyvault-keys/tests/test_keys_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,21 @@ async def test_logging_enabled(self, client, is_hsm, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
# the body of the request should be JSON
body = json.loads(section)
expected_kty = "RSA-HSM" if is_hsm else "RSA"
if body["kty"] == expected_kty:
mock_handler.close()
return
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON or has no kty property
pass

mock_handler.close()
assert False, "Expected request body wasn't logged"

@logging_disabled()
Expand All @@ -450,16 +454,22 @@ async def test_logging_disabled(self, client, is_hsm, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
# the body of the request should be JSON
body = json.loads(section)
expected_kty = "RSA-HSM" if is_hsm else "RSA"
assert body["kty"] != expected_kty, "Client request body was logged"
if body["kty"] == expected_kty:
mock_handler.close()
assert False, "Client request body was logged"
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON or has no kty property
pass

mock_handler.close()

@only_hsm_7_3_preview()
@client_setup
async def test_get_random_bytes(self, client, **kwargs):
Expand Down
26 changes: 18 additions & 8 deletions sdk/keyvault/azure-keyvault-secrets/tests/test_secrets_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,20 @@ async def test_logging_enabled(self, client, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
# the body of the request should be JSON
body = json.loads(section)
if body["value"] == "secret-value":
mock_handler.close()
return
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON
pass

mock_handler.close()
assert False, "Expected request body wasn't logged"

@logging_disabled()
Expand All @@ -317,15 +321,21 @@ async def test_logging_disabled(self, client, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
assert body["value"] != "secret-value", "Client request body was logged"
# the body of the request should be JSON
body = json.loads(section)
if body["value"] == "secret-value":
mock_handler.close()
assert False, "Client request body was logged"
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
pass

mock_handler.close()


def test_service_headers_allowed_in_logs():
service_headers = {"x-ms-keyvault-network-info", "x-ms-keyvault-region", "x-ms-keyvault-service-version"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,20 @@ def test_logging_enabled(self, client, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
# the body of the request should be JSON
body = json.loads(section)
if body["value"] == "secret-value":
mock_handler.close()
return
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
# this means the request section is not JSON
pass

mock_handler.close()
assert False, "Expected request body wasn't logged"

@logging_disabled()
Expand All @@ -323,15 +327,21 @@ def test_logging_disabled(self, client, **kwargs):

for message in mock_handler.messages:
if message.levelname == "DEBUG" and message.funcName == "on_request":
messages_request = message.message.split("/n")
for m in messages_request:
# parts of the request are logged on new lines in a single message
request_sections = message.message.split("/n")
for section in request_sections:
try:
body = json.loads(m)
assert body["value"] != "secret-value", "Client request body was logged"
# the body of the request should be JSON
body = json.loads(section)
if body["value"] == "secret-value":
mock_handler.close()
assert False, "Client request body was logged"
except (ValueError, KeyError):
# this means the message is not JSON or has no kty property
pass

mock_handler.close()


def test_service_headers_allowed_in_logs():
service_headers = {"x-ms-keyvault-network-info", "x-ms-keyvault-region", "x-ms-keyvault-service-version"}
Expand Down