Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix system test for mtls #485

Merged
merged 1 commit into from
Feb 10, 2022
Merged
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
80 changes: 69 additions & 11 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def setUpModule():
# Skip the test cases using bigquery, storage and pubsub clients for mTLS testing.
# Bigquery and storage uses http which doesn't have mTLS support, pubsub doesn't
# have mTLS fix released yet.
# We also need to skip HTTP client test cases because mTLS is only available for
# gRPC clients.
skip_for_mtls = pytest.mark.skipif(
Config.use_mtls == "always", reason="Skip the test case for mTLS testing"
)
Expand Down Expand Up @@ -196,7 +198,12 @@ def test_list_entry_with_auditlog(self):

gapic_logger = Config.CLIENT.logger(f"audit-proto-{uuid.uuid1()}")
http_logger = Config.HTTP_CLIENT.logger(f"audit-proto-{uuid.uuid1()}-http")
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
logger.log_proto(audit_struct)

# retrieve log
Expand Down Expand Up @@ -249,7 +256,12 @@ def test_list_entry_with_requestlog(self):

gapic_logger = Config.CLIENT.logger(f"req-proto-{uuid.uuid1()}")
http_logger = Config.CLIENT.logger(f"req-proto-{uuid.uuid1()}-http")
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
logger.log_proto(req_struct)

# retrieve log
Expand Down Expand Up @@ -301,7 +313,12 @@ def test_log_text(self):
TEXT_PAYLOAD = "System test: test_log_text"
gapic_logger = Config.CLIENT.logger(self._logger_name("log_text"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_text_http"))
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
self.to_delete.append(logger)
logger.log_text(TEXT_PAYLOAD)
entries = _list_entries(logger)
Expand All @@ -314,7 +331,12 @@ def test_log_text_with_timestamp(self):
gapic_logger = Config.CLIENT.logger(self._logger_name("log_text_ts"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_text_ts_http"))
now = datetime.utcnow()
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
self.to_delete.append(logger)
logger.log_text(text_payload, timestamp=now)
entries = _list_entries(logger)
Expand All @@ -329,7 +351,12 @@ def test_log_text_with_resource(self):
gapic_logger = Config.CLIENT.logger(self._logger_name("log_text_res"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_text_res_http"))
now = datetime.utcnow()
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
resource = Resource(
type="gae_app",
labels={"module_id": "default", "version_id": "test", "zone": ""},
Expand All @@ -355,7 +382,12 @@ def test_log_text_w_metadata(self):
REQUEST = {"requestMethod": METHOD, "requestUrl": URI, "status": STATUS}
gapic_logger = Config.CLIENT.logger(self._logger_name("log_text_md"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_text_md_http"))
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
self.to_delete.append(logger)

logger.log_text(
Expand All @@ -381,7 +413,12 @@ def test_log_text_w_metadata(self):
def test_log_struct(self):
gapic_logger = Config.CLIENT.logger(self._logger_name("log_struct"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_struct_http"))
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
self.to_delete.append(logger)

logger.log_struct(self.JSON_PAYLOAD)
Expand All @@ -399,7 +436,12 @@ def test_log_struct_w_metadata(self):
REQUEST = {"requestMethod": METHOD, "requestUrl": URI, "status": STATUS}
gapic_logger = Config.CLIENT.logger(self._logger_name("log_struct_md"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_struct_md_http"))
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
self.to_delete.append(logger)

logger.log_struct(
Expand All @@ -423,7 +465,12 @@ def test_log_w_text(self):
TEXT_PAYLOAD = "System test: test_log_w_text"
gapic_logger = Config.CLIENT.logger(self._logger_name("log_w_text"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_w_text"))
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
self.to_delete.append(logger)
logger.log(TEXT_PAYLOAD)
entries = _list_entries(logger)
Expand All @@ -433,7 +480,12 @@ def test_log_w_text(self):
def test_log_w_struct(self):
gapic_logger = Config.CLIENT.logger(self._logger_name("log_w_struct"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_w_struct_http"))
for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
self.to_delete.append(logger)

logger.log(self.JSON_PAYLOAD)
Expand All @@ -446,7 +498,12 @@ def test_log_empty(self):
gapic_logger = Config.CLIENT.logger(self._logger_name("log_empty"))
http_logger = Config.HTTP_CLIENT.logger(self._logger_name("log_empty_http"))

for logger in [gapic_logger, http_logger]:
loggers = (
[gapic_logger]
if Config.use_mtls == "always"
else [gapic_logger, http_logger]
)
for logger in loggers:
self.to_delete.append(logger)

logger.log()
Expand Down Expand Up @@ -829,6 +886,7 @@ def test_update_sink(self):
self.assertEqual(sink.filter_, UPDATED_FILTER)
self.assertEqual(sink.destination, dataset_uri)

@skip_for_mtls
def test_api_equality_list_logs(self):
unique_id = uuid.uuid1()
gapic_logger = Config.CLIENT.logger(f"api-list-{unique_id}")
Expand Down