Skip to content

Commit 9ebb3a2

Browse files
committed
adjust the expect warnings in the ingress settings and service account
1 parent 84e02a7 commit 9ebb3a2

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

bigframes/functions/_function_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def remote_function(
458458
msg = bfe.format_message(
459459
"You have not explicitly set a user-managed `cloud_function_service_account`. "
460460
"Using the default Compute Engine service account. "
461-
"To use Bigframes 2.0, please explicitly set `cloud_function_service_account` "
461+
"In BigFrames 2.0, you would have to explicitly set `cloud_function_service_account` "
462462
'either to a user-managed service account (preferred) or to `"default"` '
463463
"to use the Compute Engine service account (discouraged). "
464464
"See, https://cloud.google.com/functions/docs/securing/function-identity."

tests/system/large/functions/test_remote_function.py

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import inspect
1818
import math # must keep this at top level to test udf referring global import
1919
import os.path
20+
import re
2021
import shutil
2122
import sys
2223
import tempfile
@@ -1196,14 +1197,38 @@ def square_num(x):
11961197
assert gcf.service_config.service_account_email == gcf_service_account
11971198

11981199

1199-
def test_remote_function_warns_default_cloud_function_service_account():
1200-
project = "bigframes-dev-perf"
1201-
rf_session = bigframes.Session(context=bigframes.BigQueryOptions(project=project))
1200+
@pytest.mark.parametrize(
1201+
("remote_function_args"),
1202+
[
1203+
pytest.param(
1204+
{},
1205+
id="no-set",
1206+
),
1207+
pytest.param(
1208+
{"cloud_function_service_account": None},
1209+
id="set-none",
1210+
),
1211+
],
1212+
)
1213+
def test_remote_function_warns_default_cloud_function_service_account(
1214+
session, remote_function_args
1215+
):
1216+
with pytest.warns(FutureWarning) as record:
1217+
session.remote_function(**remote_function_args)
12021218

1203-
with pytest.warns(FutureWarning, match="You have not explicitly set a"):
1204-
rf_session.remote_function(
1205-
cloud_function_service_account=None, # Explicitly omit service account.
1206-
)
1219+
len(
1220+
[
1221+
warn
1222+
for warn in record
1223+
if re.search(
1224+
(
1225+
"You have not explicitly set a user-managed.*Using the default Compute Engine.*service account"
1226+
),
1227+
warn.message.args[0],
1228+
re.DOTALL,
1229+
)
1230+
]
1231+
) == 1
12071232

12081233

12091234
@pytest.mark.flaky(retries=2, delay=120)
@@ -2102,36 +2127,40 @@ def generate_stats(row: pandas.Series) -> list[int]:
21022127

21032128

21042129
@pytest.mark.parametrize(
2105-
("ingress_settings_args", "effective_ingress_settings", "expected_warning"),
2130+
(
2131+
"ingress_settings_args",
2132+
"effective_ingress_settings",
2133+
"expect_default_ingress_setting_warning",
2134+
),
21062135
[
21072136
pytest.param(
21082137
{},
21092138
functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL,
2110-
FutureWarning,
2139+
True,
21112140
id="no-set",
21122141
),
21132142
pytest.param(
21142143
{"cloud_function_ingress_settings": None},
21152144
functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL,
2116-
FutureWarning,
2145+
True,
21172146
id="set-none",
21182147
),
21192148
pytest.param(
21202149
{"cloud_function_ingress_settings": "all"},
21212150
functions_v2.ServiceConfig.IngressSettings.ALLOW_ALL,
2122-
None,
2151+
False,
21232152
id="set-all",
21242153
),
21252154
pytest.param(
21262155
{"cloud_function_ingress_settings": "internal-only"},
21272156
functions_v2.ServiceConfig.IngressSettings.ALLOW_INTERNAL_ONLY,
2128-
None,
2157+
False,
21292158
id="set-internal-only",
21302159
),
21312160
pytest.param(
21322161
{"cloud_function_ingress_settings": "internal-and-gclb"},
21332162
functions_v2.ServiceConfig.IngressSettings.ALLOW_INTERNAL_AND_GCLB,
2134-
None,
2163+
False,
21352164
id="set-internal-and-gclb",
21362165
),
21372166
],
@@ -2142,10 +2171,10 @@ def test_remote_function_ingress_settings(
21422171
scalars_dfs,
21432172
ingress_settings_args,
21442173
effective_ingress_settings,
2145-
expected_warning,
2174+
expect_default_ingress_setting_warning,
21462175
):
21472176
# Verify the function raises the expected security warning message.
2148-
with warnings.catch_warnings(record=True) as w:
2177+
with warnings.catch_warnings(record=True) as record:
21492178

21502179
def square(x: int) -> int:
21512180
return x * x
@@ -2154,11 +2183,18 @@ def square(x: int) -> int:
21542183
square
21552184
)
21562185

2157-
if expected_warning is not None:
2158-
assert issubclass(w[0].category, FutureWarning)
2159-
assert "Consider using 'internal-only' for enhanced security." in str(
2160-
w[0].message
2161-
)
2186+
default_ingress_setting_warnings = [
2187+
warn
2188+
for warn in record
2189+
if isinstance(warn.message, FutureWarning)
2190+
and "`cloud_function_ingress_settings` are set to 'all' by default"
2191+
in warn.message.args[0]
2192+
and "will change to 'internal-only' for enhanced security in future"
2193+
in warn.message.args[0]
2194+
]
2195+
assert len(default_ingress_setting_warnings) == (
2196+
1 if expect_default_ingress_setting_warning else 0
2197+
)
21622198

21632199
# Assert that the GCF is created with the intended maximum timeout
21642200
gcf = session.cloudfunctionsclient.get_function(

0 commit comments

Comments
 (0)