From 9ca14407a145ffbdbce80f79d734580bd0f609fe Mon Sep 17 00:00:00 2001 From: Aleksandr Chikovani Date: Wed, 18 Dec 2024 00:01:30 -0500 Subject: [PATCH] chore: removed unexpected changes those changes were caused by long-running MR. some changes were applied to develop, and were rewritten. --- .github/workflows/unit-tests.yml | 11 +--------- mlflow_oidc_auth/tests/test_auth.py | 24 +++++++++++++++++++++ pyproject.toml | 33 +++++++++++++++++------------ 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index b3cf1a0..1097cce 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -19,22 +19,13 @@ jobs: uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1 with: python-version: 3.11 - - name: Install build dependencies + - name: Run tests run: | python -m pip install --upgrade pip pip install tox tox -e py - - name: Build coverage file - run: | - tox -e py - pytest --cache-clear --junitxml=coverage.xml --cov-report=term-missing:skip-covered --cov=mlflow_oidc_auth > pytest-coverage.txt - name: Override Coverage Source Path for Sonar run: sed -i "s@/home/runner/work/mlflow-oidc-auth/mlflow-oidc-auth@/github/workspace@g" /home/runner/work/mlflow-oidc-auth/mlflow-oidc-auth/coverage.xml - - name: debug cov - run: | - pwd - ls -alh - head -n50 coverage.xml - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@e44258b109568baa0df60ed515909fc6c72cba92 # v2.3.0 env: diff --git a/mlflow_oidc_auth/tests/test_auth.py b/mlflow_oidc_auth/tests/test_auth.py index 9e534d9..ca42820 100644 --- a/mlflow_oidc_auth/tests/test_auth.py +++ b/mlflow_oidc_auth/tests/test_auth.py @@ -6,6 +6,7 @@ authenticate_request_basic_auth, authenticate_request_bearer_token, ) +import importlib class TestAuth: @@ -33,6 +34,29 @@ def test_get_oauth_instance(self, mock_config, mock_oauth): ) assert result == mock_oauth_instance + def test__get_oidc_jwks(self): + with patch("mlflow_oidc_auth.auth.requests") as mock_requests: + mlflow_oidc_app = importlib.import_module("mlflow_oidc_auth.app") + mock_cache = MagicMock() + mock_app = MagicMock() + mock_app.logger.debug = MagicMock() + mock_requests.get.return_value.json.return_value = {"jwks_uri": "mock_jwks_uri"} + mock_cache.get.return_value = None + + with patch.object(mlflow_oidc_app, "cache", mock_cache): + with patch.object(mlflow_oidc_app, "app", mock_app): + result = _get_oidc_jwks() + + assert len(mock_requests.get.call_args) == 2 + + assert mock_requests.get.call_args[0][0] == "mock_jwks_uri" + assert mock_requests.get.call_args[1] == {} # TODO: proper patch for first .get() return_value + + mock_cache.set.assert_called_once_with( + "jwks", mock_requests.get.return_value.json.return_value, timeout=3600 + ) + assert result == mock_requests.get.return_value.json.return_value + @patch("mlflow_oidc_auth.auth._get_oidc_jwks") @patch("mlflow_oidc_auth.auth.jwt.decode") def test_validate_token(self, mock_jwt_decode, mock_get_oidc_jwks): diff --git a/pyproject.toml b/pyproject.toml index 6bb35f3..013d048 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ classifiers = [ requires-python = ">=3.8" dependencies = [ "cachelib<1", + "mlflow-skinny<3,>=2.11.1", "mlflow<3,>=2.11.1", "oauthlib<4", "python-dotenv<2", @@ -30,13 +31,30 @@ dependencies = [ "sqlalchemy<3,>=1.4.0", "Flask<4", "Flask-Session>=0.7.0", + "gunicorn<24; platform_system != 'Windows'", + "alembic<2,!=1.10.0", + "Authlib<2", + "Flask-Caching<3", "authlib>=1.3.2", "flask-caching>=2.3.0" ] +[project.optional-dependencies] +full = ["mlflow<3,>=2.11.1"] +caching-redis = ["redis[hiredis]<6"] +dev = [ + "black==24.8.0", + "pytest==8.3.2", + "pre-commit==3.5.0", +] +test = [ + "pytest==8.3.2", + "pytest-cov==5.0.0", +] + [[project.maintainers]] -name = "Data Platform folks" -email = "noreply@example.com" +name = "Alexander Kharkevich" +email = "alexander_kharkevich@outlook.com" [project.license] file = "LICENSE" @@ -72,14 +90,3 @@ version = {attr = "mlflow_oidc_auth.version"} [tool.black] line-length = 128 - -[project.optional-dependencies] -dev = [ - "black==24.8.0", - "pytest==8.3.2", - "pre-commit==3.5.0", -] -test = [ - "pytest==8.3.2", - "pytest-cov==5.0.0", -]