aiondemand / aiondemand/aiondemand

Token.from_file loads access token with incorrect expiry when validity exceeds 24 hours

Open
#171 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
38
Forks
89
PR merge metrics
No merged PRs in 30d

Description

## Bug Description

`Token.from_file` in `src/aiod/authentication/authentication.py` incorrectly
calculates the remaining validity of a cached access token when the token
has more than 24 hours left.
As a result, the loaded token believes it has expired much sooner than it
actually has, causing unnecessary re-authentication on the next request.

## Affected Code

`src/aiod/authentication/authentication.py` — `Token.from_file` method,
specifically the block that reads `expiration_date` from the token file.

## To Reproduce

1. Obtain a token with `write_to_file=True`.
2. Wait, or manually set `expiration_date` in `~/.aiod/token.toml` to
a time more than 24 hours in the future.
3. Load the token with `Token.from_file()`.
4. Check the token's internal expiry, it will be wrong.

## Expected Behavior

The loaded token should correctly reflect the full remaining validity.

## Additional Notes
The bug involves a subtle Python `timedelta` property distinction.
A regression test `test_token_from_file_long_expiry` has been added to
`tests/test_authentication.py` which reproduces the bug by setting a 25-hour
expiry, loading the token from file, and asserting the remaining validity
is correctly ~90000 seconds and not ~3600.

No fix is proposed here intentionally as I will submit a Pull Request.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.