generated from owasp-sbot/OSBot__Repo_Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wired back execution of tests in CI Pipeline
- Loading branch information
Showing
10 changed files
with
339 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 16 additions & 2 deletions
18
deploy/docker/osbot-serverless-flows__integration-tests/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
FROM amazon/aws-lambda-python:3.12 | ||
FROM python:3.12-bookworm | ||
|
||
RUN pip install playwright | ||
RUN playwright install --with-deps chromium | ||
|
||
RUN pip install osbot-aws osbot-fast-api | ||
RUN pip install requests mangum httpx | ||
RUN pip install osbot_playwright | ||
|
||
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 /lambda-adapter /opt/extensions/lambda-adapter | ||
|
||
RUN python --version | ||
ENV PORT=8080 | ||
|
||
WORKDIR /app | ||
|
||
RUN pip install osbot-utils==v1.47.0 | ||
|
||
COPY ../../../osbot_serverless_flows /app/osbot_serverless_flows | ||
|
||
ENV PYTHONPATH="/app" | ||
|
||
CMD ["osbot_serverless_flows.lambdas.handler.run"] | ||
COPY ./deploy/docker/osbot-serverless-flows__playwright/start.sh /app/start.sh | ||
|
||
CMD ["./start.sh"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
from unittest import TestCase | ||
|
||
from osbot_utils.utils.Dev import pprint | ||
from osbot_utils.utils.Misc import list_set | ||
|
||
from osbot_aws.aws.lambda_.Lambda import Lambda | ||
from osbot_aws.aws.session.Session__Kwargs__Lambda import Session__Kwargs__Lambda | ||
from osbot_aws.testing.Temp__Random__AWS_Credentials import Temp__Random__AWS_Credentials | ||
|
||
|
||
|
||
class test__fastapi__via_boto3(TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.function_name = 'function' | ||
cls.endpoint_url = 'http://localhost:5002/' | ||
cls.session_kwargs__lambda = Session__Kwargs__Lambda(endpoint_url=cls.endpoint_url).__locals__() | ||
|
||
def invoke_lambda(self, path): | ||
with Temp__Random__AWS_Credentials(): | ||
with Lambda(name=self.function_name, session_kwargs__lambda=self.session_kwargs__lambda) as _: | ||
payload = { "resource" : "" , | ||
"requestContext": {} , | ||
"httpMethod" : "GET" , | ||
"path" : path } | ||
response = _.invoke(payload) | ||
return response | ||
|
||
def test__root(self): | ||
response = self.invoke_lambda('/') | ||
assert response.get('body' ) == "" | ||
assert response.get('statusCode') == 307 | ||
assert list_set(response.get('headers')) == ['content-length', 'fast-api-request-id', 'location'] | ||
|
||
def test__ping(self): | ||
response = self.invoke_lambda('/info/ping') | ||
assert response.get('body' ) == '{"pong":"42"}' | ||
assert response.get('statusCode') == 200 | ||
assert list_set(response.get('headers')) == ['content-length', 'content-type', 'fast-api-request-id'] | ||
|
||
# from unittest import TestCase | ||
# | ||
# from osbot_utils.utils.Dev import pprint | ||
# from osbot_utils.utils.Misc import list_set | ||
# | ||
# from osbot_aws.aws.lambda_.Lambda import Lambda | ||
# from osbot_aws.aws.session.Session__Kwargs__Lambda import Session__Kwargs__Lambda | ||
# from osbot_aws.testing.Temp__Random__AWS_Credentials import Temp__Random__AWS_Credentials | ||
# | ||
# | ||
# | ||
# class test__fastapi__via_boto3(TestCase): | ||
# @classmethod | ||
# def setUpClass(cls): | ||
# cls.function_name = 'function' | ||
# cls.endpoint_url = 'http://localhost:5002/' | ||
# cls.session_kwargs__lambda = Session__Kwargs__Lambda(endpoint_url=cls.endpoint_url).__locals__() | ||
# | ||
# def invoke_lambda(self, path): | ||
# with Temp__Random__AWS_Credentials(): | ||
# with Lambda(name=self.function_name, session_kwargs__lambda=self.session_kwargs__lambda) as _: | ||
# payload = { "resource" : "" , | ||
# "requestContext": {} , | ||
# "httpMethod" : "GET" , | ||
# "path" : path } | ||
# response = _.invoke(payload) | ||
# return response | ||
# | ||
# def test__root(self): | ||
# response = self.invoke_lambda('/') | ||
# pprint(response) | ||
# return | ||
# assert response.get('body' ) == "" | ||
# assert response.get('statusCode') == 307 | ||
# assert list_set(response.get('headers')) == ['content-length', 'fast-api-request-id', 'location'] | ||
# | ||
# def test__ping(self): | ||
# response = self.invoke_lambda('/info/ping') | ||
# assert response.get('body' ) == '{"pong":"42"}' | ||
# assert response.get('statusCode') == 200 | ||
# assert list_set(response.get('headers')) == ['content-length', 'content-type', 'fast-api-request-id'] | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from unittest import TestCase | ||
from osbot_utils.utils.Files import bytes_to_file, file_exists, file_delete, file_bytes | ||
from osbot_utils.utils.Misc import base64_to_bytes | ||
from osbot_serverless_flows.utils._for_osbot_aws.Http__Remote_Shell import Http__Remote_Shell | ||
|
||
class test__remote_shell_docker(TestCase): | ||
|
||
def setUp(self): | ||
self.port = 5002 | ||
target_url = f'http://localhost:{self.port}/debug/lambda-shell' | ||
self.shell = Http__Remote_Shell(target_url=target_url) | ||
|
||
def test_0_lambda_shell_setup(self): | ||
assert self.shell.ping() == 'pong' | ||
|
||
def test_1_check_osbot_utils_version(self): | ||
|
||
def check_osbot_utils_version(): | ||
from osbot_utils.utils.Version import Version | ||
return Version().value() | ||
|
||
assert self.shell.function(check_osbot_utils_version) == 'v1.47.0' | ||
|
||
|
||
def test_2_playwright__install_chrome(self): | ||
def playwright__install_chrome(): | ||
from osbot_playwright.playwright.api.Playwright_CLI import Playwright_CLI | ||
playwright_cli = Playwright_CLI() | ||
result = playwright_cli.install__chrome() | ||
return f'{result}' | ||
|
||
assert self.shell.function(playwright__install_chrome) == 'True' | ||
|
||
def test_3_playwright__new_page(self): | ||
|
||
def playwright__new_page(): | ||
from osbot_utils.utils.Threads import async_invoke_in_new_loop | ||
from playwright.async_api import async_playwright | ||
|
||
async def run_in_new_loop(): | ||
context = await async_playwright().start() | ||
browser = await context.chromium.launch(args=["--disable-gpu", "--single-process"]) | ||
page = await browser.new_page() | ||
return f'{page}' | ||
|
||
return async_invoke_in_new_loop(run_in_new_loop()) | ||
|
||
assert self.shell.function(playwright__new_page) == "<Page url='about:blank'>" | ||
|
||
def test_4_playwright__open_page(self): | ||
|
||
def playwright__open_page(): | ||
from osbot_utils.utils.Threads import async_invoke_in_new_loop | ||
from playwright.async_api import async_playwright | ||
|
||
async def run_in_new_loop(url): | ||
context = await async_playwright().start() | ||
browser = await context.chromium.launch(args=["--disable-gpu", "--single-process"]) | ||
page = await browser.new_page() | ||
await page.goto(url) | ||
return f'{page}' | ||
|
||
target_url = 'https://www.google.com/404' | ||
return async_invoke_in_new_loop(run_in_new_loop(target_url)) | ||
|
||
assert self.shell.function(playwright__open_page) == "<Page url='https://www.google.com/404'>" | ||
|
||
|
||
def test_5_playwright__page_screenshot(self): | ||
|
||
def playwright__page_screenshot(): | ||
from osbot_utils.utils.Threads import async_invoke_in_new_loop | ||
from playwright.async_api import async_playwright | ||
from osbot_utils.utils.Misc import bytes_to_base64 | ||
|
||
async def run_in_new_loop(url): | ||
context = await async_playwright().start() | ||
browser = await context.chromium.launch(args=["--disable-gpu", "--single-process"]) | ||
page = await browser.new_page() | ||
await page.goto(url) | ||
screenshot = await page.screenshot(full_page=True) | ||
|
||
return bytes_to_base64(screenshot) | ||
|
||
target_url = 'https://www.google.com/404' | ||
target_url = 'https://dev.cyber-boardroom.com/docs' | ||
return async_invoke_in_new_loop(run_in_new_loop(target_url)) | ||
|
||
screenshot_base64 = self.shell.function(playwright__page_screenshot) | ||
screenshot_bytes = base64_to_bytes(screenshot_base64) | ||
screenshot_file = bytes_to_file(bytes=screenshot_bytes, extension='.png') | ||
assert len (screenshot_base64) > 50000 | ||
assert type (screenshot_bytes ) is bytes | ||
assert file_exists(screenshot_file ) is True | ||
assert file_bytes (screenshot_file ) == screenshot_bytes | ||
assert file_delete(screenshot_file ) is True | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.