17
17
import inspect
18
18
import math # must keep this at top level to test udf referring global import
19
19
import os .path
20
+ import re
20
21
import shutil
21
22
import sys
22
23
import tempfile
@@ -1196,14 +1197,38 @@ def square_num(x):
1196
1197
assert gcf .service_config .service_account_email == gcf_service_account
1197
1198
1198
1199
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 )
1202
1218
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
1207
1232
1208
1233
1209
1234
@pytest .mark .flaky (retries = 2 , delay = 120 )
@@ -2102,36 +2127,40 @@ def generate_stats(row: pandas.Series) -> list[int]:
2102
2127
2103
2128
2104
2129
@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
+ ),
2106
2135
[
2107
2136
pytest .param (
2108
2137
{},
2109
2138
functions_v2 .ServiceConfig .IngressSettings .ALLOW_ALL ,
2110
- FutureWarning ,
2139
+ True ,
2111
2140
id = "no-set" ,
2112
2141
),
2113
2142
pytest .param (
2114
2143
{"cloud_function_ingress_settings" : None },
2115
2144
functions_v2 .ServiceConfig .IngressSettings .ALLOW_ALL ,
2116
- FutureWarning ,
2145
+ True ,
2117
2146
id = "set-none" ,
2118
2147
),
2119
2148
pytest .param (
2120
2149
{"cloud_function_ingress_settings" : "all" },
2121
2150
functions_v2 .ServiceConfig .IngressSettings .ALLOW_ALL ,
2122
- None ,
2151
+ False ,
2123
2152
id = "set-all" ,
2124
2153
),
2125
2154
pytest .param (
2126
2155
{"cloud_function_ingress_settings" : "internal-only" },
2127
2156
functions_v2 .ServiceConfig .IngressSettings .ALLOW_INTERNAL_ONLY ,
2128
- None ,
2157
+ False ,
2129
2158
id = "set-internal-only" ,
2130
2159
),
2131
2160
pytest .param (
2132
2161
{"cloud_function_ingress_settings" : "internal-and-gclb" },
2133
2162
functions_v2 .ServiceConfig .IngressSettings .ALLOW_INTERNAL_AND_GCLB ,
2134
- None ,
2163
+ False ,
2135
2164
id = "set-internal-and-gclb" ,
2136
2165
),
2137
2166
],
@@ -2142,10 +2171,10 @@ def test_remote_function_ingress_settings(
2142
2171
scalars_dfs ,
2143
2172
ingress_settings_args ,
2144
2173
effective_ingress_settings ,
2145
- expected_warning ,
2174
+ expect_default_ingress_setting_warning ,
2146
2175
):
2147
2176
# 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 :
2149
2178
2150
2179
def square (x : int ) -> int :
2151
2180
return x * x
@@ -2154,11 +2183,18 @@ def square(x: int) -> int:
2154
2183
square
2155
2184
)
2156
2185
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
+ )
2162
2198
2163
2199
# Assert that the GCF is created with the intended maximum timeout
2164
2200
gcf = session .cloudfunctionsclient .get_function (
0 commit comments