Skip to content

Commit

Permalink
Merge pull request #69 from conda/test-coverage-signing
Browse files Browse the repository at this point in the history
Increase test coverage for signing module.
  • Loading branch information
dholth authored Aug 21, 2023
2 parents fb8d5fc + dc402ff commit a6cb2ba
Show file tree
Hide file tree
Showing 3 changed files with 351 additions and 6 deletions.
40 changes: 34 additions & 6 deletions tests/test_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import os.path
import shutil

import pytest

from conda_content_trust.authentication import *
from conda_content_trust.common import *
from conda_content_trust.signing import *
Expand Down Expand Up @@ -68,7 +70,8 @@
"osx-64/repodata_from_packages.json": "8120fb07a6a8a280ffa2b89fb2fbb89484823d0b0357ff0cfa7c333352b2faa2",
},
}
REG__REPODATA_SAMPLE_FNAME = "tests/repodata_sample.json"
REG__REPODATA_SAMPLE_FNAME = "tests/testdata/repodata_sample.json"
REG__REPODATA_NO_PACKAGES_FNAME = "tests/testdata/repodata_no_packages.json"
REG__REPODATA_SAMPLE_TEMP_FNAME = "tests/repodata_sample_temp.json"


Expand All @@ -82,10 +85,16 @@
# '⚠️ These tests are currently implemented in '
# 'test_authentication.py instead.'))

# def test_wrap_as_signable():
# raise(NotImplementedError(
# '⚠️ This function is tested in multiple modules, but '
# 'a unit test should be constructed from those tests.'))

def test_wrap_as_signable_default():
obj = {"foo": "bar"}
signed = wrap_as_signable(obj)
assert signed == {"signatures": {}, "signed": obj}


def test_wrap_as_signable_error():
with pytest.raises(TypeError):
wrap_as_signable(object())


def remove_sample_tempfile():
Expand Down Expand Up @@ -120,7 +129,9 @@ def test_sign_all_in_repodata(request):

# Make sure there is one signature entry for every artifact entry, and no
# mystery entries.
assert repodata["packages"].keys() == repodata_signed["signatures"].keys()
assert set(repodata["packages"].keys()) | set(
repodata["packages.conda"].keys()
) == set(repodata_signed["signatures"].keys())

for artifact_name in repodata["packages"]:
# There's a signature "by" this key listed for every artifact.
Expand All @@ -132,3 +143,20 @@ def test_sign_all_in_repodata(request):
public,
canonserialize(repodata["packages"][artifact_name]),
)


def test_sign_all_in_repodata_no_packages(request):
request.addfinalizer(remove_sample_tempfile)

# Make a test copy of the repodata sample, since we're going to
# update it.
if os.path.exists(REG__REPODATA_SAMPLE_TEMP_FNAME):
os.remove(REG__REPODATA_SAMPLE_TEMP_FNAME)
shutil.copy(REG__REPODATA_NO_PACKAGES_FNAME, REG__REPODATA_SAMPLE_TEMP_FNAME)

# grab data and use it to compare to what we produce in a bit

repodata = load_metadata_from_file(REG__REPODATA_NO_PACKAGES_FNAME)

