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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ cd ..
sudo dpkg -i mintsources*.deb
```

## Test

Run the tests from the root of the project
```
python3 -m unittest
```

## Translations
Please use Launchpad to translate Mintsources: https://translations.launchpad.net/linuxmint/latest/.

Expand Down
1 change: 0 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Depends: python3-apt,
gir1.2-pango-1.0,
gir1.2-xapp-1.0,
iso-flag-png,
inxi,
lsb-release,
mint-mirrors,
${misc:Depends},
Expand Down
Empty file added tests/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions tests/test_mintSources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys, os

tests_path = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, tests_path + "/../usr/lib/linuxmint/mintSources/")

from pathlib import Path
import unittest

import repolib

from mintSources import repo_key_path


class MintSources(unittest.TestCase):
def test_repo_key_path(self):
repolib.util.SOURCES_DIR = Path(tests_path, "testdata", "sources.list.d")
repolib.load_all_sources()

nemo_uri = "https://nemo.linuxmint.com"
xviewer_uri = "https://xviewer.linuxmint.com"
xviewerdev_uri = "https://xviewer-dev.linuxmint.com"
sticky_uri = "https://sticky.linuxmint.com"
hypnotix_uri = "https://hypnotix.linuxmint.com"
pix_uri = "https://pix.linuxmint.com"

# Deb822 source format.
self.assertEqual(repo_key_path(nemo_uri), "/usr/share/keyrings/nemo.gpg")
# Legacy source format.
self.assertEqual(repo_key_path(xviewer_uri), "/usr/share/keyrings/xviewer.gpg")
# Input URI with trailing slash.
self.assertEqual(repo_key_path(nemo_uri + "/"), "/usr/share/keyrings/nemo.gpg")
# Source repository URI with trailing slash.
self.assertEqual(
repo_key_path(xviewerdev_uri), "/usr/share/keyrings/xviewer-dev.gpg"
)
# Not signed-by source.
self.assertEqual(repo_key_path(sticky_uri), None)
# Signed but disabled Deb822 source format.
self.assertEqual(repo_key_path(pix_uri), None)
# Signed but disabled legacy source format.
self.assertEqual(repo_key_path(hypnotix_uri), None)


if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions tests/testdata/sources.list.d/hypnotix.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#deb [signed-by=/usr/share/keyrings/hypnotix.gpg] https://hypnotix.linuxmint.com zena main
7 changes: 7 additions & 0 deletions tests/testdata/sources.list.d/nemo.sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Types: deb
URIs: https://nemo.linuxmint.com
Enabled: yes
Suites: stable
Components: main
Architectures: amd64
Signed-By: /usr/share/keyrings/nemo.gpg
7 changes: 7 additions & 0 deletions tests/testdata/sources.list.d/pix.sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Types: deb
URIs: https://pix.linuxmint.com
Enabled: no
Suites: stable
Components: main
Architectures: amd64
Signed-By: /usr/share/keyrings/nemo.gpg
1 change: 1 addition & 0 deletions tests/testdata/sources.list.d/sticky.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb https://sticky.linuxmint.com zena main
2 changes: 2 additions & 0 deletions tests/testdata/sources.list.d/xviewer.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deb [signed-by=/usr/share/keyrings/xviewer.gpg] https://xviewer.linuxmint.com zena main
deb [signed-by=/usr/share/keyrings/xviewer-dev.gpg] https://xviewer-dev.linuxmint.com/ zena main
25 changes: 19 additions & 6 deletions usr/lib/linuxmint/mintSources/mintSources.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,22 @@ def expand_http_line(line, distro_codename):
line = "deb %s %s %s" % ( repo, distro_codename, areas )
return line

def repo_key_path(uri):
"""
Returns the key path for a given repository URI for enabled sources.

NOTE: Must load all the sources with repolib.load_all_sources() once before
calling this.
"""
uri = uri.removesuffix("/")
for source in repolib.sources.values():
if source.enabled == repolib.AptSourceEnabled.FALSE or not source.signed_by:
continue
for u in source.uris:
if uri == u.removesuffix("/"):
return source.signed_by
return None

class CurlCallback:
def __init__(self):
self.contents = ''
Expand Down Expand Up @@ -1209,15 +1225,12 @@ def __init__(self, path, uri):

r = re.compile(r"^gpg\:\s+using \S+ key (.+)$", re.MULTILINE | re.IGNORECASE)
# try to verify all repository lists using gpg
repolib.load_all_sources()
for repository in repositories:
# if the repository is "signed-by", just check that the key file is present
uri = repository.uri
if uri.endswith("/"):
uri = uri[:-1]
output = subprocess.getoutput(f"inxi -r | grep {uri}")
key_path = None
if "signed-by" in output:
key_path = output.split("signed-by=")[1].split("]")[0]
key_path = repo_key_path(uri)
if key_path:
print(f"{uri} is signed by {key_path}")
if os.path.exists(key_path):
print(" Key found.")
Expand Down