Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project/GNU/CLI/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ TESTS = \
test/filename.sh \
test/test_mk.sh \
test/test_ffv1.sh \
test/test_policy.sh
test/test_policy.sh \
test/test_invalid_policy.sh

SAMPLES_DIR = test/SampleFiles

Expand Down
62 changes: 62 additions & 0 deletions Project/GNU/CLI/test/test_invalid_policy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh

PATH_SCRIPT=$(dirname "$0")
FILES_DIRECTORY="$PATH_SCRIPT/SampleFiles/ImplementationTestFiles/Matroska"
MC="${PWD}/mediaconch"
MEDIA_FILE="$FILES_DIRECTORY/tiny.mkv"
SCHEMA_FILE="$PATH_SCRIPT/../../../../Source/Resource/schema/MatroskaSchema.xml"

TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/mediaconch-policy.XXXXXX") || exit 1
trap 'rm -rf "$TMP_DIR"' 0

RCODE=0

check_invalid_policy()
{
POLICY_FILE="$1"
EXPECTED_ERROR="$2"
shift 2

"${MC}" "--ImplementationSchema=$SCHEMA_FILE" -p "$POLICY_FILE" "$@" "$MEDIA_FILE" >"$TMP_DIR/stdout" 2>"$TMP_DIR/stderr"
STATUS=$?

if [ "$STATUS" -eq 0 ]; then
echo "NOK: $POLICY_FILE, exited with status 0" >&9
RCODE=1
elif ! grep -F -q "$EXPECTED_ERROR" "$TMP_DIR/stderr"; then
echo "NOK: $POLICY_FILE, expected error not found" >&9
RCODE=1
elif [ -s "$TMP_DIR/stdout" ]; then
echo "NOK: $POLICY_FILE, unexpected standard output" >&9
RCODE=1
else
echo "OK: $POLICY_FILE" >&9
fi
}

printf '%s\n' \
'<?xml version="1.0"?>' \
'<!-- check -- invalid -->' \
'<policy type="and" name="MXF">' \
' <rule name="Container is MXF" value="Format" tracktype="General" occurrence="*" operator="=">MXF</rule>' \
'</policy>' >"$TMP_DIR/bad_comment.xml"

printf '%s\n' \
'<?xml version="1.0"?>' \
'<foo/>' >"$TMP_DIR/not_policy.xml"

: >"$TMP_DIR/empty.xml"

check_invalid_policy "$TMP_DIR/bad_comment.xml" "The schema given cannot be parsed"
check_invalid_policy "$TMP_DIR/bad_comment.xml" "The schema given cannot be parsed" -fx
check_invalid_policy "$TMP_DIR/not_policy.xml" "The XML policy tag accepted are 'policy' or 'rule'"
check_invalid_policy "$TMP_DIR/not_policy.xml" "The XML policy tag accepted are 'policy' or 'rule'" -fj
check_invalid_policy "$TMP_DIR/empty.xml" "The schema does not exist"

check_invalid_policy "$TMP_DIR/bad_comment.xml" "The schema given cannot be parsed" -ox "$TMP_DIR/report.xml"
if [ -e "$TMP_DIR/report.xml" ]; then
echo "NOK: report file created for an invalid policy" >&9
RCODE=1
fi

exit "$RCODE"
8 changes: 6 additions & 2 deletions Source/CLI/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S

cr.display_content = &display_content;

MCL.checker_get_report(cr, &result, error);
if (MCL.checker_get_report(cr, &result, err) < 0)
return CLI_RETURN_ERROR;

MediaInfoLib::String report_mi = ZenLib::Ztring().From_UTF8(result.report);

STRINGOUT(report_mi);
Expand All @@ -460,7 +462,9 @@ void __stdcall Event_CallBackFunction(unsigned char* Data_Content, size_t Data_S

cr.format = format;

MCL.checker_get_report(cr, &result, error);
if (MCL.checker_get_report(cr, &result, err) < 0)
return CLI_RETURN_ERROR;

MediaInfoLib::String report_mi = ZenLib::Ztring().From_UTF8(result.report);

ZenLib::File F;
Expand Down
14 changes: 3 additions & 11 deletions Source/Common/Policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,17 +1004,9 @@ int Policies::policy_get_policy_content(const std::string& policy, const std::ma
ret = p->import_schema_from_memory(policy.c_str(), policy.length(), "");
if (ret < 0)
{
if (p)
delete p;

p = new UnknownPolicy(this, !core->accepts_https());
ret = p->import_schema_from_memory(policy.c_str(), policy.length(), "");
if (ret < 0)
{
err = p->get_error();
delete p;
return -1;
}
err = p->get_error();
delete p;
return -1;
}

ret = policy_get_policy_id(p, opts, xml_policies, xslt_policies, err);
Expand Down
Loading