with pytest.raises(ValueError):
sign_all_in_repodata(REG__REPODATA_SAMPLE_TEMP_FNAME, REG__PRIVATE_HEX)
6 changes: 6 additions & 0 deletions tests/testdata/repodata_no_packages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info": {
"subdir": "linux-64"
},
"repodata_version": 1
}
311 changes: 311 additions & 0 deletions tests/repodata_sample.json → tests/testdata/repodata_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,317 @@
"version": "1.4.4"
}
},
"packages.conda": {
"_anaconda_depends-2018.12-py27_0.conda": {
"build": "py27_0",
"build_number": 0,
"depends": [
"alabaster",
"anaconda-client",
"anaconda-project",
"asn1crypto",
"astroid",
"astropy",
"atomicwrites",
"attrs",
"babel",
"backports",
"backports.functools_lru_cache",
"backports.os",
"backports.shutil_get_terminal_size",
"backports_abc",
"beautifulsoup4",
"bitarray",
"bkcharts",
"blas",
"blaze",
"bleach",
"blosc",
"bokeh",
"boto",
"bottleneck",
"bzip2",
"ca-certificates",
"cairo",
"cdecimal",
"certifi",
"cffi",
"chardet",
"click",
"cloudpickle",
"clyent",
"colorama",
"configparser",
"contextlib2",
"cryptography",
"curl",
"cycler",
"cython",
"cytoolz",
"dask",
"dask-core",
"datashape",
"dbus",
"decorator",
"defusedxml",
"distributed",
"docutils",
"entrypoints",
"enum34",
"et_xmlfile",
"expat",
"fastcache",
"filelock",
"flask",
"flask-cors",
"fontconfig",
"freetype",
"fribidi",
"funcsigs",
"functools32",
"future",
"futures",
"get_terminal_size",
"gevent",
"glib",
"glob2",
"gmp",
"gmpy2",
"graphite2",
"greenlet",
"grin",
"gst-plugins-base",
"gstreamer",
"h5py",
"harfbuzz",
"hdf5",
"heapdict",
"html5lib",
"icu",
"idna",
"imageio",
"imagesize",
"importlib_metadata",
"intel-openmp",
"ipaddress",
"ipykernel",
"ipython",
"ipython_genutils",
"ipywidgets",
"isort",
"itsdangerous",
"jbig",
"jdcal",
"jedi",
"jinja2",
"jpeg",
"jsonschema",
"jupyter",
"jupyter_client",
"jupyter_console",
"jupyter_core",
"jupyterlab",
"jupyterlab_launcher",
"kiwisolver",
"krb5",
"lazy-object-proxy",
"libarchive",
"libcurl",
"libedit",
"libffi",
"libgcc-ng",
"libgfortran-ng",
"liblief",
"libpng",
"libsodium",
"libssh2",
"libstdcxx-ng",
"libtiff",
"libtool",
"libuuid",
"libxcb",
"libxml2",
"libxslt",
"linecache2",
"llvmlite",
"locket",
"lxml",
"lz4-c",
"lzo",
"markupsafe",
"matplotlib",
"mccabe",
"mistune",
"mkl",
"mkl-service",
"mkl_fft",
"mkl_random",
"more-itertools",
"mpc",
"mpfr",
"mpmath",
"msgpack-python",
"multipledispatch",
"nbconvert",
"nbformat",
"ncurses",
"networkx",
"nltk",
"nose",
"notebook",
"numba",
"numexpr",
"numpy",
"numpy-base",
"numpydoc",
"odo",
"olefile",
"openpyxl",
"openssl",
"packaging",
"pandas",
"pandoc",
"pandocfilters",
"pango",
"parso",
"partd",
"patchelf",
"path.py",
"pathlib2",
"patsy",
"pcre",
"pep8",
"pexpect",
"pickleshare",
"pillow",
"pip",
"pixman",
"pkginfo",
"pluggy",
"ply",
"prometheus_client",
"prompt_toolkit",
"psutil",
"ptyprocess",
"py",
"py-lief",
"pycairo",
"pycodestyle",
"pycosat",
"pycparser",
"pycrypto",
"pycurl",
"pyflakes",
"pygments",
"pylint",
"pyodbc",
"pyopenssl",
"pyparsing",
"pyqt",
"pysocks",
"pytables",
"pytest",
"python 2.7.*",
"python-dateutil",
"python-libarchive-c",
"pytz",
"pywavelets",
"pyyaml",
"pyzmq",
"qt",
"qtawesome",
"qtconsole",
"qtpy",
"readline",
"requests",
"rope",
"ruamel_yaml",
"scandir",
"scikit-image",
"scikit-learn",
"scipy",
"seaborn",
"send2trash",
"setuptools",
"simplegeneric",
"singledispatch",
"sip",
"six",
"snappy",
"snowballstemmer",
"sortedcollections",
"sortedcontainers",
"sphinx",
"sphinxcontrib",
"sphinxcontrib-websupport",
"spyder",
"spyder-kernels",
"sqlalchemy",
"sqlite",
"ssl_match_hostname",
"statsmodels",
"subprocess32",
"sympy",
"tblib",
"terminado",
"testpath",
"tk",
"toolz",
"tornado",
"tqdm",
"traceback2",
"traitlets",
"typing",
"unicodecsv",
"unittest2",
"unixodbc",
"urllib3",
"wcwidth",
"webencodings",
"werkzeug",
"wheel",
"widgetsnbextension",
"wrapt",
"wurlitzer",
"xlrd",
"xlsxwriter",
"xlwt",
"xz",
"yaml",
"zeromq",
"zict",
"zlib",
"zstd"
],
"license": "BSD",
"md5": "c64c38860168c341cee90ff2d615f160",
"name": "_anaconda_depends",
"sha256": "447d60baa9c9aa871ae4af347a1def98a69bdf4cca16d4d4e6bf00ea5c2c88d8",
"size": 6339,
"subdir": "linux-64",
"timestamp": 1562173890182,
"version": "2018.12"
},
"zstd-1.4.4-h0b5b093_3.conda": {
"build": "h0b5b093_3",
"build_number": 3,
"depends": [
"libgcc-ng >=7.3.0",
"libstdcxx-ng >=7.3.0",
"lz4-c >=1.9.2,<1.10.0a0",
"xz >=5.2.5,<6.0a0",
"zlib >=1.2.11,<1.3.0a0"
],
"license": "BSD 3-Clause",
"md5": "5debcfb1d9707b07619699782f8d463a",
"name": "zstd",
"sha256": "c0d4b9396580e272a40d42aa444e639720eb783bcf69e63a8c27296b277fbbd2",
"size": 458180,
"subdir": "linux-64",
"timestamp": 1587075143434,
"version": "1.4.4"
}
},
"removed": [
"conda-package-handling-1.5.0-py27h7b6447c_0.conda",
"conda-package-handling-1.5.0-py27h7b6447c_0.tar.bz2",
Expand Down

0 comments on commit a6cb2ba

Please sign in to comment.