Skip to content

Commit

Permalink
Merge branch 'master' into security/prevent_rootfs_escape
Browse files Browse the repository at this point in the history
  • Loading branch information
HorlogeSkynet committed Dec 15, 2023
2 parents e40187b + 6a487e9 commit 7dc0126
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 15 deletions.
23 changes: 17 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand All @@ -25,20 +25,31 @@ jobs:

test:
name: Python ${{ matrix.python }}
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- "ubuntu-latest"
python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "pypy-3.6"
- "3.11"
- "3.12"
include:
- os: "ubuntu-20.04"
python: "3.6"
- os: "ubuntu-20.04"
python: "pypy-3.6"
- os: "ubuntu-22.04"
python: "pypy-3.10"
- os: "macos-12"
python: 3.12

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
Expand All @@ -61,7 +72,7 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: codecov/codecov-action@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
environment: Deploy
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag }}
- uses: actions/setup-python@v4
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ repos:
- id: black
args: ["--target-version", "py36"]
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.9.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
8 changes: 6 additions & 2 deletions src/distro/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class InfoDict(TypedDict):
# Base file names to be looked up for if _UNIXCONFDIR is not readable.
_DISTRO_RELEASE_BASENAMES = [
"SuSE-release",
"altlinux-release",
"arch-release",
"base-release",
"centos-release",
Expand All @@ -152,6 +153,8 @@ class InfoDict(TypedDict):
"system-release",
"plesk-release",
"iredmail-release",
"board-release",
"ec2_version",
)


Expand Down Expand Up @@ -244,6 +247,7 @@ def id() -> str:
"rocky" Rocky Linux
"aix" AIX
"guix" Guix System
"altlinux" ALT Linux
============== =========================================
If you have a need to get distros for reliable IDs added into this set,
Expand Down Expand Up @@ -994,10 +998,10 @@ def info(self, pretty: bool = False, best: bool = False) -> InfoDict:
For details, see :func:`distro.info`.
"""
return dict(
return InfoDict(
id=self.id(),
version=self.version(pretty, best),
version_parts=dict(
version_parts=VersionDict(
major=self.major_version(best),
minor=self.minor_version(best),
build_number=self.build_number(best),
Expand Down
1 change: 1 addition & 0 deletions tests/resources/distros/altlinux10/etc/altlinux-release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALT Server 10.1 (Mendelevium)
1 change: 1 addition & 0 deletions tests/resources/distros/altlinux10/etc/fedora-release
10 changes: 10 additions & 0 deletions tests/resources/distros/altlinux10/etc/os-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
NAME="ALT Server"
VERSION="10.1"
ID=altlinux
VERSION_ID=10.1
PRETTY_NAME="ALT Server 10.1 (Mendelevium)"
ANSI_COLOR="1;33"
CPE_NAME="cpe:/o:alt:server:10.1"
BUILD_ID="ALT Server 10.1"
HOME_URL="https://basealt.ru/"
BUG_REPORT_URL="https://bugs.altlinux.org/"
1 change: 1 addition & 0 deletions tests/resources/distros/altlinux10/etc/redhat-release
1 change: 1 addition & 0 deletions tests/resources/distros/altlinux10/etc/system-release
10 changes: 7 additions & 3 deletions tests/resources/distros/arch/usr/lib/os-release
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
NAME="Arch Linux"
ID=arch
PRETTY_NAME="Arch Linux"
ANSI_COLOR="0;36"
HOME_URL="https://www.archlinux.org/"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo
9 changes: 9 additions & 0 deletions tests/resources/distros/bttcb1/etc/board-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# PLEASE DO NOT EDIT THIS FILE
BOARD=h616
BOARD_NAME="BTT-CB1"
DISTRIBUTION_CODENAME=bullseye
VERSION=2.3.1
LINUXFAMILY=sun50iw9
ARCH=arm64
INITRD_ARCH=arm64
BRANCH=current
9 changes: 9 additions & 0 deletions tests/resources/distros/bttcb1/etc/os-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PRETTY_NAME="BTT-CB1 2.3.1 Bullseye"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
9 changes: 9 additions & 0 deletions tests/resources/distros/bttcb1/usr/lib/os-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
23 changes: 23 additions & 0 deletions tests/resources/distros/debiantesting/bin/lsb_release
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
#
# lsb_release command for testing the ld module.
# Only the -a option is supported.
#
# This version of the lsb_release command works without a corresponding
# etc/lsb-release file.
#

if [[ "$@" != "-a" ]]; then
echo "Usage: lsb_release -a"
exit 2
fi

cat <<OUT
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux bookworm/sid
Release: n/a
Codename: bookworm
OUT

exit 0
1 change: 1 addition & 0 deletions tests/resources/distros/debiantesting/etc/debian_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bookworm/sid
7 changes: 7 additions & 0 deletions tests/resources/distros/debiantesting/etc/os-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PRETTY_NAME="Debian GNU/Linux bookworm/sid"
NAME="Debian GNU/Linux"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
90 changes: 90 additions & 0 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ def test_debian10_os_release(self) -> None:
}
self._test_outcome(desired_outcome)

def test_debiantesting_os_release(self) -> None:
desired_outcome = {
"id": "debian",
"name": "Debian GNU/Linux",
"pretty_name": "Debian GNU/Linux bookworm/sid",
"version": "bookworm/sid",
"pretty_version": "bookworm/sid (bookworm)",
"best_version": "bookworm/sid",
"codename": "bookworm",
}
self._test_outcome(desired_outcome)

def test_fedora19_os_release(self) -> None:
desired_outcome = {
"id": "fedora",
Expand Down Expand Up @@ -509,6 +521,34 @@ def test_cloudlinux7_os_release(self) -> None:
}
self._test_outcome(desired_outcome)

def test_altlinux10_os_release(self) -> None:
desired_outcome = {
"id": "altlinux",
"name": "ALT Server",
"pretty_name": "ALT Server 10.1 (Mendelevium)",
"version": "10.1",
"pretty_version": "10.1",
"best_version": "10.1",
"major_version": "10",
"minor_version": "1",
}
self._test_outcome(desired_outcome)

def test_bttcb1_os_release(self) -> None:
desired_outcome = {
"id": "debian",
"codename": "bullseye",
"name": "Debian GNU/Linux",
"pretty_name": "BTT-CB1 2.3.1 Bullseye",
"like": "",
"version": "11",
"pretty_version": "11 (bullseye)",
"best_version": "11",
"major_version": "11",
"minor_version": "0",
}
self._test_outcome(desired_outcome)


class TestWithRootDir(TestOSRelease):
"""Test that a LinuxDistribution can be created using an arbitrary root_dir
Expand Down Expand Up @@ -1105,6 +1145,20 @@ def test_cloudlinux7_dist_release(self) -> None:
}
self._test_outcome(desired_outcome, "cloudlinux", "7", "redhat")

