Skip to content

Commit 1478e1a

Browse files
h-tsuboi918copybara-github
authored andcommitted
ci: ignore OAuth scopes in endpoint check
Merge #6245 Fixes #6238 PiperOrigin-RevId: 954813339
1 parent 8200fae commit 1478e1a

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

scripts/compliance_checks.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,15 @@ def check_cli_import(content: str, filename: str) -> bool:
121121
def check_mtls(content: str, filename: str) -> bool:
122122
if filename in _EXCLUDED_FROM_MTLS:
123123
return True
124-
# Pattern for googleapis: https?://[a-zA-Z0-9.-]+\.googleapis\.com
125-
endpoint_pattern = re.compile(r'https?://[a-zA-Z0-9.-]+\.googleapis\.com')
126-
if endpoint_pattern.search(content):
124+
urls = re.findall(
125+
r'https?://[a-zA-Z0-9.-]+\.googleapis\.com[^"\'\s]*', content
126+
)
127+
non_scope_urls = [
128+
url
129+
for url in urls
130+
if not re.match(r'https?://www\.googleapis\.com/auth(/|$)', url)
131+
]
132+
if non_scope_urls:
127133
return '.mtls.googleapis.com' in content
128134
return True
129135

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from scripts import compliance_checks
16+
17+
18+
def test_check_mtls_ignores_oauth_scope() -> None:
19+
content = 'scope = "https://www.googleapis.com/auth/cloud-platform"\n'
20+
assert compliance_checks.check_mtls(content, 'test_file.py') is True
21+
22+
23+
def test_check_mtls_detects_missing_mtls() -> None:
24+
content = 'endpoint = "https://storage.googleapis.com"\n'
25+
assert compliance_checks.check_mtls(content, 'test_file.py') is False
26+
27+
28+
def test_check_mtls_passes_with_mtls() -> None:
29+
content = (
30+
'endpoint = "https://storage.googleapis.com"\n'
31+
'mtls_endpoint = "https://storage.mtls.googleapis.com"\n'
32+
)
33+
assert compliance_checks.check_mtls(content, 'test_file.py') is True

0 commit comments

Comments
 (0)