From 6d6d3288cf95b5b47441de7a91af4708947ed694 Mon Sep 17 00:00:00 2001 From: Denzel Farmer Date: Tue, 26 Mar 2024 21:02:10 -0400 Subject: [PATCH] Update and fix conditionals tests --- pytests/php-samples/conditions_field_get.php | 13 ++++++- pytests/php-samples/conditions_field_set.php | 12 +++++- .../php-samples/conditions_two_calls_test.php | 37 +++++++++++++++---- pytests/test_conditions_fragments.py | 16 ++++---- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/pytests/php-samples/conditions_field_get.php b/pytests/php-samples/conditions_field_get.php index f05f4ec..8ff7346 100755 --- a/pytests/php-samples/conditions_field_get.php +++ b/pytests/php-samples/conditions_field_get.php @@ -1,5 +1,14 @@ logtypeget; -print($readval); +$readval = $data->getfield; + ?> diff --git a/pytests/php-samples/conditions_field_set.php b/pytests/php-samples/conditions_field_set.php index 5393815..6dd4c62 100755 --- a/pytests/php-samples/conditions_field_set.php +++ b/pytests/php-samples/conditions_field_set.php @@ -1,5 +1,14 @@ logtypeput = "NEWVAL"; -print($data->logtypeput); +$data->setfield = "NEWVAL"; ?> diff --git a/pytests/php-samples/conditions_two_calls_test.php b/pytests/php-samples/conditions_two_calls_test.php index b539530..ef722f9 100755 --- a/pytests/php-samples/conditions_two_calls_test.php +++ b/pytests/php-samples/conditions_two_calls_test.php @@ -1,16 +1,37 @@ hey(); -// -// this is currently caught by our analysis -// -$data->ola()->to_you_to(); +$data->lone_call(); + + +$data2 = unserialize($object); // POI bug +$data2->first_call()->second_call(); ?> diff --git a/pytests/test_conditions_fragments.py b/pytests/test_conditions_fragments.py index f216058..53d9540 100644 --- a/pytests/test_conditions_fragments.py +++ b/pytests/test_conditions_fragments.py @@ -8,15 +8,14 @@ @pytest.mark.datafiles(SAMPLES_DIR / CONDITIONS_FIELD_GET_NAME) -@pytest.mark.skip() def test_conditions_field_get(datafiles, tmp_path): fragment_path = datafiles / CONDITIONS_FIELD_GET_NAME results = do_analysis(fragment_path, tmp_path) expected_result = [ - {'filename': 'conditions_field_get.php', 'lineNumber': 6, - 'allowedTypes': [''], 'allowedClasses': []} + {'filename': 'conditions_field_get.php', 'lineNumber': 15, + 'allowedTypes': ['', 'SomeClass'], 'allowedClasses': ['SomeClass']} ] assert compare_results(expected_result, results) @@ -26,14 +25,13 @@ def test_conditions_field_get(datafiles, tmp_path): @pytest.mark.datafiles(SAMPLES_DIR / CONDITIONS_FIELD_SET_NAME) -@pytest.mark.skip() def test_conditions_field_set(datafiles, tmp_path): fragment_path = datafiles / CONDITIONS_FIELD_SET_NAME results = do_analysis(fragment_path, tmp_path) expected_result = [{'filename': 'conditions_field_set.php', - 'lineNumber': 6, 'allowedTypes': [''], 'allowedClasses': []}] + 'lineNumber': 15, 'allowedTypes': ['SomeClass'], 'allowedClasses': ['SomeClass']}] assert compare_results(expected_result, results) @@ -57,20 +55,22 @@ def test_conditions_test(datafiles, tmp_path): @pytest.mark.datafiles(SAMPLES_DIR / CONDITIONS_TWO_CALLS_TEST_NAME) -@pytest.mark.skip() def test_conditions_two_calls_test(datafiles, tmp_path): fragment_path = datafiles / CONDITIONS_TWO_CALLS_TEST_NAME results = do_analysis(fragment_path, tmp_path) expected_result = [{'filename': 'conditions_two_calls_test.php', - 'lineNumber': 6, 'allowedTypes': ['', ''], 'allowedClasses': []}] - + 'lineNumber': 30, 'allowedTypes': ['LoneClass'], 'allowedClasses': ['LoneClass']}, + {'filename': 'conditions_two_calls_test.php', 'lineNumber': 34, + 'allowedTypes': ['FirstCall'], 'allowedClasses': ['FirstCall']} + ] assert compare_results(expected_result, results) CONDITIONALS_TEST_NAME = "conditionals_test.php" + @pytest.mark.datafiles(SAMPLES_DIR / CONDITIONALS_TEST_NAME) def test_conditionals(datafiles, tmp_path): fragment_path = datafiles / CONDITIONALS_TEST_NAME