Skip to content

Commit

Permalink
Add workflows and expand supported pythons
Browse files Browse the repository at this point in the history
Feature/more pythons
  • Loading branch information
lilatomic authored Sep 18, 2022
2 parents 5e6d2af + f9af1b0 commit d163e48
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 41 deletions.
17 changes: 17 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[paths]
source =
keyutils
*/site-packages

[run]
branch = true
source =
keyutils
parallel = true

[report]
show_missing = true
precision = 2
omit = *migrations*
exclude_lines =
if __name__ == .__main__.:
53 changes: 53 additions & 0 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Tests

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]


jobs:
build:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: ["ubuntu-20.04"]
python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10"]
include:
- platform: "ubuntu-18.04"
python-version: "2.7"
# - platform: "ubuntu-18.04"
# python-version: "3.4"
- platform: "ubuntu-18.04"
python-version: "3.6"

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install C dependencies
run: |
sudo apt-get install -y keyutils libkeyutils-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install coverage[toml] virtualenv tox tox-gh-actions
- name: Test with tox
run: tox
#env:
# PLATFORM: ${{ matrix.platform }}

# from https://github.com/codecov/codecov-action
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Lint tests run on PR
# but should not run after push to main because reporting
# these after push is meaningless to the building of the package
name: lint

on:
pull_request:
branches: [main, master]

jobs:
build:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest]
python-version: ["2.7", "3.6", "3.10"]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install C dependencies
run: |
sudo apt-get install -y keyutils libkeyutils-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install virtualenv tox tox-gh-actions
- name: Test Lint
run: tox -e lint,radon
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include AUTHORS ChangeLog INSTALL LICENSE README.rst TODO
include keyutils/_keyutils.c
14 changes: 12 additions & 2 deletions keyutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@

from __future__ import absolute_import


from . import _keyutils


for k, v in _keyutils.constants.__dict__.items():
globals()[k] = v
del k, v

from errno import EINVAL, ENOMEM, EDQUOT, EINTR, EACCES

from errno import ( # noqa: F401,E402 , imported for reexport; TODO: better reexport
EACCES,
EDQUOT,
EINTR,
EINVAL,
ENOMEM,
)


Error = _keyutils.error


def add_key(key, value, keyring, keyType=b"user"):
return _keyutils.add_key(keyType, key, value, keyring)

Expand Down
1 change: 1 addition & 0 deletions keyutils/_keyutils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from libc cimport stdlib


cdef extern from "Python.h":
object PyErr_SetFromErrno(exc)
object PyBytes_FromStringAndSize(char *str, Py_ssize_t size)
Expand Down
40 changes: 23 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@


import io
from setuptools import setup, Extension

with io.open('README.rst', "r", encoding="utf-8") as f:
from setuptools import Extension, setup


with io.open("README.rst", "r", encoding="utf-8") as f:
long_description = f.read()

setup(
name='keyutils',
version='0.6',
description='keyutils bindings for Python',
name="keyutils",
version="0.6",
description="keyutils bindings for Python",
long_description=long_description,
author='Mihai Ibanescu',
author_email='[email protected]',
url='https://github.com/sassoftware/python-keyutils',
license='Apache 2.0',
packages=['keyutils'],
author="Mihai Ibanescu",
author_email="[email protected]",
url="https://github.com/sassoftware/python-keyutils",
license="Apache 2.0",
packages=["keyutils"],
classifiers=[
"Topic :: Security",
"Operating System :: POSIX :: Linux",
Expand All @@ -41,17 +43,21 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
platforms=[
"Linux",
],
],
ext_modules=[
Extension(
'keyutils._keyutils',
['keyutils/_keyutils.pyx'],
libraries=['keyutils'],
"keyutils._keyutils",
["keyutils/_keyutils.pyx"],
libraries=["keyutils"],
),
],
setup_requires=["pytest-runner"],
tests_require=["pytest"],
setup_requires=[],
tests_require=["pytest", "pytest-runner"],
)
41 changes: 21 additions & 20 deletions test/keyutils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import keyutils


