From 294e54a6d12bb557595b9ac2aa53d4f080dd9144 Mon Sep 17 00:00:00 2001 From: HackerShark Date: Wed, 16 Oct 2024 10:37:02 -0400 Subject: [PATCH 1/8] fixing the logic for the longitude and latitude being 0. Now it won't error on those values Signed-off-by: HackerShark --- stix2/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stix2/base.py b/stix2/base.py index 3ff01d98..078a7cb0 100644 --- a/stix2/base.py +++ b/stix2/base.py @@ -103,7 +103,8 @@ def _check_properties_dependency(self, list_of_properties, list_of_dependent_pro failed_dependency_pairs = [] for p in list_of_properties: for dp in list_of_dependent_properties: - if not self.get(p) and self.get(dp): + if self.get(p) is None and self.get(dp) is not None: + # if not self.get(p) and self.get(dp): failed_dependency_pairs.append((p, dp)) if failed_dependency_pairs: raise DependentPropertiesError(self.__class__, failed_dependency_pairs) From 4a659b56bcc4fe6baa43e3abfd1e0579befa39ed Mon Sep 17 00:00:00 2001 From: HackerShark Date: Thu, 17 Oct 2024 13:27:31 -0400 Subject: [PATCH 2/8] removed commented line in base.py. added tests for 0 value longitude and latitude Signed-off-by: HackerShark --- stix2/base.py | 1 - stix2/test/v21/test_location.py | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/stix2/base.py b/stix2/base.py index 078a7cb0..6511f805 100644 --- a/stix2/base.py +++ b/stix2/base.py @@ -104,7 +104,6 @@ def _check_properties_dependency(self, list_of_properties, list_of_dependent_pro for p in list_of_properties: for dp in list_of_dependent_properties: if self.get(p) is None and self.get(dp) is not None: - # if not self.get(p) and self.get(dp): failed_dependency_pairs.append((p, dp)) if failed_dependency_pairs: raise DependentPropertiesError(self.__class__, failed_dependency_pairs) diff --git a/stix2/test/v21/test_location.py b/stix2/test/v21/test_location.py index 5d3eab8a..616d7711 100644 --- a/stix2/test/v21/test_location.py +++ b/stix2/test/v21/test_location.py @@ -377,3 +377,45 @@ def test_bing_map_url_multiple_props_and_long_lat_provided(): loc_url = loc.to_maps_url("Bing Maps") assert loc_url == expected_url + +def test_bing_map_url_for_0_long_lat(): + expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C0.0&lvl=16" + + loc = stix2.v21.Location( + region="northern-america", + country="United States of America", + street_address="1410 Museum Campus Drive, Chicago, IL 60605", + latitude=0, + longitude=-0, + ) + + loc_url = loc.to_maps_url("Bing Maps") + assert loc_url == expected_url + +def test_bing_map_url_for_0_long(): + expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C-348.2&lvl=16" + + loc = stix2.v21.Location( + region="northern-america", + country="United States of America", + street_address="1410 Museum Campus Drive, Chicago, IL 60605", + latitude=0, + longitude=-348.2, + ) + + loc_url = loc.to_maps_url("Bing Maps") + assert loc_url == expected_url + +def test_bing_map_url_for_0_lat(): + expected_url = "https://bing.com/maps/default.aspx?where1=84.2%2C0.0&lvl=16" + + loc = stix2.v21.Location( + region="northern-america", + country="United States of America", + street_address="1410 Museum Campus Drive, Chicago, IL 60605", + latitude=84.2, + longitude=-0, + ) + + loc_url = loc.to_maps_url("Bing Maps") + assert loc_url == expected_url From 9ff9b3f9e404b4b4cae4971d671286c3d630fa63 Mon Sep 17 00:00:00 2001 From: HackerShark Date: Thu, 17 Oct 2024 14:02:49 -0400 Subject: [PATCH 3/8] fixing tests by making the long and lat a float instead of integers Signed-off-by: HackerShark --- stix2/test/v21/test_location.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stix2/test/v21/test_location.py b/stix2/test/v21/test_location.py index 616d7711..a27aacb8 100644 --- a/stix2/test/v21/test_location.py +++ b/stix2/test/v21/test_location.py @@ -385,8 +385,8 @@ def test_bing_map_url_for_0_long_lat(): region="northern-america", country="United States of America", street_address="1410 Museum Campus Drive, Chicago, IL 60605", - latitude=0, - longitude=-0, + latitude=0.0, + longitude=-0.0, ) loc_url = loc.to_maps_url("Bing Maps") @@ -399,7 +399,7 @@ def test_bing_map_url_for_0_long(): region="northern-america", country="United States of America", street_address="1410 Museum Campus Drive, Chicago, IL 60605", - latitude=0, + latitude=0.0, longitude=-348.2, ) @@ -414,7 +414,7 @@ def test_bing_map_url_for_0_lat(): country="United States of America", street_address="1410 Museum Campus Drive, Chicago, IL 60605", latitude=84.2, - longitude=-0, + longitude=-0.0, ) loc_url = loc.to_maps_url("Bing Maps") From d824c0ba5437a19021d4efdd938ebd97b1f74c3d Mon Sep 17 00:00:00 2001 From: HackerShark Date: Thu, 17 Oct 2024 14:04:44 -0400 Subject: [PATCH 4/8] updating longitude value in one of the tests Signed-off-by: HackerShark --- stix2/test/v21/test_location.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stix2/test/v21/test_location.py b/stix2/test/v21/test_location.py index a27aacb8..782b9a6f 100644 --- a/stix2/test/v21/test_location.py +++ b/stix2/test/v21/test_location.py @@ -414,7 +414,7 @@ def test_bing_map_url_for_0_lat(): country="United States of America", street_address="1410 Museum Campus Drive, Chicago, IL 60605", latitude=84.2, - longitude=-0.0, + longitude=0.0, ) loc_url = loc.to_maps_url("Bing Maps") From a440d343893b28124b814db335afcb5f9c8b679b Mon Sep 17 00:00:00 2001 From: HackerShark Date: Fri, 18 Oct 2024 10:25:05 -0400 Subject: [PATCH 5/8] fixed the tests, now they all pass Signed-off-by: HackerShark --- stix2/test/v21/test_location.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/stix2/test/v21/test_location.py b/stix2/test/v21/test_location.py index 782b9a6f..c3a167e8 100644 --- a/stix2/test/v21/test_location.py +++ b/stix2/test/v21/test_location.py @@ -382,38 +382,38 @@ def test_bing_map_url_for_0_long_lat(): expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C0.0&lvl=16" loc = stix2.v21.Location( - region="northern-america", - country="United States of America", - street_address="1410 Museum Campus Drive, Chicago, IL 60605", + region="Gulf of Guinea", + country="International waters", + street_address="0°N, 0°E – Null Island", latitude=0.0, - longitude=-0.0, + longitude=0.0, ) loc_url = loc.to_maps_url("Bing Maps") assert loc_url == expected_url def test_bing_map_url_for_0_long(): - expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C-348.2&lvl=16" + expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C39.668&lvl=16" loc = stix2.v21.Location( - region="northern-america", - country="United States of America", - street_address="1410 Museum Campus Drive, Chicago, IL 60605", + region="Eastern Africa", + country="Kenya", + street_address="0°N, 39.668°E", latitude=0.0, - longitude=-348.2, + longitude=39.668, ) loc_url = loc.to_maps_url("Bing Maps") assert loc_url == expected_url def test_bing_map_url_for_0_lat(): - expected_url = "https://bing.com/maps/default.aspx?where1=84.2%2C0.0&lvl=16" + expected_url = "https://bing.com/maps/default.aspx?where1=51.477%2C0.0&lvl=16" loc = stix2.v21.Location( - region="northern-america", - country="United States of America", - street_address="1410 Museum Campus Drive, Chicago, IL 60605", - latitude=84.2, + region="Western Europe", + country="United Kingdom", + street_address="Royal Observatory, Blackheath Ave, Greenwich, London SE10 8XJ, United Kingdom", + latitude=51.477, longitude=0.0, ) From 7665f23184c2441df4836c720792e1988932dcbd Mon Sep 17 00:00:00 2001 From: HackerShark Date: Fri, 25 Oct 2024 10:14:07 -0400 Subject: [PATCH 6/8] Issue with old code was it checks for None specifically, this change in behavior caused the fail because is_encrypted is set to False which is a falsy value. Adjusted the code to handle both None and other falsy values Signed-off-by: HackerShark --- stix2/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stix2/base.py b/stix2/base.py index 6511f805..79de2b6a 100644 --- a/stix2/base.py +++ b/stix2/base.py @@ -103,7 +103,7 @@ def _check_properties_dependency(self, list_of_properties, list_of_dependent_pro failed_dependency_pairs = [] for p in list_of_properties: for dp in list_of_dependent_properties: - if self.get(p) is None and self.get(dp) is not None: + if (self.get(p) is None or self.get(p) is False) and self.get(dp) is not None: failed_dependency_pairs.append((p, dp)) if failed_dependency_pairs: raise DependentPropertiesError(self.__class__, failed_dependency_pairs) From 5629e7cc9034a53231230e5e6d023f5c1ba0dea9 Mon Sep 17 00:00:00 2001 From: HackerShark Date: Fri, 25 Oct 2024 15:20:01 -0400 Subject: [PATCH 7/8] fixing spacing between functions to address styling issues Signed-off-by: HackerShark --- stix2/test/v21/test_location.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stix2/test/v21/test_location.py b/stix2/test/v21/test_location.py index c3a167e8..e5d3f862 100644 --- a/stix2/test/v21/test_location.py +++ b/stix2/test/v21/test_location.py @@ -378,6 +378,7 @@ def test_bing_map_url_multiple_props_and_long_lat_provided(): loc_url = loc.to_maps_url("Bing Maps") assert loc_url == expected_url + def test_bing_map_url_for_0_long_lat(): expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C0.0&lvl=16" @@ -392,6 +393,7 @@ def test_bing_map_url_for_0_long_lat(): loc_url = loc.to_maps_url("Bing Maps") assert loc_url == expected_url + def test_bing_map_url_for_0_long(): expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C39.668&lvl=16" @@ -406,6 +408,7 @@ def test_bing_map_url_for_0_long(): loc_url = loc.to_maps_url("Bing Maps") assert loc_url == expected_url + def test_bing_map_url_for_0_lat(): expected_url = "https://bing.com/maps/default.aspx?where1=51.477%2C0.0&lvl=16" From d7b14cb6a52a6eec03aa16b8ee3dfb31b8815d87 Mon Sep 17 00:00:00 2001 From: HackerShark Date: Thu, 7 Nov 2024 14:05:12 -0500 Subject: [PATCH 8/8] fixing _default_properties_dependency to check for the presence of the property that way it won't incorrectly raise a DependentPropertiesError Signed-off-by: HackerShark --- stix2/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stix2/base.py b/stix2/base.py index 79de2b6a..a4f3f03b 100644 --- a/stix2/base.py +++ b/stix2/base.py @@ -103,7 +103,9 @@ def _check_properties_dependency(self, list_of_properties, list_of_dependent_pro failed_dependency_pairs = [] for p in list_of_properties: for dp in list_of_dependent_properties: - if (self.get(p) is None or self.get(p) is False) and self.get(dp) is not None: + if p not in self and dp in self: + failed_dependency_pairs.append((p, dp)) + elif p in self and (self[p] is None or self[p] is False) and dp in self and self[dp] is not None: failed_dependency_pairs.append((p, dp)) if failed_dependency_pairs: raise DependentPropertiesError(self.__class__, failed_dependency_pairs)