mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 23:05:05 +00:00
fix(output_bucket): Use full path for -o option with output to S3 bucket (#1854)
Co-authored-by: sergargar <sergargar@users.noreply.github.com> Co-authored-by: Pepe Fagoaga <pepe@verica.io>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import pathlib
|
||||
from os import path, remove
|
||||
from os import getcwd, path, remove
|
||||
from unittest import mock
|
||||
|
||||
import boto3
|
||||
@@ -336,10 +335,8 @@ class Test_Outputs:
|
||||
client = boto3.client("s3")
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
# Create mock csv output file
|
||||
fixtures_dir = "fixtures"
|
||||
output_directory = (
|
||||
f"{pathlib.Path().absolute()}/tests/lib/outputs/{fixtures_dir}"
|
||||
)
|
||||
fixtures_dir = "tests/lib/outputs/fixtures"
|
||||
output_directory = getcwd() + "/" + fixtures_dir
|
||||
output_mode = "csv"
|
||||
filename = f"prowler-output-{input_audit_info.audited_account}"
|
||||
# Send mock csv file to mock S3 Bucket
|
||||
@@ -359,6 +356,59 @@ class Test_Outputs:
|
||||
== "binary/octet-stream"
|
||||
)
|
||||
|
||||
@mock_s3
|
||||
def test_send_to_s3_bucket_custom_directory(self):
|
||||
# Create mock session
|
||||
session = boto3.session.Session(
|
||||
region_name="us-east-1",
|
||||
)
|
||||
# Create mock audit_info
|
||||
input_audit_info = AWS_Audit_Info(
|
||||
original_session=None,
|
||||
audit_session=session,
|
||||
audited_account=AWS_ACCOUNT_ID,
|
||||
audited_identity_arn="test-arn",
|
||||
audited_user_id="test",
|
||||
audited_partition="aws",
|
||||
profile="default",
|
||||
profile_region="eu-west-1",
|
||||
credentials=None,
|
||||
assumed_role_info=None,
|
||||
audited_regions=["eu-west-2", "eu-west-1"],
|
||||
organizations_metadata=None,
|
||||
audit_resources=None,
|
||||
)
|
||||
# Creat mock bucket
|
||||
bucket_name = "test_bucket"
|
||||
client = boto3.client("s3")
|
||||
client.create_bucket(Bucket=bucket_name)
|
||||
# Create mock csv output file
|
||||
fixtures_dir = "fixtures"
|
||||
output_directory = f"tests/lib/outputs/{fixtures_dir}"
|
||||
output_mode = "csv"
|
||||
filename = f"prowler-output-{input_audit_info.audited_account}"
|
||||
# Send mock csv file to mock S3 Bucket
|
||||
send_to_s3_bucket(
|
||||
filename,
|
||||
output_directory,
|
||||
output_mode,
|
||||
bucket_name,
|
||||
input_audit_info.audit_session,
|
||||
)
|
||||
# Check if the file has been sent by checking its content type
|
||||
assert (
|
||||
client.get_object(
|
||||
Bucket=bucket_name,
|
||||
Key=output_directory
|
||||
+ "/"
|
||||
+ output_mode
|
||||
+ "/"
|
||||
+ filename
|
||||
+ csv_file_suffix,
|
||||
)["ContentType"]
|
||||
== "binary/octet-stream"
|
||||
)
|
||||
|
||||
def test_extract_findings_statistics_different_resources(self):
|
||||
finding_1 = mock.MagicMock()
|
||||
finding_1.status = "PASS"
|
||||
|
||||
Reference in New Issue
Block a user