diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7678fec..6ef560f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,4 +30,4 @@ jobs: - name: Run unit tests run: | - make unit \ No newline at end of file + make unit diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..24ee5b1 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.13 diff --git a/Makefile b/Makefile index 9d39bab..c0cfb38 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,14 @@ VENV_PYTHON:=venv/bin/python -VENV_REQS:=.requirements.venv SRCS:=$(shell find src tests -name '*.py') all: test -# BSD `sed` treats the `-i` option differently than Linux and others. -# Check for Mac OS X 'Darwin' and set our `-i` option accordingly. -ifeq ($(UNAME), Darwin) -# macOS (BSD sed) - SED_INPLACE := -i '' -else -# Linux and others (GNU sed) - SED_INPLACE := -i -endif - -venv: requirements-test.txt +venv: requirements-test.in rm -rf $@ python -m venv venv - $(VENV_PYTHON) -m pip install -r requirements-test.txt + $(VENV_PYTHON) -m pip install -r $^ # Install dependencies from pyproject.toml $(VENV_PYTHON) -m pip install -e . - - -requirements-test.txt: export VCR_CLEANER_REPO=git+https://github.com/techservicesillinois/vcrpy-cleaner.git -requirements-test.txt: requirements-test.in - rm -rf $(VENV_REQS) - python -m venv $(VENV_REQS) - # Workaround for wheel install failures. - $(VENV_REQS)/bin/python -m pip install --upgrade pip - $(VENV_REQS)/bin/python -m pip install -r $^ - $(VENV_REQS)/bin/python -m pip freeze -qqq > $@ - sed $(SED_INPLACE) "s;^vcr-cleaner==.*;$(VCR_CLEANER_REPO);" $@ lint: venv .lint .lint: $(SRCS) $(TSCS) @@ -53,10 +31,9 @@ unit: venv test: lint static unit clean: - rm -rf venv $(VENV_REQS) rm -rf .lint .static rm -rf .mypy_cache -find src -type d -name __pycache__ -exec rm -fr "{}" \; force-clean: clean - rm -f requirements-test.txt \ No newline at end of file + rm -rf venv diff --git a/cassettes/test_404_disable_mac.yaml b/cassettes/test_404_disable_mac.yaml index 30a3f2a..15848a1 100644 --- a/cassettes/test_404_disable_mac.yaml +++ b/cassettes/test_404_disable_mac.yaml @@ -14,9 +14,9 @@ interactions: Content-Type: - application/json User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: POST - uri: https://notauri.edu/api/oauth + uri: https://cleaned.example.edu/api/oauth response: body: string: '{"access_token": "NOTASECRET"}' @@ -30,7 +30,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 05 Aug 2024 16:40:43 GMT + - Mon, 17 Nov 2025 22:02:31 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -44,8 +44,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK @@ -61,9 +65,9 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/endpoint/mac-address/deadbeef1234 + uri: https://cleaned.example.edu/api/endpoint/mac-address/deadbeef1234 response: body: string: '{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Not @@ -78,7 +82,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 05 Aug 2024 16:40:43 GMT + - Mon, 17 Nov 2025 22:02:31 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -92,8 +96,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 404 message: Not Found diff --git a/cassettes/test_404_enable_mac.yaml b/cassettes/test_404_enable_mac.yaml index 4ea1f5c..c545c36 100644 --- a/cassettes/test_404_enable_mac.yaml +++ b/cassettes/test_404_enable_mac.yaml @@ -14,9 +14,9 @@ interactions: Content-Type: - application/json User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: POST - uri: https://notauri.edu/api/oauth + uri: https://cleaned.example.edu/api/oauth response: body: string: '{"access_token": "NOTASECRET"}' @@ -30,7 +30,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 05 Aug 2024 16:40:44 GMT + - Mon, 17 Nov 2025 22:02:33 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -44,8 +44,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK @@ -61,9 +65,9 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/endpoint/mac-address/deadbeef1234 + uri: https://cleaned.example.edu/api/endpoint/mac-address/deadbeef1234 response: body: string: '{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Not @@ -78,7 +82,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 05 Aug 2024 16:40:44 GMT + - Mon, 17 Nov 2025 22:02:34 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -92,8 +96,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 404 message: Not Found diff --git a/cassettes/test_connectivity.yaml b/cassettes/test_connectivity.yaml index 0178a47..bf2cf93 100644 --- a/cassettes/test_connectivity.yaml +++ b/cassettes/test_connectivity.yaml @@ -14,12 +14,12 @@ interactions: Content-Type: - application/json User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: POST - uri: https://notauri.edu/api/oauth + uri: https://cleaned.example.edu/api/oauth response: body: - string: '{"access_token": "CLEANED"}' + string: '{"access_token": "NOTASECRET"}' headers: Cache-Control: - no-store @@ -30,7 +30,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 22 Jul 2024 20:38:25 GMT + - Mon, 17 Nov 2025 22:02:28 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -39,14 +39,17 @@ interactions: - no-cache Server: - Apache - Set-Cookie: - - GSID=3cabr753nknijgm1unpfbv7eqk; path=/; secure; HttpOnly; SameSite=Lax + Set-Cookie: NO-COOKIE-FOR-YOU Vary: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK diff --git a/cassettes/test_disable_mac.yaml b/cassettes/test_disable_mac.yaml index 8b7eefe..0776e75 100644 --- a/cassettes/test_disable_mac.yaml +++ b/cassettes/test_disable_mac.yaml @@ -14,9 +14,9 @@ interactions: Content-Type: - application/json User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: POST - uri: https://notauri.edu/api/oauth + uri: https://cleaned.example.edu/api/oauth response: body: string: '{"access_token": "NOTASECRET"}' @@ -30,7 +30,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 05 Aug 2024 16:31:44 GMT + - Mon, 17 Nov 2025 22:02:29 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -44,8 +44,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK @@ -61,13 +65,13 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/endpoint/mac-address/123123123123 + uri: https://cleaned.example.edu/api/endpoint/mac-address/123123123123 response: body: string: '{"id":4524,"mac_address":"123123123123","status":"Known","randomized_mac":true,"attributes":{},"added_at":"Nov - 15, 2023 14:52:34 CST","updated_at":"Aug 05, 2024 11:27:32 CDT","_stuff":"deleted"}' + 15, 2023 14:52:34 CST","updated_at":"Nov 17, 2025 15:02:29 CST","_links":{"self":{"href":"https:\/\/cleaned.example.edu\/api\/endpoint\/4524"}}}' headers: Cache-Control: - no-store, no-cache, must-revalidate @@ -78,7 +82,7 @@ interactions: Content-Type: - application/hal+json Date: - - Mon, 05 Aug 2024 16:31:45 GMT + - Mon, 17 Nov 2025 22:02:30 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -92,8 +96,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK @@ -114,14 +122,14 @@ interactions: Content-Type: - application/json User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: PUT - uri: https://notauri.edu/api/endpoint/4524 + uri: https://cleaned.example.edu/api/endpoint/4524 response: body: string: '{"id":4524,"mac_address":"123123123123","status":"Disabled","randomized_mac":true,"attributes":{"Disabled By":"TESTING","Disabled Reason":"Still testing..."},"added_at":"Nov 15, 2023 - 14:52:34 CST","updated_at":"Aug 05, 2024 11:31:45 CDT","stuff":"deleted"}' + 14:52:34 CST","updated_at":"Nov 17, 2025 16:02:30 CST","_links":{"self":{"href":"https:\/\/cleaned.example.edu\/api\/endpoint\/4524"}}}' headers: Cache-Control: - no-store, no-cache, must-revalidate @@ -132,7 +140,7 @@ interactions: Content-Type: - application/hal+json Date: - - Mon, 05 Aug 2024 16:31:45 GMT + - Mon, 17 Nov 2025 22:02:30 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -146,8 +154,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK diff --git a/cassettes/test_enable_mac.yaml b/cassettes/test_enable_mac.yaml index 686eea1..a336e37 100644 --- a/cassettes/test_enable_mac.yaml +++ b/cassettes/test_enable_mac.yaml @@ -14,9 +14,9 @@ interactions: Content-Type: - application/json User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: POST - uri: https://notauri.edu/api/oauth + uri: https://cleaned.example.edu/api/oauth response: body: string: '{"access_token": "NOTASECRET"}' @@ -30,7 +30,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 05 Aug 2024 16:27:31 GMT + - Mon, 17 Nov 2025 22:02:32 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -44,8 +44,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK @@ -61,25 +65,25 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/endpoint/mac-address/123123123123 + uri: https://cleaned.example.edu/api/endpoint/mac-address/123123123123 response: body: string: '{"id":4524,"mac_address":"123123123123","status":"Disabled","randomized_mac":true,"attributes":{"Disabled - By":"automation","Disabled Reason":"Disabled"},"added_at":"Nov 15, 2023 14:52:34 - CST","updated_at":"Mar 28, 2024 15:31:54 CDT","stuff":"deleted"}' + By":"TESTING","Disabled Reason":"Still testing..."},"added_at":"Nov 15, 2023 + 14:52:34 CST","updated_at":"Nov 17, 2025 16:02:30 CST","_links":{"self":{"href":"https:\/\/cleaned.example.edu\/api\/endpoint\/4524"}}}' headers: Cache-Control: - no-store, no-cache, must-revalidate Connection: - Keep-Alive Content-Length: - - '325' + - '330' Content-Type: - application/hal+json Date: - - Mon, 05 Aug 2024 16:27:31 GMT + - Mon, 17 Nov 2025 22:02:32 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -93,8 +97,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK @@ -114,13 +122,13 @@ interactions: Content-Type: - application/json User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: PUT - uri: https://notauri.edu/api/endpoint/4524 + uri: https://cleaned.example.edu/api/endpoint/4524 response: body: string: '{"id":4524,"mac_address":"123123123123","status":"Known","randomized_mac":true,"attributes":{},"added_at":"Nov - 15, 2023 14:52:34 CST","updated_at":"Aug 05, 2024 11:27:32 CDT","stuff":"deleted"}' + 15, 2023 14:52:34 CST","updated_at":"Nov 17, 2025 16:02:33 CST","_links":{"self":{"href":"https:\/\/cleaned.example.edu\/api\/endpoint\/4524"}}}' headers: Cache-Control: - no-store, no-cache, must-revalidate @@ -131,7 +139,7 @@ interactions: Content-Type: - application/hal+json Date: - - Mon, 05 Aug 2024 16:27:32 GMT + - Mon, 17 Nov 2025 22:02:33 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -145,8 +153,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK diff --git a/cassettes/test_failed_connectivity.yaml b/cassettes/test_failed_connectivity.yaml index 3a9ae4d..bd4b941 100644 --- a/cassettes/test_failed_connectivity.yaml +++ b/cassettes/test_failed_connectivity.yaml @@ -16,7 +16,7 @@ interactions: User-Agent: - python-requests/2.32.3 method: POST - uri: https://notauri.edu/api/oauth + uri: https://cleaned.example.edu/api/oauth response: body: string: '{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"invalid_client","status":400,"detail":"The diff --git a/cassettes/test_get_info_for_mac_address.yaml b/cassettes/test_get_info_for_mac_address.yaml index bd2dbef..9b9ee49 100644 --- a/cassettes/test_get_info_for_mac_address.yaml +++ b/cassettes/test_get_info_for_mac_address.yaml @@ -14,9 +14,9 @@ interactions: Content-Type: - application/json User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: POST - uri: https://notauri.edu/api/oauth + uri: https://cleaned.example.edu/api/oauth response: body: string: '{"access_token": "NOTASECRET"}' @@ -30,7 +30,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 05 Aug 2024 19:44:09 GMT + - Mon, 17 Nov 2025 22:02:34 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -44,8 +44,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK @@ -61,25 +65,24 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/endpoint?filter=%7B%22mac_address%22%3A%20%22123123123123%22%7D + uri: https://cleaned.example.edu/api/endpoint?filter=%7B%22mac_address%22%3A%20%22123123123123%22%7D response: body: - string: '{"_embedded":{"items":[{"id":4524,"mac_address":"123123123123","status":"Disabled","randomized_mac":true,"attributes":{"Disabled - By":"TESTING","Disabled Reason":"Still testing..."},"added_at":"Nov 15, 2023 - 14:52:34 CST","updated_at":"Aug 05, 2024 11:31:45 CDT","_links":{"self":{"stuff":"cleaned"}}}]}}' + string: '{"_links":{"self":{"href":"https:\/\/cleaned.example.edu\/api\/endpoint?calculate_count=false\u0026offset=0\u0026limit=25\u0026sort=%2Bid\u0026filter=%7B%22mac_address%22%3A+%22123123123123%22%7D"},"first":{"href":"https:\/\/cleaned.example.edu\/api\/endpoint?calculate_count=false\u0026offset=0\u0026limit=25\u0026sort=%2Bid\u0026filter=%7B%22mac_address%22%3A+%22123123123123%22%7D"}},"_embedded":{"items":[{"id":4524,"mac_address":"123123123123","status":"Known","randomized_mac":true,"attributes":{},"added_at":"Nov + 15, 2023 14:52:34 CST","updated_at":"Nov 17, 2025 16:02:33 CST","_links":{"self":{"href":"https:\/\/cleaned.example.edu\/api\/endpoint\/4524"}}}]}}' headers: Cache-Control: - no-store, no-cache, must-revalidate Connection: - Keep-Alive Content-Length: - - '766' + - '703' Content-Type: - application/hal+json Date: - - Mon, 05 Aug 2024 19:44:09 GMT + - Mon, 17 Nov 2025 22:02:35 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -93,8 +96,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 200 message: OK @@ -110,9 +117,9 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/device?filter=%7B%22mac%22%3A%20%2212-31-23-12-31-23%22%7D + uri: https://cleaned.example.edu/api/device?filter=%7B%22mac%22%3A%20%2212-31-23-12-31-23%22%7D response: body: string: '{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Forbidden","status":403,"detail":"Access @@ -127,7 +134,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 05 Aug 2024 19:44:10 GMT + - Mon, 17 Nov 2025 22:02:35 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -141,8 +148,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 403 message: Forbidden @@ -158,9 +169,9 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/guest?filter=%7B%22mac%22%3A%20%2212-31-23-12-31-23%22%7D + uri: https://cleaned.example.edu/api/guest?filter=%7B%22mac%22%3A%20%2212-31-23-12-31-23%22%7D response: body: string: '{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Forbidden","status":403,"detail":"Access @@ -175,7 +186,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 05 Aug 2024 19:44:10 GMT + - Mon, 17 Nov 2025 22:02:36 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -189,8 +200,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 403 message: Forbidden @@ -206,9 +221,9 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/session?filter=%7B%22mac_address%22%3A%20%22123123123123%22%7D + uri: https://cleaned.example.edu/api/session?filter=%7B%22mac_address%22%3A%20%22123123123123%22%7D response: body: string: '{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Forbidden","status":403,"detail":"Access @@ -223,7 +238,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 05 Aug 2024 19:44:10 GMT + - Mon, 17 Nov 2025 22:02:36 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -237,8 +252,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 403 message: Forbidden @@ -254,9 +273,9 @@ interactions: Connection: - keep-alive User-Agent: - - python-requests/2.32.3 + - python-requests/2.32.5 method: GET - uri: https://notauri.edu/api/insight/endpoint/mac/123123123123 + uri: https://cleaned.example.edu/api/insight/endpoint/mac/123123123123 response: body: string: '{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Not @@ -271,7 +290,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 05 Aug 2024 19:44:10 GMT + - Mon, 17 Nov 2025 22:02:37 GMT Expires: - Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: @@ -285,8 +304,12 @@ interactions: - X-Forwarded-For X-Content-Type-Options: - nosniff + - nosniff + X-Frame-Options: + - SAMEORIGIN X-XSS-Protection: - 1;mode=block + - 1;mode=block status: code: 404 message: Not Found diff --git a/requirements-test.in b/requirements-test.in index 8773007..7824dd9 100644 --- a/requirements-test.in +++ b/requirements-test.in @@ -23,5 +23,3 @@ setuptools-scm vcrpy git+https://github.com/techservicesillinois/vcrpy-cleaner.git yq -# Requirements are also here because pyproject.toml and pip are dumb -requests diff --git a/requirements-test.txt b/requirements-test.txt deleted file mode 100644 index f3f5927..0000000 --- a/requirements-test.txt +++ /dev/null @@ -1,70 +0,0 @@ -argcomplete==3.6.2 -asttokens==3.0.0 -autopep8==2.3.2 -certifi==2025.4.26 -cfgv==3.4.0 -charset-normalizer==3.4.2 -coverage==7.8.2 -decorator==5.2.1 -detect-secrets==1.5.0 -distlib==0.3.9 -exceptiongroup==1.3.0 -executing==2.2.0 -filelock==3.18.0 -flake8==7.2.0 -identify==2.6.12 -idna==3.10 -importlib_metadata==8.7.0 -iniconfig==2.1.0 -ipdb==0.13.13 -ipython==8.18.1 -jedi==0.19.2 -matplotlib-inline==0.1.7 -mccabe==0.7.0 -multidict==6.4.4 -mypy==1.16.0 -mypy_extensions==1.1.0 -nodeenv==1.9.1 -packaging==25.0 -parso==0.8.4 -pathspec==0.12.1 -pexpect==4.9.0 -platformdirs==4.3.8 -pluggy==1.6.0 -pre_commit==4.2.0 -prompt_toolkit==3.0.51 -propcache==0.3.2 -ptyprocess==0.7.0 -pure_eval==0.2.3 -pycodestyle==2.13.0 -pyflakes==3.3.2 -Pygments==2.19.1 -PyJWT==2.10.1 -pytest==8.4.0 -PyYAML==6.0.2 -requests==2.32.4 -setuptools-scm==8.3.1 -stack-data==0.6.3 -tomli==2.2.1 -tomlkit==0.13.3 -traitlets==5.14.3 -types-PyMySQL==1.1.0.20250516 -types-python-dateutil==2.9.0.20250516 -types-pytz==2025.2.0.20250516 -types-PyYAML==6.0.12.20250516 -types-requests==2.31.0.6 -types-setuptools==80.9.0.20250529 -types-simplejson==3.20.0.20250326 -types-six==1.17.0.20250515 -types-urllib3==1.26.25.14 -typing_extensions==4.14.0 -urllib3==1.26.19 -vcr_cleaner @ git+https://github.com/techservicesillinois/vcrpy-cleaner.git@82bd9745642e81b2f794781aec89676540fab5cc -vcrpy==7.0.0 -virtualenv==20.31.2 -wcwidth==0.2.13 -wrapt==1.17.2 -xmltodict==0.14.2 -yarl==1.20.1 -yq==3.4.3 -zipp==3.23.0 diff --git a/tests/conftest.py b/tests/conftest.py index 617bc56..892a92c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,18 +4,21 @@ import pytest import vcr +import logging from clearpass.client import APIConnection +from vcr_cleaner import CleanYAMLSerializer +from vcr_cleaner.filters import if_uri_endswith +from vcr_cleaner.cleaners.uri import clean_domains -from vcr_cleaner import CleanYAMLSerializer, clean_if - +# Set up logger +logger = logging.getLogger(__name__) CASSETTE_USERNAME = "JOE" CASSETTE_PASSWORD = "NOTAPASSWORD" # pragma: allowlist secret -CASSETTE_ENDPOINT = "notauri.edu" +CASSETTE_ENDPOINT = "cleaned.example.edu" CASSETTE_CLIENT_ID = "FAKEID" CASSETTE_CLIENT_SECRET = "NOTASECRET" # pragma: allowlist secret -URL = f"https://{CASSETTE_ENDPOINT}" CLEANER_SALT = 'salty' CLEANER_JWT_TOKEN = {'exp': datetime.datetime(2049, 6, 25)} @@ -57,10 +60,18 @@ def clean_cookie(request: dict, response: dict): response['headers']['Set-Cookie'] = 'NO-COOKIE-FOR-YOU' -@clean_if(uri=f"{URL}/api/oauth") def clean_token(request: dict, response: dict): '''Clean a JSON token.''' - token = {'access_token': 'NOTASECRET'} + message = "NOTASECRET" + try: + token = json.loads(response['body']['string']) + if 'access_token' not in token: + logger.warning(f"No access_token in token response: {token}") + message = "ERROR: ACCESS TOKEN NOT FOUND" + except json.JSONDecodeError: + logger.warning(f"Token response is not valid JSON: {token}") + message = "ERROR: ACCESS TOKEN NOT FOUND: INVALID JSON" + token = {'access_token': message} response['body']['string'] = json.dumps(token) @@ -82,14 +93,6 @@ def remove_creds(request): return request -def clean_uri(request: dict, response: dict): - if "uri" not in request.keys(): - return request - request['uri'] = request['uri'].replace( - os.environ.get("CLEARPASS_ENDPOINT"), CASSETTE_ENDPOINT) - return request - - @pytest.fixture def cassette(request) -> vcr.cassette.Cassette: my_vcr = vcr.VCR( @@ -102,9 +105,8 @@ def cassette(request) -> vcr.cassette.Cassette: yaml_cleaner = CleanYAMLSerializer() my_vcr.register_serializer("cleanyaml", yaml_cleaner) - # TODO: Register cleaner functions here: - yaml_cleaner.register_cleaner(clean_uri) - yaml_cleaner.register_cleaner(clean_token) + yaml_cleaner.register_cleaner(clean_domains('illinois.edu')) + yaml_cleaner.register_cleaner(if_uri_endswith("/api/oauth", clean_token)) yaml_cleaner.register_cleaner(clean_cookie) with my_vcr.use_cassette(f'{request.function.__name__}.yaml', diff --git a/tests/test_connector.py b/tests/test_connector.py index df76dc8..215ff32 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -8,6 +8,8 @@ def test_connectivity(cassette, clearpass_client): def test_failed_connectivity(cassette, clearpass_client): result = clearpass_client.test_connectivity() + # This cassette is handcrafted. Expect a failure if you use valid + # credentials. Expect to lock yourself out if you use invalid credentials. assert result is False