lsst-ctrl-bps-panda 29.2025.4100__tar.gz → 29.2025.4200__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {lsst_ctrl_bps_panda-29.2025.4100/python/lsst_ctrl_bps_panda.egg-info → lsst_ctrl_bps_panda-29.2025.4200}/PKG-INFO +1 -1
  2. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/cli/cmd/__init__.py +2 -2
  3. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/cli/cmd/panda_auth_commands.py +17 -1
  4. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/panda_auth_drivers.py +28 -1
  5. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/panda_auth_utils.py +97 -0
  6. lsst_ctrl_bps_panda-29.2025.4200/python/lsst/ctrl/bps/panda/panda_exceptions.py +34 -0
  7. lsst_ctrl_bps_panda-29.2025.4200/python/lsst/ctrl/bps/panda/version.py +2 -0
  8. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200/python/lsst_ctrl_bps_panda.egg-info}/PKG-INFO +1 -1
  9. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst_ctrl_bps_panda.egg-info/SOURCES.txt +1 -0
  10. lsst_ctrl_bps_panda-29.2025.4200/tests/test_panda_auth_utils.py +151 -0
  11. lsst_ctrl_bps_panda-29.2025.4100/python/lsst/ctrl/bps/panda/version.py +0 -2
  12. lsst_ctrl_bps_panda-29.2025.4100/tests/test_panda_auth_utils.py +0 -64
  13. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/COPYRIGHT +0 -0
  14. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/LICENSE +0 -0
  15. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/README.rst +0 -0
  16. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/bsd_license.txt +0 -0
  17. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/gpl-v3.0.txt +0 -0
  18. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/pyproject.toml +0 -0
  19. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/__init__.py +0 -0
  20. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/cli/__init__.py +0 -0
  21. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/cli/panda_auth.py +0 -0
  22. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/cmd_line_embedder.py +0 -0
  23. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/conf_example/example_panda_SLAC.yaml +0 -0
  24. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/conf_example/pipelines_check_idf.yaml +0 -0
  25. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/conf_example/test_idf.yaml +0 -0
  26. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/conf_example/test_sdf.yaml +0 -0
  27. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/conf_example/test_usdf.yaml +0 -0
  28. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/constants.py +0 -0
  29. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/edgenode/__init__.py +0 -0
  30. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/edgenode/build_cmd_line_decoder.py +0 -0
  31. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/edgenode/cmd_line_decoder.py +0 -0
  32. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/panda_service.py +0 -0
  33. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst/ctrl/bps/panda/utils.py +0 -0
  34. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst_ctrl_bps_panda.egg-info/dependency_links.txt +0 -0
  35. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst_ctrl_bps_panda.egg-info/requires.txt +0 -0
  36. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst_ctrl_bps_panda.egg-info/top_level.txt +0 -0
  37. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/python/lsst_ctrl_bps_panda.egg-info/zip-safe +0 -0
  38. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/setup.cfg +0 -0
  39. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/tests/test_cmd_line_decoder.py +0 -0
  40. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/tests/test_cmd_line_embedder.py +0 -0
  41. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/tests/test_panda_service.py +0 -0
  42. {lsst_ctrl_bps_panda-29.2025.4100 → lsst_ctrl_bps_panda-29.2025.4200}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lsst-ctrl-bps-panda
3
- Version: 29.2025.4100
3
+ Version: 29.2025.4200
4
4
  Summary: PanDA plugin for lsst-ctrl-bps.
5
5
  Author-email: Rubin Observatory Data Management <dm-admin@lists.lsst.org>
6
6
  License: BSD 3-Clause License
@@ -25,6 +25,6 @@
25
25
  # You should have received a copy of the GNU General Public License
26
26
  # along with this program. If not, see <https://www.gnu.org/licenses/>.
27
27
 
28
- __all__ = ["clean", "reset", "status"]
28
+ __all__ = ["clean", "reset", "refresh", "status"]
29
29
 
30
- from .panda_auth_commands import clean, reset, status
30
+ from .panda_auth_commands import clean, reset, refresh, status
@@ -28,6 +28,7 @@
28
28
 