class BasicTest(unittest.TestCase):
def testSet(self):
keyDesc = b"test:key:01"
Expand All @@ -36,7 +37,7 @@ def testSet(self):
try:
keyutils.read_key(12345)
except keyutils.Error as e:
self.assertEqual(e.args, (126, 'Required key not available'))
self.assertEqual(e.args, (126, "Required key not available"))

keyutils.add_key(keyDesc, keyVal, keyring)
keyId = keyutils.request_key(keyDesc, keyring)
Expand All @@ -49,17 +50,16 @@ def testSession(self):
val = b"asdfasdfasdf"
session = keyutils.join_session_keyring()
keyId = keyutils.add_key(desc, val, session)
self.assertEqual(keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING,
desc), keyId)
self.assertEqual(
keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING, desc), keyId
)
keyutils.join_session_keyring()
self.assertEqual(keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING,
desc), None)
self.assertEqual(keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING, desc), None)

def testRevoke(self):
desc = b"dummy"
session = keyutils.join_session_keyring()
self.assertEqual(keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING,
desc), None)
self.assertEqual(keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING, desc), None)
keyutils.revoke(session)
try:
keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING, desc)
Expand All @@ -77,8 +77,8 @@ def testRevoke(self):
pid, exitcode = os.waitpid(childpid, 0)
self.assertEqual(childpid, pid)
self.assertTrue(
os.WIFEXITED(exitcode) and os.WEXITSTATUS(exitcode) == 0,
exitcode)
os.WIFEXITED(exitcode) and os.WEXITSTATUS(exitcode) == 0, exitcode
)
else:
rc = 1
try:
Expand All @@ -88,14 +88,16 @@ def testRevoke(self):
finally:
os._exit(rc)

self.assertEqual(keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING,
desc), None)

self.assertEqual(keyutils.search(keyutils.KEY_SPEC_SESSION_KEYRING, desc), None)

def testLink(self):
desc = b"key1"
child = keyutils.add_key(b"ring1", None, keyutils.KEY_SPEC_PROCESS_KEYRING, b"keyring")
parent = keyutils.add_key(b"ring2", None, keyutils.KEY_SPEC_PROCESS_KEYRING, b"keyring")
child = keyutils.add_key(
b"ring1", None, keyutils.KEY_SPEC_PROCESS_KEYRING, b"keyring"
)
parent = keyutils.add_key(
b"ring2", None, keyutils.KEY_SPEC_PROCESS_KEYRING, b"keyring"
)
keyId = keyutils.add_key(desc, b"dummy", child)
self.assertEqual(keyutils.search(child, desc), keyId)
self.assertEqual(keyutils.search(parent, desc), None)
Expand Down Expand Up @@ -140,7 +142,7 @@ def testDescribe(self):
key_id = keyutils.add_key(desc, value, keyring)

ret = keyutils.describe_key(key_id)
ktype, _, _, kperm, kdesc = ret.split(b';', 4)
ktype, _, _, kperm, kdesc = ret.split(b";", 4)
self.assertEqual(ktype, b"user")
self.assertEqual(desc, kdesc)

Expand All @@ -162,16 +164,15 @@ def testSetPerm(self):

key_id = keyutils.add_key(desc, value, keyring)

ktype, _, _, kperm, kdesc = keyutils.describe_key(key_id).split(b';', 4)
ktype, _, _, kperm, kdesc = keyutils.describe_key(key_id).split(b";", 4)
kperm = int(kperm, base=16)
self.assertEqual(
keyutils.KEY_POS_READ, kperm & keyutils.KEY_POS_READ)
self.assertEqual(keyutils.KEY_POS_READ, kperm & keyutils.KEY_POS_READ)
keyutils.set_perm(key_id, kperm - keyutils.KEY_POS_READ)

ktype, _, _, kperm, kdesc = keyutils.describe_key(key_id).split(b';', 4)
ktype, _, _, kperm, kdesc = keyutils.describe_key(key_id).split(b";", 4)
kperm = int(kperm, base=16)
self.assertEqual(0, kperm & keyutils.KEY_POS_READ)


if __name__ == '__main__':
if __name__ == "__main__":
sys.exit(unittest.main())
Loading

0 comments on commit d163e48

Please sign in to comment.