From 3e142aec34d17bb7db6d1229387f2dbac84beced Mon Sep 17 00:00:00 2001 From: DawidDlubek-TomTom <78544608+DawidDlubek-TomTom@users.noreply.github.com> Date: Thu, 9 Jun 2022 15:46:00 +0200 Subject: [PATCH] Add tests for vault_authenticate script (#22) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add tests for vault_authenticate script * Format with black, add missing poetry files * Bump version: 0.3.4 → 0.3.5 * Bump version: 0.3.6 → 0.3.7 * Bump version: 0.3.7 → 0.3.8 --- .bumpversion.cfg | 2 +- .github/workflows/release.yml | 2 +- poetry.lock | 123 +++++++++++++------- pyproject.toml | 4 +- tests/test_vault_authenticate.py | 194 +++++++++++++++++++++++++++++++ 5 files changed, 278 insertions(+), 47 deletions(-) create mode 100644 tests/test_vault_authenticate.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d18c04a..9a544a8 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.3.7 +current_version = 0.3.8 commit = True tag = False message = Bump version: {current_version} → {new_version} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 113d135..7c13730 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: workflow_dispatch: env: - VERSION: 0.3.7 + VERSION: 0.3.8 jobs: release: diff --git a/poetry.lock b/poetry.lock index d89ff2f..2bd5f7a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -130,14 +130,14 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "coverage" -version = "6.4" +version = "6.4.1" description = "Code coverage measurement for Python" category = "dev" optional = false python-versions = ">=3.7" [package.dependencies] -tomli = {version = "*", optional = true, markers = "python_version < \"3.11\" and extra == \"toml\""} +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} [package.extras] toml = ["tomli"] @@ -236,6 +236,19 @@ category = "dev" optional = false python-versions = ">=3.6" +[[package]] +name = "mock" +version = "4.0.3" +description = "Rolling backport of unittest.mock for all Pythons" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.extras] +build = ["twine", "wheel", "blurb"] +docs = ["sphinx"] +test = ["pytest (<5.4)", "pytest-cov"] + [[package]] name = "mypy" version = "0.942" @@ -400,6 +413,20 @@ pytest = ">=4.6" [package.extras] testing = ["fields", "hunter", "process-tests", "six", "pytest-xdist", "virtualenv"] +[[package]] +name = "pytest-mock" +version = "3.6.1" +description = "Thin-wrapper around the mock package for easier use with pytest" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +pytest = ">=5.0" + +[package.extras] +dev = ["pre-commit", "tox", "pytest-asyncio"] + [[package]] name = "pyyaml" version = "6.0" @@ -520,7 +547,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "376605adc63dd7d5f5b2ee06be5a5c656c3c5631a3533b416fa7b27ea156c48e" +content-hash = "77efea91ec1a7df087808032a67aebacf8c760c95928839a4c9e894573bd84a9" [metadata.files] astroid = [ @@ -588,47 +615,47 @@ colorama = [ {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] coverage = [ - {file = "coverage-6.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:50ed480b798febce113709846b11f5d5ed1e529c88d8ae92f707806c50297abf"}, - {file = "coverage-6.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:26f8f92699756cb7af2b30720de0c5bb8d028e923a95b6d0c891088025a1ac8f"}, - {file = "coverage-6.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:60c2147921da7f4d2d04f570e1838db32b95c5509d248f3fe6417e91437eaf41"}, - {file = "coverage-6.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:750e13834b597eeb8ae6e72aa58d1d831b96beec5ad1d04479ae3772373a8088"}, - {file = "coverage-6.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:af5b9ee0fc146e907aa0f5fb858c3b3da9199d78b7bb2c9973d95550bd40f701"}, - {file = "coverage-6.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:a022394996419142b33a0cf7274cb444c01d2bb123727c4bb0b9acabcb515dea"}, - {file = "coverage-6.4-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5a78cf2c43b13aa6b56003707c5203f28585944c277c1f3f109c7b041b16bd39"}, - {file = "coverage-6.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:9229d074e097f21dfe0643d9d0140ee7433814b3f0fc3706b4abffd1e3038632"}, - {file = "coverage-6.4-cp310-cp310-win32.whl", hash = "sha256:fb45fe08e1abc64eb836d187b20a59172053999823f7f6ef4f18a819c44ba16f"}, - {file = "coverage-6.4-cp310-cp310-win_amd64.whl", hash = "sha256:3cfd07c5889ddb96a401449109a8b97a165be9d67077df6802f59708bfb07720"}, - {file = "coverage-6.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:03014a74023abaf5a591eeeaf1ac66a73d54eba178ff4cb1fa0c0a44aae70383"}, - {file = "coverage-6.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9c82f2cd69c71698152e943f4a5a6b83a3ab1db73b88f6e769fabc86074c3b08"}, - {file = "coverage-6.4-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7b546cf2b1974ddc2cb222a109b37c6ed1778b9be7e6b0c0bc0cf0438d9e45a6"}, - {file = "coverage-6.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cc173f1ce9ffb16b299f51c9ce53f66a62f4d975abe5640e976904066f3c835d"}, - {file = "coverage-6.4-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:c53ad261dfc8695062fc8811ac7c162bd6096a05a19f26097f411bdf5747aee7"}, - {file = "coverage-6.4-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:eef5292b60b6de753d6e7f2d128d5841c7915fb1e3321c3a1fe6acfe76c38052"}, - {file = "coverage-6.4-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:543e172ce4c0de533fa892034cce260467b213c0ea8e39da2f65f9a477425211"}, - {file = "coverage-6.4-cp37-cp37m-win32.whl", hash = "sha256:00c8544510f3c98476bbd58201ac2b150ffbcce46a8c3e4fb89ebf01998f806a"}, - {file = "coverage-6.4-cp37-cp37m-win_amd64.whl", hash = "sha256:b84ab65444dcc68d761e95d4d70f3cfd347ceca5a029f2ffec37d4f124f61311"}, - {file = "coverage-6.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d548edacbf16a8276af13063a2b0669d58bbcfca7c55a255f84aac2870786a61"}, - {file = "coverage-6.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:033ebec282793bd9eb988d0271c211e58442c31077976c19c442e24d827d356f"}, - {file = "coverage-6.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:742fb8b43835078dd7496c3c25a1ec8d15351df49fb0037bffb4754291ef30ce"}, - {file = "coverage-6.4-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d55fae115ef9f67934e9f1103c9ba826b4c690e4c5bcf94482b8b2398311bf9c"}, - {file = "coverage-6.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5cd698341626f3c77784858427bad0cdd54a713115b423d22ac83a28303d1d95"}, - {file = "coverage-6.4-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:62d382f7d77eeeaff14b30516b17bcbe80f645f5cf02bb755baac376591c653c"}, - {file = "coverage-6.4-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:016d7f5cf1c8c84f533a3c1f8f36126fbe00b2ec0ccca47cc5731c3723d327c6"}, - {file = "coverage-6.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:69432946f154c6add0e9ede03cc43b96e2ef2733110a77444823c053b1ff5166"}, - {file = "coverage-6.4-cp38-cp38-win32.whl", hash = "sha256:83bd142cdec5e4a5c4ca1d4ff6fa807d28460f9db919f9f6a31babaaa8b88426"}, - {file = "coverage-6.4-cp38-cp38-win_amd64.whl", hash = "sha256:4002f9e8c1f286e986fe96ec58742b93484195defc01d5cc7809b8f7acb5ece3"}, - {file = "coverage-6.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:e4f52c272fdc82e7c65ff3f17a7179bc5f710ebc8ce8a5cadac81215e8326740"}, - {file = "coverage-6.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:b5578efe4038be02d76c344007b13119b2b20acd009a88dde8adec2de4f630b5"}, - {file = "coverage-6.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d8099ea680201c2221f8468c372198ceba9338a5fec0e940111962b03b3f716a"}, - {file = "coverage-6.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a00441f5ea4504f5abbc047589d09e0dc33eb447dc45a1a527c8b74bfdd32c65"}, - {file = "coverage-6.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2e76bd16f0e31bc2b07e0fb1379551fcd40daf8cdf7e24f31a29e442878a827c"}, - {file = "coverage-6.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:8d2e80dd3438e93b19e1223a9850fa65425e77f2607a364b6fd134fcd52dc9df"}, - {file = "coverage-6.4-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:341e9c2008c481c5c72d0e0dbf64980a4b2238631a7f9780b0fe2e95755fb018"}, - {file = "coverage-6.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:21e6686a95025927775ac501e74f5940cdf6fe052292f3a3f7349b0abae6d00f"}, - {file = "coverage-6.4-cp39-cp39-win32.whl", hash = "sha256:968ed5407f9460bd5a591cefd1388cc00a8f5099de9e76234655ae48cfdbe2c3"}, - {file = "coverage-6.4-cp39-cp39-win_amd64.whl", hash = "sha256:e35217031e4b534b09f9b9a5841b9344a30a6357627761d4218818b865d45055"}, - {file = "coverage-6.4-pp36.pp37.pp38-none-any.whl", hash = "sha256:e637ae0b7b481905358624ef2e81d7fb0b1af55f5ff99f9ba05442a444b11e45"}, - {file = "coverage-6.4.tar.gz", hash = "sha256:727dafd7f67a6e1cad808dc884bd9c5a2f6ef1f8f6d2f22b37b96cb0080d4f49"}, + {file = "coverage-6.4.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f1d5aa2703e1dab4ae6cf416eb0095304f49d004c39e9db1d86f57924f43006b"}, + {file = "coverage-6.4.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:4ce1b258493cbf8aec43e9b50d89982346b98e9ffdfaae8ae5793bc112fb0068"}, + {file = "coverage-6.4.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:83c4e737f60c6936460c5be330d296dd5b48b3963f48634c53b3f7deb0f34ec4"}, + {file = "coverage-6.4.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:84e65ef149028516c6d64461b95a8dbcfce95cfd5b9eb634320596173332ea84"}, + {file = "coverage-6.4.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f69718750eaae75efe506406c490d6fc5a6161d047206cc63ce25527e8a3adad"}, + {file = "coverage-6.4.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:e57816f8ffe46b1df8f12e1b348f06d164fd5219beba7d9433ba79608ef011cc"}, + {file = "coverage-6.4.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:01c5615d13f3dd3aa8543afc069e5319cfa0c7d712f6e04b920431e5c564a749"}, + {file = "coverage-6.4.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:75ab269400706fab15981fd4bd5080c56bd5cc07c3bccb86aab5e1d5a88dc8f4"}, + {file = "coverage-6.4.1-cp310-cp310-win32.whl", hash = "sha256:a7f3049243783df2e6cc6deafc49ea123522b59f464831476d3d1448e30d72df"}, + {file = "coverage-6.4.1-cp310-cp310-win_amd64.whl", hash = "sha256:ee2ddcac99b2d2aec413e36d7a429ae9ebcadf912946b13ffa88e7d4c9b712d6"}, + {file = "coverage-6.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:fb73e0011b8793c053bfa85e53129ba5f0250fdc0392c1591fd35d915ec75c46"}, + {file = "coverage-6.4.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:106c16dfe494de3193ec55cac9640dd039b66e196e4641fa8ac396181578b982"}, + {file = "coverage-6.4.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:87f4f3df85aa39da00fd3ec4b5abeb7407e82b68c7c5ad181308b0e2526da5d4"}, + {file = "coverage-6.4.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:961e2fb0680b4f5ad63234e0bf55dfb90d302740ae9c7ed0120677a94a1590cb"}, + {file = "coverage-6.4.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:cec3a0f75c8f1031825e19cd86ee787e87cf03e4fd2865c79c057092e69e3a3b"}, + {file = "coverage-6.4.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:129cd05ba6f0d08a766d942a9ed4b29283aff7b2cccf5b7ce279d50796860bb3"}, + {file = "coverage-6.4.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:bf5601c33213d3cb19d17a796f8a14a9eaa5e87629a53979a5981e3e3ae166f6"}, + {file = "coverage-6.4.1-cp37-cp37m-win32.whl", hash = "sha256:269eaa2c20a13a5bf17558d4dc91a8d078c4fa1872f25303dddcbba3a813085e"}, + {file = "coverage-6.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:f02cbbf8119db68455b9d763f2f8737bb7db7e43720afa07d8eb1604e5c5ae28"}, + {file = "coverage-6.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:ffa9297c3a453fba4717d06df579af42ab9a28022444cae7fa605af4df612d54"}, + {file = "coverage-6.4.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:145f296d00441ca703a659e8f3eb48ae39fb083baba2d7ce4482fb2723e050d9"}, + {file = "coverage-6.4.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d67d44996140af8b84284e5e7d398e589574b376fb4de8ccd28d82ad8e3bea13"}, + {file = "coverage-6.4.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2bd9a6fc18aab8d2e18f89b7ff91c0f34ff4d5e0ba0b33e989b3cd4194c81fd9"}, + {file = "coverage-6.4.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3384f2a3652cef289e38100f2d037956194a837221edd520a7ee5b42d00cc605"}, + {file = "coverage-6.4.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:9b3e07152b4563722be523e8cd0b209e0d1a373022cfbde395ebb6575bf6790d"}, + {file = "coverage-6.4.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:1480ff858b4113db2718848d7b2d1b75bc79895a9c22e76a221b9d8d62496428"}, + {file = "coverage-6.4.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:865d69ae811a392f4d06bde506d531f6a28a00af36f5c8649684a9e5e4a85c83"}, + {file = "coverage-6.4.1-cp38-cp38-win32.whl", hash = "sha256:664a47ce62fe4bef9e2d2c430306e1428ecea207ffd68649e3b942fa8ea83b0b"}, + {file = "coverage-6.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:26dff09fb0d82693ba9e6231248641d60ba606150d02ed45110f9ec26404ed1c"}, + {file = "coverage-6.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d9c80df769f5ec05ad21ea34be7458d1dc51ff1fb4b2219e77fe24edf462d6df"}, + {file = "coverage-6.4.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:39ee53946bf009788108b4dd2894bf1349b4e0ca18c2016ffa7d26ce46b8f10d"}, + {file = "coverage-6.4.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f5b66caa62922531059bc5ac04f836860412f7f88d38a476eda0a6f11d4724f4"}, + {file = "coverage-6.4.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fd180ed867e289964404051a958f7cccabdeed423f91a899829264bb7974d3d3"}, + {file = "coverage-6.4.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:84631e81dd053e8a0d4967cedab6db94345f1c36107c71698f746cb2636c63e3"}, + {file = "coverage-6.4.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:8c08da0bd238f2970230c2a0d28ff0e99961598cb2e810245d7fc5afcf1254e8"}, + {file = "coverage-6.4.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:d42c549a8f41dc103a8004b9f0c433e2086add8a719da00e246e17cbe4056f72"}, + {file = "coverage-6.4.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:309ce4a522ed5fca432af4ebe0f32b21d6d7ccbb0f5fcc99290e71feba67c264"}, + {file = "coverage-6.4.1-cp39-cp39-win32.whl", hash = "sha256:fdb6f7bd51c2d1714cea40718f6149ad9be6a2ee7d93b19e9f00934c0f2a74d9"}, + {file = "coverage-6.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:342d4aefd1c3e7f620a13f4fe563154d808b69cccef415415aece4c786665397"}, + {file = "coverage-6.4.1-pp36.pp37.pp38-none-any.whl", hash = "sha256:4803e7ccf93230accb928f3a68f00ffa80a88213af98ed338a57ad021ef06815"}, + {file = "coverage-6.4.1.tar.gz", hash = "sha256:4321f075095a096e70aff1d002030ee612b65a205a0a0f5b815280d5dc58100c"}, ] dill = [ {file = "dill-0.3.5.1-py2.py3-none-any.whl", hash = "sha256:33501d03270bbe410c72639b350e941882a8b0fd55357580fbc873fba0c59302"}, @@ -701,6 +728,10 @@ mccabe = [ {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, ] +mock = [ + {file = "mock-4.0.3-py3-none-any.whl", hash = "sha256:122fcb64ee37cfad5b3f48d7a7d51875d7031aaf3d8be7c42e2bee25044eee62"}, + {file = "mock-4.0.3.tar.gz", hash = "sha256:7d3fbbde18228f4ff2f1f119a45cdffa458b4c0dee32eb4d2bb2f82554bac7bc"}, +] mypy = [ {file = "mypy-0.942-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:5bf44840fb43ac4074636fd47ee476d73f0039f4f54e86d7265077dc199be24d"}, {file = "mypy-0.942-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dcd955f36e0180258a96f880348fbca54ce092b40fbb4b37372ae3b25a0b0a46"}, @@ -774,6 +805,10 @@ pytest-cov = [ {file = "pytest-cov-3.0.0.tar.gz", hash = "sha256:e7f0f5b1617d2210a2cabc266dfe2f4c75a8d32fb89eafb7ad9d06f6d076d470"}, {file = "pytest_cov-3.0.0-py3-none-any.whl", hash = "sha256:578d5d15ac4a25e5f961c938b85a05b09fdaae9deef3bb6de9a6e766622ca7a6"}, ] +pytest-mock = [ + {file = "pytest-mock-3.6.1.tar.gz", hash = "sha256:40217a058c52a63f1042f0784f62009e976ba824c418cced42e88d5f40ab0e62"}, + {file = "pytest_mock-3.6.1-py3-none-any.whl", hash = "sha256:30c2f2cc9759e76eee674b81ea28c9f0b94f8f0445a1b87762cadf774f0df7e3"}, +] pyyaml = [ {file = "PyYAML-6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53"}, {file = "PyYAML-6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c"}, diff --git a/pyproject.toml b/pyproject.toml index 216f53f..005f985 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vault-assesment-prometheus-exporter" -version = "0.3.7" +version = "0.3.8" description = "Prometheus exporter to monitor custom metadata for KV2 secrets for (self-imposed) expiration." authors = ["Eugene Davis "] readme = "README.md" @@ -31,6 +31,8 @@ types-requests = "2.27.25" types-PyYAML = "6.0.7" bandit = "^1.7.4" bump2version = "^1.0.1" +pytest-mock = "3.6.1" +mock = "4.0.3" [build-system] diff --git a/tests/test_vault_authenticate.py b/tests/test_vault_authenticate.py new file mode 100644 index 0000000..9799697 --- /dev/null +++ b/tests/test_vault_authenticate.py @@ -0,0 +1,194 @@ +import pytest +import os +import mock +import hvac +from pytest_mock import mocker +from mock import call + +import vault_monitor.common.vault_authenticate + + +def test_vault_client_for_user_success(mocker): + test_token = "testtoken1234" + test_url = "https://vault.test.url" + test_namespace = "testnamespace" + + assert isinstance(vault_monitor.common.vault_authenticate.get_vault_client_for_user(url=test_url, namespace=test_namespace, vault_token=test_token), hvac.Client) + + +@mock.patch.dict(os.environ, {"VAULT_ADDR": ""}) +def test_vault_client_for_user_url_runtime(): + test_namespace = "testnamespace" + test_token = "testtoken1234" + test_url = None + + with pytest.raises(RuntimeError): + vault_monitor.common.vault_authenticate.get_vault_client_for_user(url=test_url, namespace=test_namespace, vault_token=test_token) + + +@mock.patch("builtins.open", mock.mock_open(read_data="")) +def test_vault_client_for_user_token_runtime(): + test_namespace = "testnamespace" + test_url = "https://test.vault.url" + + with pytest.raises(RuntimeError): + vault_monitor.common.vault_authenticate.get_vault_client_for_user(url=test_url, namespace=test_namespace) + + +def test_get_authenticated_client_approle(mocker): + test_namespace = "test_namespace" + test_address = "https://vault.test.addr" + test_config = {"approle": {"mount_point": "approle", "role_id": "role_id_test_1234", "secret_id": "secret_id_test_1234"}} + + mock_get_namespace = mocker.patch("vault_monitor.common.vault_authenticate.get_namespace", return_value=test_namespace) + mock_get_address = mocker.patch("vault_monitor.common.vault_authenticate.get_address", return_value=test_address) + + mock_client = mocker.Mock() + mock_return_approle_client = mocker.patch("vault_monitor.common.vault_authenticate.get_client_with_approle_auth", return_value=mock_client) + + vault_monitor.common.vault_authenticate.get_authenticated_client(test_config, test_address, test_namespace) + + mock_get_namespace.assert_called_once_with(test_namespace) + mock_get_address.assert_called_once_with(test_address) + mock_return_approle_client.assert_called_once_with(test_config.get("approle"), test_address, test_namespace) + + +@mock.patch("builtins.open", mock.mock_open(read_data="test_kubernetes_token")) +def test_get_authenticated_client_kubernetes(mocker): + test_namespace = "test_namespace" + test_address = "https://vault.test.addr" + test_config = {"kubernetes": "token_file_path"} + + mock_get_namespace = mocker.patch("vault_monitor.common.vault_authenticate.get_namespace", return_value=test_namespace) + mock_get_address = mocker.patch("vault_monitor.common.vault_authenticate.get_address", return_value=test_address) + + mock_client = mocker.Mock() + mock_return_approle_client = mocker.patch("vault_monitor.common.vault_authenticate.get_client_with_kubernetes_auth", return_value=mock_client) + + vault_monitor.common.vault_authenticate.get_authenticated_client(test_config, test_address, test_namespace) + + mock_get_namespace.assert_called_once_with(test_namespace) + mock_get_address.assert_called_once_with(test_address) + mock_return_approle_client.assert_called_once_with(test_config.get("kubernetes"), test_address, test_namespace) + + +@mock.patch("builtins.open", mock.mock_open(read_data="test_token")) +def test_get_authenticated_client_token(mocker): + test_namespace = "test_namespace" + test_address = "https://vault.test.addr" + test_config = {"token": "token_file_path"} + + mock_get_namespace = mocker.patch("vault_monitor.common.vault_authenticate.get_namespace", return_value=test_namespace) + mock_get_address = mocker.patch("vault_monitor.common.vault_authenticate.get_address", return_value=test_address) + + mock_client = mocker.Mock() + mock_return_approle_client = mocker.patch("vault_monitor.common.vault_authenticate.get_client_with_token_auth", return_value=mock_client) + + vault_monitor.common.vault_authenticate.get_authenticated_client(test_config, test_address, test_namespace) + + mock_get_namespace.assert_called_once_with(test_namespace) + mock_get_address.assert_called_once_with(test_address) + mock_return_approle_client.assert_called_once_with(test_config.get("token"), test_address, test_namespace) + + +@mock.patch.dict(os.environ, {"VAULT_NAMESPACE": "testnamespace"}) +def test_get_namespace(mocker): + test_namespace = "testnamespace" + assert vault_monitor.common.vault_authenticate.get_namespace() == test_namespace + + +@mock.patch.dict(os.environ, {"VAULT_ADDR": "https://test.vault.addr"}) +def test_get_address(mocker): + test_address = "https://test.vault.addr" + assert vault_monitor.common.vault_authenticate.get_address() == test_address + + +@mock.patch("builtins.open", mock.mock_open(read_data="asdf-1243")) +@mock.patch.dict(os.environ, {"ROLE_ID": "1243-asdf"}) +def test_get_client_with_approle_auth_creds_in_file(mocker): + test_config = { + "mount_point": "approle", + "role_id_variable": "ROLE_ID", + "secret_id_file": "secret_file", + } + test_address = "https://vault.test.addr" + test_namespace = "testnamespace" + + mock_client = mocker.Mock() + mock_get_client = mocker.patch("vault_monitor.common.vault_authenticate.hvac.Client", return_value=mock_client) + + vault_monitor.common.vault_authenticate.get_client_with_approle_auth(config=test_config, address=test_address, namespace=test_namespace) + + mock_get_client.assert_called_once_with(url=test_address, namespace=test_namespace) + mock_client.auth.approle.login.assert_called_once_with(role_id="1243-asdf", secret_id="asdf-1243", mount_point="approle") + + +@mock.patch("builtins.open", mock.mock_open(read_data="1243-asdf")) +@mock.patch.dict(os.environ, {"SECRET_ID": "asdf-1243"}) +def test_get_client_with_approle_auth_creds_in_env(mocker): + test_config = { + "mount_point": "approle", + "role_id_file": "role_file", + "secret_id_variable": "SECRET_ID", + } + test_address = "https://vault.test.addr" + test_namespace = "testnamespace" + + mock_client = mocker.Mock() + mock_get_client = mocker.patch("vault_monitor.common.vault_authenticate.hvac.Client", return_value=mock_client) + + vault_monitor.common.vault_authenticate.get_client_with_approle_auth(config=test_config, address=test_address, namespace=test_namespace) + + mock_get_client.assert_called_once_with(url=test_address, namespace=test_namespace) + mock_client.auth.approle.login.assert_called_once_with(role_id="1243-asdf", secret_id="asdf-1243", mount_point="approle") + + +def test_get_client_with_approle_auth_creds_in_config(mocker): + test_config = { + "mount_point": "approle", + "role_id": "1243-asdf", + "secret_id": "asdf-1243", + } + test_address = "https://vault.test.addr" + test_namespace = "testnamespace" + + mock_client = mocker.Mock() + mock_get_client = mocker.patch("vault_monitor.common.vault_authenticate.hvac.Client", return_value=mock_client) + + vault_monitor.common.vault_authenticate.get_client_with_approle_auth(config=test_config, address=test_address, namespace=test_namespace) + + mock_get_client.assert_called_once_with(url=test_address, namespace=test_namespace) + mock_client.auth.approle.login.assert_called_once_with(role_id="1243-asdf", secret_id="asdf-1243", mount_point="approle") + + +@mock.patch("builtins.open", mock.mock_open(read_data="test_kubernetes_token")) +def test_get_client_with_kubernetes_auth(mocker): + test_config = {"mount_point": "kubernetes", "token_file": "/var/run/secrets/kubernetes.io/serviceaccount/token"} + test_namespace = "testnamespace" + test_address = "https://vault.test.addr" + + mock_client = mocker.Mock() + mock_get_client = mocker.patch("vault_monitor.common.vault_authenticate.hvac.Client", return_value=mock_client) # check it's getting called with line 120 (original) + + vault_monitor.common.vault_authenticate.get_client_with_kubernetes_auth(config=test_config, address=test_address, namespace=test_namespace) + + mock_get_client.assert_called_once_with(url=test_address, namespace=test_namespace) + mock_client.auth_kubernetes.assert_called_once_with("kubernetes", "test_kubernetes_token") + + +@mock.patch.dict(os.environ, {"VAULT_TOKEN": "test_token"}) +def test_get_client_with_token_auth_var_success(): + test_config = {"token_var_name": "VAULT_TOKEN"} + test_address = "https://test.vault.addr" + test_namespace = "testnamespace" + + assert isinstance(vault_monitor.common.vault_authenticate.get_client_with_token_auth(config=test_config, address=test_address, namespace=test_namespace), hvac.Client) + + +@mock.patch("builtins.open", mock.mock_open(read_data="test_token")) +def test_get_client_with_token_auth_file_success(): + test_config = {"token_file": "~/.vault-token"} + test_address = "https://test.vault.addr" + test_namespace = "testnamespace" + + assert isinstance(vault_monitor.common.vault_authenticate.get_client_with_token_auth(config=test_config, address=test_address, namespace=test_namespace), hvac.Client)