You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Display "N/A" for tokens without expiration metadata (#539)
This release improves how token expiration information is handled and
displayed in the GitHub context. The changes ensure more accurate and
user-friendly reporting of token expiration properties, enhance
formatting in table views, and add comprehensive tests to validate these
behaviors.
**Token Expiration Calculation & Representation:**
* Updated the `TokenExpiresIn` and `RefreshTokenExpiresIn` script
properties in `GitHubContext.Types.ps1xml` to only return a value when
`TokenExpiresAt` or `RefreshTokenExpiresAt` is present, otherwise return
nothing. This avoids returning a zero timespan when the expiration is
not set.
**Table Formatting & Display:**
* Improved the table formatting in `GitHubContext.Format.ps1xml` to:
- Display `TokenExpiresAt` as 'N/A' (in gray if supported) when not
present, instead of omitting the column.
- Show `TokenExpiresIn` as 'N/A' (with similar formatting) when not
available, and color the value based on time remaining when present.
**Testing Enhancements:**
* Added and updated tests in `GitHub.Tests.ps1` and `Apps.Tests.ps1` to:
- Validate both `TokenExpiresAt` and `TokenExpiresIn` properties for
correctness, type, and logical values across different authentication
types.
- Check that installation tokens have the correct `AuthType` and that
expiration properties behave as expected for both App and non-App
contexts.
These changes make token expiration handling more robust, user-friendly,
and well-tested throughout the module.
### Test Coverage Summary:
| Token Type | AuthType | Has Expiration? | Test Coverage |
|------------|----------|-----------------|---------------|
| Classic PAT (`ghp`) | PAT | No | ✓ |
| Fine-grained PAT (`github_pat`) | PAT | No | ✓ |
| GITHUB_TOKEN (in GitHub Actions) | IAT | No | ✓ |
| GitHub App JWT | APP | Yes | ✓ |
| GitHub App Installation | IAT | Yes | ✓ |
#### Token Expiration Behavior:
- **PAT tokens** (both classic `ghp` and fine-grained `github_pat`): No
expiration metadata → displays "Unknown"
- **GITHUB_TOKEN** (IAT in GitHub Actions): No expiration metadata →
displays "Unknown"
- **GitHub App Installation tokens** (IAT from Connect-GitHubApp): Has
expiration metadata → displays time remaining or "Expired"
- **UAT tokens** (device flow): Has expiration metadata → displays time
remaining or "Expired"
- **APP tokens** (JWT): Has expiration metadata → displays time
remaining or "Expired"
#### Example Output:
**Before:**
```
* Name AuthType TokenType TokenExpiresAt TokenExpiresIn
- ---- -------- --------- -------------- --------------
> github.com/psmodule-user PAT ghp Expired
```
**After:**
```
* Name AuthType TokenType TokenExpiresAt TokenExpiresIn
- ---- -------- --------- -------------- --------------
> github.com/psmodule-user PAT ghp N/A N/A
```
- Fixes#538
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: Marius Storhaug <marstor@hotmail.com>
0 commit comments