From 6d89a2bfcc6da7cc49137a31f8cac4ef0a182746 Mon Sep 17 00:00:00 2001 From: Christopher Phillips Date: Tue, 19 Dec 2023 13:37:38 -0500 Subject: [PATCH] test: final version of snippet script Signed-off-by: Christopher Phillips --- syft/pkg/cataloger/binary/cataloger_test.go | 2 +- .../httpd | Bin 639 -> 652 bytes .../test-fixtures/get-fixture-snippet.sh | 19 +++++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) rename syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/{httpd-2.4.54-3e11fbb6fa371cc9c3e513f49f0ab247b482773cd312248eb86e51251e36fafd-546892-100 => httpd-2.4.54}/httpd (85%) diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index f9dfc0729..be0e2f9a9 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -146,7 +146,7 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) { }, { name: "positive-httpd-2.4.54", - fixtureDir: "test-fixtures/classifiers/positive/httpd-2.4.54-3e11fbb6fa371cc9c3e513f49f0ab247b482773cd312248eb86e51251e36fafd-546892-100", + fixtureDir: "test-fixtures/classifiers/positive/httpd-2.4.54", expected: pkg.Package{ Name: "httpd", Version: "2.4.54", diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/httpd-2.4.54-3e11fbb6fa371cc9c3e513f49f0ab247b482773cd312248eb86e51251e36fafd-546892-100/httpd b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/httpd-2.4.54/httpd similarity index 85% rename from syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/httpd-2.4.54-3e11fbb6fa371cc9c3e513f49f0ab247b482773cd312248eb86e51251e36fafd-546892-100/httpd rename to syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/httpd-2.4.54/httpd index 6290cfc50dad49ffd0a16edcb2f71dd34ccce7eb..d121fdbd61dfcb71d19b3228273e9c72a934fa95 100644 GIT binary patch delta 43 ycmey*(!)Bzfz{a5%G7+LYaOFVV1!dfq)|qWPnBn>pR7`Xr_xeZhR delta 29 kcmeBS{m(MNfz{B=%EVx!YaJtpZ>EWXPgbbG [--length ] [--prefix-length ]" + echo "Usage: $0 [--search-for ] [--length ] [--prefix-length ]" exit 1 } @@ -15,6 +16,11 @@ while [[ $# -gt 0 ]]; do key="$1" case $key in + --search-for) + SEARCH_FOR="$2" + shift # past argument + shift # past value + ;; --length) LENGTH="$2" shift # past argument @@ -28,8 +34,8 @@ while [[ $# -gt 0 ]]; do *) if [ -z "$BINARY_FILE" ]; then BINARY_FILE="$1" - elif [ -z "$PATTERN" ]; then - PATTERN="$1" + elif [ -z "$VERSION" ]; then + VERSION="$1" else echo "Unknown option: $1" usage @@ -40,7 +46,7 @@ while [[ $# -gt 0 ]]; do done # check if binary file and pattern are provided -if [ -z "$BINARY_FILE" ] || [ -z "$PATTERN" ]; then +if [ -z "$BINARY_FILE" ] || [ -z "$VERSION" ]; then usage fi @@ -50,6 +56,9 @@ if ! command -v xxd &> /dev/null; then exit 1 fi + +PATTERN=${SEARCH_FOR:-$VERSION} + PATTERN_RESULTS=$(strings -a -t d "$BINARY_FILE" | grep "$PATTERN") # if there are multiple matches, prompt the user to select one @@ -113,7 +122,7 @@ DATE=$(date) BASE64_PATTERN=$(echo -n "$PATTERN" | base64) FILENAME=$(basename "$BINARY_FILE") INFO=$(file -b "$BINARY_FILE") -OUTPUT_DIRECTORY="classifiers/positive/$FILENAME-$PATTERN-$SHA256-$OFFSET-$LENGTH" +OUTPUT_DIRECTORY="classifiers/positive/$FILENAME-$VERSION" mkdir "$OUTPUT_DIRECTORY" OUTPUT_FILE="$OUTPUT_DIRECTORY/$FILENAME"