def test_altlinux10_dist_release(self) -> None:
desired_outcome = {
"id": "altlinux",
"name": "ALT Server",
"codename": "Mendelevium",
"pretty_name": "ALT Server 10.1 (Mendelevium)",
"version": "10.1",
"pretty_version": "10.1 (Mendelevium)",
"best_version": "10.1",
"major_version": "10",
"minor_version": "1",
}
self._test_outcome(desired_outcome, "altlinux", "10")


@pytest.mark.skipif(not IS_LINUX, reason="Irrelevant on non-linux")
class TestOverall(DistroTestCase):
Expand Down Expand Up @@ -1280,6 +1334,20 @@ def test_debian10_release(self) -> None:
self._test_outcome(desired_outcome)
self._test_non_existing_release_file()

def test_debiantesting_release(self) -> None:
desired_outcome = {
"id": "debian",
"name": "Debian GNU/Linux",
"pretty_name": "Debian GNU/Linux bookworm/sid",
"version": "bookworm/sid",
"pretty_version": "bookworm/sid (bookworm)",
"best_version": "bookworm/sid",
"codename": "bookworm",
"major_version": "",
}
self._test_outcome(desired_outcome)
self._test_non_existing_release_file()

def test_exherbo_release(self) -> None:
desired_outcome = {
"id": "exherbo",
Expand Down Expand Up @@ -1854,6 +1922,28 @@ def test_cloudlinux7_release(self) -> None:
}
self._test_outcome(desired_outcome)

def test_altlinux10_release(self) -> None:
desired_outcome = {
"id": "altlinux",
"name": "ALT Server",
"codename": "Mendelevium",
"pretty_name": "ALT Server 10.1 (Mendelevium)",
"version": "10.1",
"pretty_version": "10.1 (Mendelevium)",
"best_version": "10.1",
"major_version": "10",
"minor_version": "1",
}
self._test_outcome(desired_outcome)

desired_info = {
"id": "altlinux",
"name": "ALT Server",
"version_id": "10.1",
"codename": "Mendelevium",
}
self._test_release_file_info("altlinux-release", desired_info)


def _bad_os_listdir(path: str = ".") -> NoReturn:
"""This function is used by TestOverallWithEtcNotReadable to simulate
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

[tox]
minversion = 1.9
envlist = lint, py{36,37,38,39,310,py3}
envlist = lint, py{36,37,38,39,310,311,312,py3}
isolated_build = true
skip_missing_interpreters = true

Expand Down

0 comments on commit 7dc0126

Please sign in to comment.