Skip to contentSkip to conversation

fetch2: BB_ALLOWED_NETWORKS should not care about port numbers

PATCH New Olof Johansson 1 participant 2 messages Apr 1, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 fetch2: BB_ALLOWED_NETWORKS should not care about port numbers

From: Olof Johansson <[email protected]>

Bitbake would fail to classify the following URL as belonging to a allowed network, because of the port number in the url.

BB_ALLOWED_NETWORKS = "*.example.com" SRC_URI = "http://git.example.com:8080/foo.tar.gz"

Since protocols aren't specified in the BB_ALLOWED_NETWORKS variable, it's reasonable to believe that this should work regardless of protocol being used.

---
 bitbake/lib/bb/fetch2/__init__.py | 1 +
 1 file changed, 1 insertion(+)
bitbake/lib/bb/fetch2/__init__.py +1 -0
index e8cea7f..c2ddebd 100644
@@ -1032,6 +1032,7 @@ def trusted_network(d, url):
     if not network:
         return True
 
+    network = network.split(':')[0]
     network = network.lower()
 
     for host in trusted_hosts.split(" "):
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 2/2 tests/fetch.py: Improve unit tests for trusted network check

From: Olof Johansson <[email protected]>

The tests were skipped when running without network even though they didn't require network. This commit also adds a test case for URLs with ports in them (the ports should not be considered when doing trusted network checks).

---
 bitbake/lib/bb/tests/fetch.py | 77 +++++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 35 deletions(-)
bitbake/lib/bb/tests/fetch.py +42 -35
index 29d8999..4ba688b 100644
@@ -611,42 +611,49 @@ class FetcherNetworkTest(FetcherTest):
             os.chdir(os.path.dirname(self.unpackdir))
             fetcher.unpack(self.unpackdir)
 
-        def test_trusted_network(self):
-            # Ensure trusted_network returns False when the host IS in the list.
-            url = "git://Someserver.org/foo;rev=1"
-            self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
-            self.assertTrue(bb.fetch.trusted_network(self.d, url))
-
-        def test_wild_trusted_network(self):
-            # Ensure trusted_network returns true when the *.host IS in the list.
-            url = "git://Someserver.org/foo;rev=1"
-            self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
-            self.assertTrue(bb.fetch.trusted_network(self.d, url))
-
-        def test_prefix_wild_trusted_network(self):
-            # Ensure trusted_network returns true when the prefix matches *.host.
-            url = "git://git.Someserver.org/foo;rev=1"
-            self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
-            self.assertTrue(bb.fetch.trusted_network(self.d, url))
-
-        def test_two_prefix_wild_trusted_network(self):
-            # Ensure trusted_network returns true when the prefix matches *.host.
-            url = "git://something.git.Someserver.org/foo;rev=1"
-            self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
-            self.assertTrue(bb.fetch.trusted_network(self.d, url))
-
-        def test_untrusted_network(self):
-            # Ensure trusted_network returns False when the host is NOT in the list.
-            url = "git://someserver.org/foo;rev=1"
-            self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
-            self.assertFalse(bb.fetch.trusted_network(self.d, url))
-
-        def test_wild_untrusted_network(self):
-            # Ensure trusted_network returns False when the host is NOT in the list.
-            url = "git://*.someserver.org/foo;rev=1"
-            self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
-            self.assertFalse(bb.fetch.trusted_network(self.d, url))
 
+class TrustedNetworksTest(FetcherTest):
+    def test_trusted_network(self):
+        # Ensure trusted_network returns False when the host IS in the list.
+        url = "git://Someserver.org/foo;rev=1"
+        self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org")
+        self.assertTrue(bb.fetch.trusted_network(self.d, url))
+
+    def test_wild_trusted_network(self):
+        # Ensure trusted_network returns true when the *.host IS in the list.
+        url = "git://Someserver.org/foo;rev=1"
+        self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
+        self.assertTrue(bb.fetch.trusted_network(self.d, url))
+
+    def test_prefix_wild_trusted_network(self):
+        # Ensure trusted_network returns true when the prefix matches *.host.
+        url = "git://git.Someserver.org/foo;rev=1"
+        self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
+        self.assertTrue(bb.fetch.trusted_network(self.d, url))
+
+    def test_two_prefix_wild_trusted_network(self):
+        # Ensure trusted_network returns true when the prefix matches *.host.
+        url = "git://something.git.Someserver.org/foo;rev=1"
+        self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org")
+        self.assertTrue(bb.fetch.trusted_network(self.d, url))
+
+    def test_port_trusted_network(self):
+        # Ensure trusted_network returns True, even if the url specifies a port.
+        url = "git://someserver.org:8080/foo;rev=1"
+        self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org")
+        self.assertTrue(bb.fetch.trusted_network(self.d, url))
+
+    def test_untrusted_network(self):
+        # Ensure trusted_network returns False when the host is NOT in the list.
+        url = "git://someserver.org/foo;rev=1"
+        self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
+        self.assertFalse(bb.fetch.trusted_network(self.d, url))
+
+    def test_wild_untrusted_network(self):
+        # Ensure trusted_network returns False when the host is NOT in the list.
+        url = "git://*.someserver.org/foo;rev=1"
+        self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org")
+        self.assertFalse(bb.fetch.trusted_network(self.d, url))
 
 class URLHandle(unittest.TestCase):
 
Signature · 1 line
2.1.4