Skip to content

Commit

Permalink
fix: remove failing codeql tests (#1618)
Browse files Browse the repository at this point in the history
* remove codeql tests, exclude all dependency locations

* Fix excludePathPatterns syntax in build filesformatting

* Update CodeQL exclude paths in CI files

---------

Co-authored-by: Victoria Hall <[email protected]>
  • Loading branch information
hallvictoria and Victoria Hall authored Dec 5, 2024
1 parent 6f00a89 commit 8f730af
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 79 deletions.
3 changes: 2 additions & 1 deletion eng/ci/official-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ extends:
os: windows
sdl:
codeql:
excludePathPatterns: '/deps'
# Exclude dependencies from CodeQL analysis
excludePathPatterns: '/deps,/build'
codeSignValidation:
enabled: true
break: true
Expand Down
3 changes: 2 additions & 1 deletion eng/ci/public-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ extends:
compiled:
enabled: true # still only runs for default branch
runSourceLanguagesInSourceAnalysis: true
excludePathPatterns: '/deps'
# Exclude dependencies from CodeQL analysis
excludePathPatterns: '/deps,/build'
settings:
skipBuildTagsForGitHubPullRequests: ${{ variables['System.PullRequest.IsFork'] }}
stages:
Expand Down
72 changes: 36 additions & 36 deletions tests/unittests/test_third_party_http_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,48 +132,12 @@ def check_log_print_to_console_stderr(self,
# System logs stderr now exist in host_out
self.assertIn('Secret42', host_out)

def test_raw_body_bytes(self):
parent_dir = pathlib.Path(__file__).parent.parent
image_file = parent_dir / 'unittests/resources/functions.png'
with open(image_file, 'rb') as image:
img = image.read()
encoded_image = base64.b64encode(img).decode('utf-8')
html_img_tag = \
f'<img src="data:image/png;base64,{encoded_image}" alt="PNG Image"/>' # noqa
sanitized_img_len = len(html_img_tag)
r = self.webhost.request('POST', 'raw_body_bytes', data=img,
no_prefix=True)

received_body_len = int(r.headers['body-len'])
self.assertEqual(received_body_len, sanitized_img_len)

encoded_image_data = encoded_image.split(",")[0]
body = base64.b64decode(encoded_image_data)
try:
received_img_file = parent_dir / 'received_img.png'
with open(received_img_file, 'wb') as received_img:
received_img.write(body)
self.assertTrue(filecmp.cmp(received_img_file, image_file))
finally:
if (os.path.exists(received_img_file)):
os.remove(received_img_file)

def test_return_http_no_body(self):
r = self.webhost.request('GET', 'return_http_no_body',
no_prefix=True)
self.assertEqual(r.text, '')
self.assertEqual(r.status_code, 200)

def test_return_http_redirect(self):
r = self.webhost.request('GET', 'return_http_redirect',
no_prefix=True)
self.assertEqual(r.status_code, 200)
self.assertEqual(r.text, '<h1>Hello World™</h1>')

r = self.webhost.request('GET', 'return_http_redirect',
allow_redirects=False, no_prefix=True)
self.assertEqual(r.status_code, 302)

def test_unhandled_error(self):
r = self.webhost.request('GET', 'unhandled_error', no_prefix=True)
self.assertEqual(r.status_code, 500)
Expand Down Expand Up @@ -228,10 +192,46 @@ def check_log_hijack_current_event_loop(self,
self.assertIn('parallelly_log_system at disguised_logger',
host_out)

def test_raw_body_bytes(self):
parent_dir = pathlib.Path(__file__).parent.parent
image_file = parent_dir / 'unittests/resources/functions.png'
with open(image_file, 'rb') as image:
img = image.read()
encoded_image = base64.b64encode(img).decode('utf-8')
html_img_tag = \
f'<img src="data:image/png;base64,{encoded_image}" alt="PNG Image"/>' # noqa
sanitized_img_len = len(html_img_tag)
r = self.webhost.request('POST', 'raw_body_bytes', data=img,
no_prefix=True)

received_body_len = int(r.headers['body-len'])
self.assertEqual(received_body_len, sanitized_img_len)

encoded_image_data = encoded_image.split(",")[0]
body = base64.b64decode(encoded_image_data)
try:
received_img_file = parent_dir / 'received_img.png'
with open(received_img_file, 'wb') as received_img:
received_img.write(body)
self.assertTrue(filecmp.cmp(received_img_file, image_file))
finally:
if (os.path.exists(received_img_file)):
os.remove(received_img_file)


class TestWsgiHttpFunctions(
ThirdPartyHttpFunctionsTestBase.TestThirdPartyHttpFunctions):
@classmethod
def get_script_dir(cls):
return UNIT_TESTS_ROOT / 'third_party_http_functions' / 'stein' / \
'wsgi_function'

def test_return_http_redirect(self):
r = self.webhost.request('GET', 'return_http_redirect',
no_prefix=True)
self.assertEqual(r.status_code, 200)
self.assertEqual(r.text, '<h1>Hello World™</h1>')

r = self.webhost.request('GET', 'return_http_redirect',
allow_redirects=False, no_prefix=True)
self.assertEqual(r.status_code, 302)
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import asyncio
import logging
import re
import sys
from urllib.request import urlopen
import base64

import azure.functions as func
from fastapi import FastAPI, Request, Response
from fastapi.responses import RedirectResponse

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


@fast_app.get("/return_http_redirect")
async def return_http_redirect(request: Request, code: str = ''):
# Expected format: 127.0.0.1:<port>
host_and_port = request.url.components[1]

# Validate to ensure it's a valid host and port structure
match = re.match(r'^127\.0\.0\.1:(\d+)$', host_and_port)
if not match:
return Response("Invalid request", status_code=400)

# Validate port is within specific range
port = int(match.group(1))
if port < 50000 or port > 65999:
return Response("Invalid port", status_code=400)

# Validate the code param
allowed_codes = ['', 'testFunctionKey']
if code not in allowed_codes:
return Response("Invalid code", status_code=400)

# Return after all validation succeeds
location = 'return_http?code={}'.format(code)
return RedirectResponse(status_code=302,
url=f"http://{host_and_port}/"
f"{location}")


@fast_app.get("/unhandled_error")
async def unhandled_error():
1 / 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import sys
from urllib.request import urlopen
import base64

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


@flask_app.post("/raw_body_bytes")
def raw_body_bytes():
body = request.get_data()

base64_encoded = base64.b64encode(body).decode('utf-8')
html_img_tag = \
f'<img src="data:image/png;base64,{base64_encoded}" alt="PNG Image"/>'

return Response(html_img_tag, headers={'body-len': str(len(html_img_tag))})


@flask_app.get("/return_http_no_body")
def return_http_no_body():
return ''
Expand Down

0 comments on commit 8f730af

Please sign in to comment.