mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 14:55:00 +00:00
test(python): 3.9, 3.10, 3.11 (#2718)
This commit is contained in:
8
.github/workflows/pull-request.yml
vendored
8
.github/workflows/pull-request.yml
vendored
@@ -13,19 +13,19 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ["3.9"]
|
python-version: ["3.9", "3.10", "3.11"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Install poetry
|
- name: Install poetry
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pipx install poetry
|
pipx install poetry
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
cache: 'poetry'
|
cache: "poetry"
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
poetry install
|
poetry install
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from re import search
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from boto3 import client, session
|
from boto3 import client, session
|
||||||
from moto import mock_s3
|
from moto import mock_s3, mock_s3control
|
||||||
|
|
||||||
from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info
|
from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info
|
||||||
from prowler.providers.common.models import Audit_Metadata
|
from prowler.providers.common.models import Audit_Metadata
|
||||||
@@ -85,6 +85,7 @@ class Test_s3_bucket_policy_public_write_access:
|
|||||||
assert result[0].region == "us-east-1"
|
assert result[0].region == "us-east-1"
|
||||||
|
|
||||||
@mock_s3
|
@mock_s3
|
||||||
|
@mock_s3control
|
||||||
def test_bucket_comply_policy(self):
|
def test_bucket_comply_policy(self):
|
||||||
s3_client_us_east_1 = client("s3", region_name="us-east-1")
|
s3_client_us_east_1 = client("s3", region_name="us-east-1")
|
||||||
bucket_name_us = "bucket_test_us"
|
bucket_name_us = "bucket_test_us"
|
||||||
@@ -97,7 +98,20 @@ class Test_s3_bucket_policy_public_write_access:
|
|||||||
Bucket=bucket_name_us,
|
Bucket=bucket_name_us,
|
||||||
Policy=encryption_policy,
|
Policy=encryption_policy,
|
||||||
)
|
)
|
||||||
from prowler.providers.aws.services.s3.s3_service import S3
|
|
||||||
|
# Generate S3Control Client
|
||||||
|
s3control_client = client("s3control", region_name=AWS_REGION)
|
||||||
|
s3control_client.put_public_access_block(
|
||||||
|
AccountId=AWS_ACCOUNT_NUMBER,
|
||||||
|
PublicAccessBlockConfiguration={
|
||||||
|
"BlockPublicAcls": False,
|
||||||
|
"IgnorePublicAcls": False,
|
||||||
|
"BlockPublicPolicy": False,
|
||||||
|
"RestrictPublicBuckets": False,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
from prowler.providers.aws.services.s3.s3_service import S3, S3Control
|
||||||
|
|
||||||
audit_info = self.set_mocked_audit_info()
|
audit_info = self.set_mocked_audit_info()
|
||||||
|
|
||||||
@@ -108,6 +122,9 @@ class Test_s3_bucket_policy_public_write_access:
|
|||||||
with mock.patch(
|
with mock.patch(
|
||||||
"prowler.providers.aws.services.s3.s3_bucket_policy_public_write_access.s3_bucket_policy_public_write_access.s3_client",
|
"prowler.providers.aws.services.s3.s3_bucket_policy_public_write_access.s3_bucket_policy_public_write_access.s3_client",
|
||||||
new=S3(audit_info),
|
new=S3(audit_info),
|
||||||
|
), mock.patch(
|
||||||
|
"prowler.providers.aws.services.s3.s3_bucket_policy_public_write_access.s3_bucket_policy_public_write_access.s3control_client",
|
||||||
|
new=S3Control(audit_info),
|
||||||
):
|
):
|
||||||
# Test Check
|
# Test Check
|
||||||
from prowler.providers.aws.services.s3.s3_bucket_policy_public_write_access.s3_bucket_policy_public_write_access import (
|
from prowler.providers.aws.services.s3.s3_bucket_policy_public_write_access.s3_bucket_policy_public_write_access import (
|
||||||
@@ -131,6 +148,7 @@ class Test_s3_bucket_policy_public_write_access:
|
|||||||
assert result[0].region == "us-east-1"
|
assert result[0].region == "us-east-1"
|
||||||
|
|
||||||
@mock_s3
|
@mock_s3
|
||||||
|
@mock_s3control
|
||||||
def test_bucket_public_write_policy(self):
|
def test_bucket_public_write_policy(self):
|
||||||
s3_client_us_east_1 = client("s3", region_name="us-east-1")
|
s3_client_us_east_1 = client("s3", region_name="us-east-1")
|
||||||
bucket_name_us = "bucket_test_us"
|
bucket_name_us = "bucket_test_us"
|
||||||
@@ -142,13 +160,29 @@ class Test_s3_bucket_policy_public_write_access:
|
|||||||
Bucket=bucket_name_us,
|
Bucket=bucket_name_us,
|
||||||
Policy=public_write_policy,
|
Policy=public_write_policy,
|
||||||
)
|
)
|
||||||
from prowler.providers.aws.services.s3.s3_service import S3
|
|
||||||
|
# Generate S3Control Client
|
||||||
|
s3control_client = client("s3control", region_name=AWS_REGION)
|
||||||
|
s3control_client.put_public_access_block(
|
||||||
|
AccountId=AWS_ACCOUNT_NUMBER,
|
||||||
|
PublicAccessBlockConfiguration={
|
||||||
|
"BlockPublicAcls": False,
|
||||||
|
"IgnorePublicAcls": False,
|
||||||
|
"BlockPublicPolicy": False,
|
||||||
|
"RestrictPublicBuckets": False,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
from prowler.providers.aws.services.s3.s3_service import S3, S3Control
|
||||||
|
|
||||||
audit_info = self.set_mocked_audit_info()
|
audit_info = self.set_mocked_audit_info()
|
||||||
|
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"prowler.providers.aws.lib.audit_info.audit_info.current_audit_info",
|
"prowler.providers.aws.lib.audit_info.audit_info.current_audit_info",
|
||||||
new=audit_info,
|
new=audit_info,
|
||||||
|
), mock.patch(
|
||||||
|
"prowler.providers.aws.services.s3.s3_bucket_policy_public_write_access.s3_bucket_policy_public_write_access.s3control_client",
|
||||||
|
new=S3Control(audit_info),
|
||||||
):
|
):
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"prowler.providers.aws.services.s3.s3_bucket_policy_public_write_access.s3_bucket_policy_public_write_access.s3_client",
|
"prowler.providers.aws.services.s3.s3_bucket_policy_public_write_access.s3_bucket_policy_public_write_access.s3_client",
|
||||||
|
|||||||
Reference in New Issue
Block a user