29
29
  __all__ = [
30
30
  "clean",
31
+ "refresh",
31
32
  "reset",
32
33
  "status",
33
34
  ]
@@ -37,7 +38,12 @@ import click
37
38
 
38
39
  from lsst.daf.butler.cli.utils import MWCommand
39
40
 
40
- from ...panda_auth_drivers import panda_auth_clean_driver, panda_auth_reset_driver, panda_auth_status_driver
41
+ from ...panda_auth_drivers import (
42
+ panda_auth_clean_driver,
43
+ panda_auth_refresh_driver,
44
+ panda_auth_reset_driver,
45
+ panda_auth_status_driver,
46
+ )
41
47
 
42
48
 
43
49
  class PandaAuthCommand(MWCommand):
@@ -62,3 +68,13 @@ def reset(*args, **kwargs):
62
68
  def clean(*args, **kwargs):
63
69
  """Clean up token and token cache files."""
64
70
  panda_auth_clean_driver(*args, **kwargs)
71
+
72
+
73
+ @click.command(cls=PandaAuthCommand)
74
+ @click.option("--days", default=4, help="The earlist remaining days to refresh the token.")
75
+ @click.option("--verbose", is_flag=True, help="Enable verbose output")
76
+ def refresh(*args, **kwargs):
77
+ """Refresh auth tocken."""
78
+ days = kwargs.get("days", 4)
79
+ verbose = kwargs.get("verbose", False)
80
+ panda_auth_refresh_driver(days, verbose)
@@ -33,6 +33,7 @@ the subcommand method.
33
33
 
34
34
  __all__ = [
35
35
  "panda_auth_clean_driver",
36
+ "panda_auth_refresh_driver",
36
37
  "panda_auth_reset_driver",
37
38
  "panda_auth_status_driver",
38
39
  ]
