Skip to content

Commit b041395

Browse files
author
Victoria Hall
committed
remove codeql tests, exclude all dependency locations
1 parent 6f00a89 commit b041395

File tree

5 files changed

+40
-79
lines changed

5 files changed

+40
-79
lines changed

eng/ci/official-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ extends:
4040
os: windows
4141
sdl:
4242
codeql:
43-
excludePathPatterns: '/deps'
43+
# Exclude dependencies from CodeQL analysis
44+
excludePathPatterns: ['/deps', '/build/webhost/bin/workers/python']
4445
codeSignValidation:
4546
enabled: true
4647
break: true

eng/ci/public-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ extends:
4141
compiled:
4242
enabled: true # still only runs for default branch
4343
runSourceLanguagesInSourceAnalysis: true
44-
excludePathPatterns: '/deps'
44+
# Exclude dependencies from CodeQL analysis
45+
excludePathPatterns: ['/deps', '/build/webhost/bin/workers/python']
4546
settings:
4647
skipBuildTagsForGitHubPullRequests: ${{ variables['System.PullRequest.IsFork'] }}
4748
stages:

tests/unittests/test_third_party_http_functions.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -132,48 +132,12 @@ def check_log_print_to_console_stderr(self,
132132
# System logs stderr now exist in host_out
133133
self.assertIn('Secret42', host_out)
134134

135-
def test_raw_body_bytes(self):
136-
parent_dir = pathlib.Path(__file__).parent.parent
137-
image_file = parent_dir / 'unittests/resources/functions.png'
138-
with open(image_file, 'rb') as image:
139-
img = image.read()
140-
encoded_image = base64.b64encode(img).decode('utf-8')
141-
html_img_tag = \
142-
f'<img src="data:image/png;base64,{encoded_image}" alt="PNG Image"/>' # noqa
143-
sanitized_img_len = len(html_img_tag)
144-
r = self.webhost.request('POST', 'raw_body_bytes', data=img,
145-
no_prefix=True)
146-
147-
received_body_len = int(r.headers['body-len'])
148-
self.assertEqual(received_body_len, sanitized_img_len)
149-
150-
encoded_image_data = encoded_image.split(",")[0]
151-
body = base64.b64decode(encoded_image_data)
152-
try:
153-
received_img_file = parent_dir / 'received_img.png'
154-
with open(received_img_file, 'wb') as received_img:
155-
received_img.write(body)
156-
self.assertTrue(filecmp.cmp(received_img_file, image_file))
157-
finally:
158-
if (os.path.exists(received_img_file)):
159-
os.remove(received_img_file)
160-
161135
def test_return_http_no_body(self):
162136
r = self.webhost.request('GET', 'return_http_no_body',
163137
no_prefix=True)
164138
self.assertEqual(r.text, '')
165139
self.assertEqual(r.status_code, 200)
166140

167-
def test_return_http_redirect(self):
168-
r = self.webhost.request('GET', 'return_http_redirect',
169-
no_prefix=True)
170-
self.assertEqual(r.status_code, 200)
171-
self.assertEqual(r.text, '<h1>Hello World™</h1>')
172-
173-
r = self.webhost.request('GET', 'return_http_redirect',
174-
allow_redirects=False, no_prefix=True)
175-
self.assertEqual(r.status_code, 302)
176-
177141
def test_unhandled_error(self):
178142
r = self.webhost.request('GET', 'unhandled_error', no_prefix=True)
179143
self.assertEqual(r.status_code, 500)
@@ -228,10 +192,46 @@ def check_log_hijack_current_event_loop(self,
228192
self.assertIn('parallelly_log_system at disguised_logger',
229193
host_out)
230194

195+
def test_raw_body_bytes(self):
196+
parent_dir = pathlib.Path(__file__).parent.parent
197+
image_file = parent_dir / 'unittests/resources/functions.png'
198+
with open(image_file, 'rb') as image:
199+
img = image.read()
200+
encoded_image = base64.b64encode(img).decode('utf-8')
201+
html_img_tag = \
202+
f'<img src="data:image/png;base64,{encoded_image}" alt="PNG Image"/>' # noqa
203+
sanitized_img_len = len(html_img_tag)
204+
r = self.webhost.request('POST', 'raw_body_bytes', data=img,
205+
no_prefix=True)
206+
207+
received_body_len = int(r.headers['body-len'])
208+
self.assertEqual(received_body_len, sanitized_img_len)
209+
210+
encoded_image_data = encoded_image.split(",")[0]
211+
body = base64.b64decode(encoded_image_data)
212+
try:
213+
received_img_file = parent_dir / 'received_img.png'
214+
with open(received_img_file, 'wb') as received_img:
215+
received_img.write(body)
216+
self.assertTrue(filecmp.cmp(received_img_file, image_file))
217+
finally:
218+
if (os.path.exists(received_img_file)):
219+
os.remove(received_img_file)
220+
231221

232222
class TestWsgiHttpFunctions(
233223
ThirdPartyHttpFunctionsTestBase.TestThirdPartyHttpFunctions):
234224
@classmethod
235225
def get_script_dir(cls):
236226
return UNIT_TESTS_ROOT / 'third_party_http_functions' / 'stein' / \
237227
'wsgi_function'
228+
229+
def test_return_http_redirect(self):
230+
r = self.webhost.request('GET', 'return_http_redirect',
231+
no_prefix=True)
232+
self.assertEqual(r.status_code, 200)
233+
self.assertEqual(r.text, '<h1>Hello World™</h1>')
234+
235+
r = self.webhost.request('GET', 'return_http_redirect',
236+
allow_redirects=False, no_prefix=True)
237+
self.assertEqual(r.status_code, 302)

tests/unittests/third_party_http_functions/stein/asgi_function/function_app.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import asyncio
22
import logging
3-
import re
43
import sys
54
from urllib.request import urlopen
65
import base64
76

87
import azure.functions as func
98
from fastapi import FastAPI, Request, Response
10-
from fastapi.responses import RedirectResponse
119

1210
fast_app = FastAPI()
1311
logger = logging.getLogger("my-function")
@@ -151,33 +149,6 @@ async def return_http(request: Request):
151149
return Response('<h1>Hello World™</h1>', media_type='text/html')
152150

153151

154-
@fast_app.get("/return_http_redirect")
155-
async def return_http_redirect(request: Request, code: str = ''):
156-
# Expected format: 127.0.0.1:<port>
157-
host_and_port = request.url.components[1]
158-
159-
# Validate to ensure it's a valid host and port structure
160-
match = re.match(r'^127\.0\.0\.1:(\d+)$', host_and_port)
161-
if not match:
162-
return Response("Invalid request", status_code=400)
163-
164-
# Validate port is within specific range
165-
port = int(match.group(1))
166-
if port < 50000 or port > 65999:
167-
return Response("Invalid port", status_code=400)
168-
169-
# Validate the code param
170-
allowed_codes = ['', 'testFunctionKey']
171-
if code not in allowed_codes:
172-
return Response("Invalid code", status_code=400)
173-
174-
# Return after all validation succeeds
175-
location = 'return_http?code={}'.format(code)
176-
return RedirectResponse(status_code=302,
177-
url=f"http://{host_and_port}/"
178-
f"{location}")
179-
180-
181152
@fast_app.get("/unhandled_error")
182153
async def unhandled_error():
183154
1 / 0

tests/unittests/third_party_http_functions/stein/wsgi_function/function_app.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
import sys
33
from urllib.request import urlopen
4-
import base64
54

65
import azure.functions as func
76
from flask import Flask, Response, redirect, request, url_for
@@ -58,17 +57,6 @@ def print_logging():
5857
return 'OK-print-logging'
5958

6059

61-
@flask_app.post("/raw_body_bytes")
62-
def raw_body_bytes():
63-
body = request.get_data()
64-
65-
base64_encoded = base64.b64encode(body).decode('utf-8')
66-
html_img_tag = \
67-
f'<img src="data:image/png;base64,{base64_encoded}" alt="PNG Image"/>'
68-
69-
return Response(html_img_tag, headers={'body-len': str(len(html_img_tag))})
70-
71-
7260
@flask_app.get("/return_http_no_body")
7361
def return_http_no_body():
7462
return ''

0 commit comments

Comments
 (0)