@@ -41,7 +42,19 @@ __all__ = [
41
42
  import logging
42
43
  from datetime import datetime
43
44
 
44
- from .panda_auth_utils import panda_auth_clean, panda_auth_status, panda_auth_update
45
+ from lsst.ctrl.bps.panda.panda_exceptions import (
46
+ PandaAuthError,
47
+ TokenExpiredError,
48
+ TokenNotFoundError,
49
+ TokenTooEarlyError,
50
+ )
51
+
52
+ from .panda_auth_utils import (
53
+ panda_auth_clean,
54
+ panda_auth_refresh,
55
+ panda_auth_status,
56
+ panda_auth_update,
57
+ )
45
58
 
46
59
  _LOG = logging.getLogger(__name__)
47
60
 
@@ -56,6 +69,20 @@ def panda_auth_reset_driver():
56
69
  panda_auth_update(None, True)
57
70
 
58
71
 
72
+ def panda_auth_refresh_driver(days, verbose):
73
+ """Refresh auth token."""
74
+ try:
75
+ panda_auth_refresh(days, verbose)
76
+ except TokenNotFoundError as e:
77
+ print(f"[ERROR] {e}")
78
+ except TokenExpiredError as e:
79
+ print(f"[ERROR] {e}")
80
+ except TokenTooEarlyError as e:
81
+ print(f"[INFO] {e}")
82
+ except PandaAuthError as e:
83
+ print(f"[FAIL] {e}")
84
+
85
+
59
86
  def panda_auth_status_driver():
60
87
  """Gather information about a token if it exists."""
61
88
  status = panda_auth_status()
@@ -30,19 +30,32 @@
30
30
  __all__ = [
31
31
  "panda_auth_clean",
32
32
  "panda_auth_expiration",
33
+ "panda_auth_refresh",
33
34
  "panda_auth_setup",
34
35
  "panda_auth_status",
35
36
  "panda_auth_update",
36
37
  ]
37
38
 
38
39
 
40
+ import base64
41
+ import json
39
42
  import logging
40
43
  import os
44
+ from datetime import UTC, datetime, timedelta
41
45
 
42
46
  import idds.common.utils as idds_utils
43
47
  import pandaclient.idds_api
44
48
  from pandaclient.openidc_utils import OpenIdConnect_Utils
45
49
 
50
+ from lsst.ctrl.bps.panda.panda_exceptions import (
51
+ AuthConfigError,
52
+ PandaAuthError,
53
+ TokenExpiredError,
54
+ TokenNotFoundError,
55
+ TokenRefreshError,
56
+ TokenTooEarlyError,
57
+ )
58
+
46
59
  _LOG = logging.getLogger(__name__)
47
60
 
48
61
 
@@ -151,3 +164,87 @@ def panda_auth_update(idds_server=None, reset=False):
151
164
  # idds server given. So for now, check result string for keywords.
152
165
  if "request_id" not in ret[1][-1] or "status" not in ret[1][-1]:
153
166
  raise RuntimeError(f"Error contacting PanDA service: {ret}")
167
+
168
+
169
+ def panda_auth_refresh(days=4, verbose=False):
170
+ """
171
+ Refresh the current valid IAM OpenID authentication token.
172
+
173
+ This function checks the expiration time of the existing token stored
174
+ in the local token file and attempts to refresh it if it is close to
175
+ expiring (within a specified number of days).
176
+
177
+ Parameters
178
+ ----------
179
+ days : `int`, optional
180
+ The minimum number of days before token expiration to trigger a
181
+ refresh. If the token expires in more than this number of days,
182
+ the refresh is skipped. Default is 4.
183
+ verbose : `bool`, optional
184
+ If True, enables verbose output for debugging or logging.
185
+ Default is False.
186
+
187
+ Returns
188
+ -------
189
+ status: `dict`
190
+ A dictionary containing the refreshed token status
191
+ """
192
+ panda_url = os.environ.get("PANDA_URL")
193
+ panda_auth_vo = os.environ.get("PANDA_AUTH_VO")
194
+
195
+ if not panda_url or not panda_auth_vo:
196
+ raise PandaAuthError("Missing required environment variables: PANDA_URL or PANDA_AUTH_VO")
197
+
198
+ url_prefix = panda_url.split("/server", 1)[0]
199
+ auth_url = f"{url_prefix}/auth/{panda_auth_vo}_auth_config.json"
200
+ open_id = OpenIdConnect_Utils(auth_url, log_stream=_LOG, verbose=verbose)
201
+
202
+ token_file = open_id.get_token_path()
203
+ if not os.path.exists(token_file):
204
+ raise TokenNotFoundError("Cannot find token file. Use 'panda_auth reset' to obtain a new token.")
205
+
206
+ with open(token_file) as f:
207
+ data = json.load(f)
208
+ enc = data["id_token"].split(".")[1]
209
+ enc += "=" * (-len(enc) % 4)
210
+ dec = json.loads(base64.urlsafe_b64decode(enc.encode()))
211
+ exp_time = datetime.fromtimestamp(dec["exp"], tz=UTC)
212
+ delta = exp_time - datetime.now(UTC)
213
+ minutes = delta.total_seconds() / 60
214
+ print(f"Token will expire in {minutes} minutes.")
215
+ print(f"Token expiration time : {exp_time.strftime('%Y-%m-%d %H:%M:%S')} UTC")
216
+ if delta < timedelta(minutes=0):
217
+ raise TokenExpiredError("Token already expired. Cannot refresh.")
218
+ elif delta > timedelta(days=days):
219
+ raise TokenTooEarlyError(
220
+ f"Too early to refresh. More than {days} day(s) until expiration.\n"
221
+ f"Use '--days' option to adjust threshold, e.g.:\n"
222
+ f" panda_auth refresh --days 10"
223
+ )
224
+
225
+ refresh_token_string = data["refresh_token"]
226
+
227
+ s, auth_config = open_id.fetch_page(open_id.auth_config_url)
228
+ if not s:
229
+ raise AuthConfigError("Failed to get Auth configuration.")
230
+
231
+ s, endpoint_config = open_id.fetch_page(auth_config["oidc_config_url"])
232
+ if not s:
233
+ raise AuthConfigError("Failed to get endpoint configuration.")
234
+
235
+ s, o = open_id.refresh_token(
236
+ endpoint_config["token_endpoint"],
237
+ auth_config["client_id"],
238
+ auth_config["client_secret"],
239
+ refresh_token_string,
240
+ )
241
+
242
+ if not s:
243
+ raise TokenRefreshError("Failed to refresh token.")
244
+
245
+ status = panda_auth_status()
246
+ if status:
247
+ exp_time = datetime.fromtimestamp(status["exp"], tz=UTC)
248
+ print(f"{'New expiration time:':23} {exp_time.strftime('%Y-%m-%d %H:%M:%S')} UTC")
249
+ print("Success to refresh token")
250
+ return status
@@ -0,0 +1,34 @@
1
+ class PandaAuthError(Exception):
2
+ """Base class for authentication errors."""
3
+
4
+ pass
5
+
6
+
7
+ class TokenNotFoundError(PandaAuthError):
8
+ """Raised when the token file is missing."""
9
+
10
+ pass
11
+
12
+
13
+ class TokenExpiredError(PandaAuthError):
14
+ """Raised when the token has already expired."""
15
+
16
+ pass
17
+
18
+
19
+ class TokenTooEarlyError(PandaAuthError):
20
+ """Raised when attempting to refresh too early."""
21
+
22
+ pass
23
+
24
+
25
+ class AuthConfigError(PandaAuthError):
26
+ """Raised when fetching the auth or endpoint configuration fails."""
27
+
28
+ pass
29
+
30
+
31
+ class TokenRefreshError(PandaAuthError):
32
+ """Raised when token refresh fails."""
33
+
34
+ pass
@@ -0,0 +1,2 @@
1
+ __all__ = ["__version__"]
2
+ __version__ = "29.2025.4200"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lsst-ctrl-bps-panda
3
- Version: 29.2025.4100
3
+ Version: 29.2025.4200
4
4
  Summary: PanDA plugin for lsst-ctrl-bps.
5
5
  Author-email: Rubin Observatory Data Management <dm-admin@lists.lsst.org>
6
6
  License: BSD 3-Clause License
@@ -10,6 +10,7 @@ python/lsst/ctrl/bps/panda/cmd_line_embedder.py
10
10
  python/lsst/ctrl/bps/panda/constants.py
11
11
  python/lsst/ctrl/bps/panda/panda_auth_drivers.py
12
12
  python/lsst/ctrl/bps/panda/panda_auth_utils.py
13
+ python/lsst/ctrl/bps/panda/panda_exceptions.py
13
14
  python/lsst/ctrl/bps/panda/panda_service.py
14
15
  python/lsst/ctrl/bps/panda/utils.py
15
16
  python/lsst/ctrl/bps/panda/version.py
@@ -0,0 +1,151 @@
1
+ # This file is part of ctrl_bps_panda.
2
+ #
3
+ # Developed for the LSST Data Management System.
4
+ # This product includes software developed by the LSST Project
5
+ # (https://www.lsst.org).
6
+ # See the COPYRIGHT file at the top-level directory of this distribution
7
+ # for details of code ownership.
8
+ #
9
+ # This software is dual licensed under the GNU General Public License and also
10
+ # under a 3-clause BSD license. Recipients may choose which of these licenses
11
+ # to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12
+ # respectively. If you choose the GPL option then the following text applies
13
+ # (but note that there is still no warranty even if you opt for BSD instead):
14
+ #
15
+ # This program is free software: you can redistribute it and/or modify
16
+ # it under the terms of the GNU General Public License as published by
17
+ # the Free Software Foundation, either version 3 of the License, or
18
+ # (at your option) any later version.
19
+ #
20
+ # This program is distributed in the hope that it will be useful,
21
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ # GNU General Public License for more details.
24
+ #
25
+ # You should have received a copy of the GNU General Public License
26
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
27
+
28
+ """Unit tests for PanDA authentication utilities."""
29
+
30
+ import base64
31
+ import json
32
+ import os
33
+ import unittest
34
+ from datetime import UTC, datetime, timedelta
35
+ from unittest import mock
36
+
37
+ from lsst.ctrl.bps.panda import __version__ as version
38
+ from lsst.ctrl.bps.panda.panda_auth_utils import (
39
+ TokenExpiredError,
40
+ panda_auth_refresh,
41
+ panda_auth_status,
42
+ )
43
+
44
+
45
+ def make_fake_jwt(exp_offset_days):
46
+ """Return a fake id_token that expires in N days."""
47
+ payload = {"exp": int((datetime.now(UTC) + timedelta(days=exp_offset_days)).timestamp())}
48
+ b64_payload = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
49
+ return f"header.{b64_payload}.sig"
50
+
51
+
52
+ def fake_token_file(exp_days=3, refresh_token="fake_refresh"):
53
+ """Generate fake token file data"""
54
+ token = make_fake_jwt(exp_days)
55
+ return json.dumps({"id_token": token, "refresh_token": refresh_token})
56
+
57
+
58
+ def fetch_page_side_effect(url):
59
+ """Simulate OpenIdConnect_Utils.fetch_page behavior in tests."""
60
+ if url.endswith("auth_config.json"):
61
+ return True, {
62
+ "client_secret": "secret",
63
+ "audience": "https://iam.example.com",
64
+ "client_id": "cid",
65
+ "oidc_config_url": "https://oidc.example.org/.well-known/openid-configuration",
66
+ "vo": "fake_vo",
67
+ "no_verify": "True",
68
+ "robot_ids": "NONE",
69
+ }
70
+ elif url.endswith("openid-configuration"):
71
+ return True, {"token_endpoint": "https://oidc.example.org/token"}
72
+ return False, {}
73
+
74
+
75
+ class VersionTestCase(unittest.TestCase):
76
+ """Test versioning."""
77
+
78
+ def test_version(self):
79
+ # Check that version is defined.
80
+ self.assertIsNotNone(version)
81
+
82
+
83
+ class TestPandaAuthUtils(unittest.TestCase):
84
+ """Simple test of auth utilities."""
85
+
86
+ def setUp(self):
87
+ self.test_env = {
88
+ "PANDA_CONFIG_ROOT": "/fake/token",
89
+ "PANDA_URL_SSL": "https://fake.server.com:8443/server/panda",
90
+ "PANDA_URL": "https://fake.server.com:8443/server/panda",
91
+ "PANDACACHE_URL": "https://fake.server.com:8443/server/panda",
92
+ "PANDAMON_URL": "https://fake.monitor.com:8443/",
93
+ "PANDA_AUTH": "oidc",
94
+ "PANDA_VERIFY_HOST": "off",
95
+ "PANDA_AUTH_VO": "fake_vo",
96
+ "PANDA_BEHIND_REAL_LB": "true",
97
+ "PANDA_SYS": "/fake/pandasys",
98
+ "IDDS_CONFIG": "/fake/pandasys/etc/idds/idds.cfg.client.template",
99
+ }
100
+
101
+ def testPandaAuthStatusWrongEnviron(self):
102
+ unwanted = {
103
+ "PANDA_AUTH",
104
+ "PANDA_VERIFY_HOST",
105
+ "PANDA_AUTH_VO",
106
+ "PANDA_URL_SSL",
107
+ "PANDA_URL",
108
+ }
109
+ test_environ = {key: val for key, val in os.environ.items() if key not in unwanted}
110
+ with mock.patch.dict(os.environ, test_environ, clear=True):
111
+ with self.assertRaises(OSError):
112
+ panda_auth_status()
113
+
114
+ @mock.patch("builtins.print")
115
+ @mock.patch("os.path.exists", return_value=True)
116
+ @mock.patch("pandaclient.openidc_utils.OpenIdConnect_Utils")
117
+ def test_expired_token(self, mock_oidc, mock_exists, mock_print):
118
+ mock_oidc.return_value.get_token_path.return_value = "/fake/token.json"
119
+
120
+ with mock.patch.dict("os.environ", self.test_env):
121
+ with mock.patch("builtins.open", mock.mock_open(read_data=fake_token_file(exp_days=-1))):
122
+ with self.assertRaises(TokenExpiredError):
123
+ panda_auth_refresh(days=4)
124
+
125
+ @mock.patch("builtins.print")
126
+ @mock.patch("lsst.ctrl.bps.panda.panda_auth_utils.panda_auth_status")
127
+ @mock.patch("os.path.exists", return_value=True)
128
+ @mock.patch("lsst.ctrl.bps.panda.panda_auth_utils.OpenIdConnect_Utils")
129
+ def test_successful_refresh(self, mock_oidc, mock_exists, mock_status, mock_print):
130
+ fake_openid = mock_oidc.return_value
131
+ fake_openid.get_token_path.return_value = "/fake/token.json"
132
+ fake_openid.auth_config_url = "https://fake.server/auth_config.json"
133
+
134
+ fake_openid.fetch_page.side_effect = fetch_page_side_effect
135
+
136
+ fake_openid.refresh_token.return_value = (True, {"access_token": "new_token"})
137
+
138
+ mock_status.return_value = {"exp": int((datetime.now(UTC) + timedelta(seconds=3600)).timestamp())}
139
+
140
+ with mock.patch.dict("os.environ", self.test_env):
141
+ token_json = fake_token_file(exp_days=2)
142
+ with mock.patch("builtins.open", mock.mock_open(read_data=token_json)):
143
+ panda_auth_refresh(days=4)
144
+
145
+ fake_openid.refresh_token.assert_called_once()
146
+ found = any("Success to refresh token" in str(c[0][0]) for c in mock_print.call_args_list)
147
+ assert found
148
+
149
+
150
+ if __name__ == "__main__":
151
+ unittest.main()
@@ -1,2 +0,0 @@
1
- __all__ = ["__version__"]
2
- __version__ = "29.2025.4100"
@@ -1,64 +0,0 @@
1
- # This file is part of ctrl_bps_panda.
2
- #
3
- # Developed for the LSST Data Management System.
4
- # This product includes software developed by the LSST Project
5
- # (https://www.lsst.org).
6
- # See the COPYRIGHT file at the top-level directory of this distribution
7
- # for details of code ownership.
8
- #
9
- # This software is dual licensed under the GNU General Public License and also
10
- # under a 3-clause BSD license. Recipients may choose which of these licenses
11
- # to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12
- # respectively. If you choose the GPL option then the following text applies
13
- # (but note that there is still no warranty even if you opt for BSD instead):
14
- #
15
- # This program is free software: you can redistribute it and/or modify
16
- # it under the terms of the GNU General Public License as published by
17
- # the Free Software Foundation, either version 3 of the License, or
18
- # (at your option) any later version.
19
- #
20
- # This program is distributed in the hope that it will be useful,
21
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- # GNU General Public License for more details.
24
- #
25
- # You should have received a copy of the GNU General Public License
26
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
27
-
28
- """Unit tests for PanDA authentication utilities."""
29
-
30
- import os
31
- import unittest
32
- from unittest import mock
33
-
34
- from lsst.ctrl.bps.panda import __version__ as version
35
- from lsst.ctrl.bps.panda.panda_auth_utils import panda_auth_status
36
-
37
-
38
- class VersionTestCase(unittest.TestCase):
39
- """Test versioning."""
40
-
41
- def test_version(self):
42
- # Check that version is defined.
43
- self.assertIsNotNone(version)
44
-
45
-
46
- class TestPandaAuthUtils(unittest.TestCase):
47
- """Simple test of auth utilities."""
48
-
49
- def testPandaAuthStatusWrongEnviron(self):
50
- unwanted = {
51
- "PANDA_AUTH",
52
- "PANDA_VERIFY_HOST",
53
- "PANDA_AUTH_VO",
54
- "PANDA_URL_SSL",
55
- "PANDA_URL",
56
- }
57
- test_environ = {key: val for key, val in os.environ.items() if key not in unwanted}
58
- with mock.patch.dict(os.environ, test_environ, clear=True):
59
- with self.assertRaises(OSError):
60
- panda_auth_status()
61
-
62
-
63
- if __name__ == "__main__":
64
- unittest.main()