Skip to content

fix(token): honor expires_type 'never' in user token validation & fix test module collision - #3266

Merged
lbjlaq merged 2 commits into
lbjlaq:mainfrom
CarlitoDon:fix/never-expire-user-token-validation
Jul 27, 2026
Merged

fix(token): honor expires_type 'never' in user token validation & fix test module collision#3266
lbjlaq merged 2 commits into
lbjlaq:mainfrom
CarlitoDon:fix/never-expire-user-token-validation

Conversation

@CarlitoDon

Copy link
Copy Markdown
Contributor

Description

1. Fix User Token Expiration Validation

When a user token was created or updated with expires_type: "never", its expires_at column in SQLite could be 0 or NULL. Previously, validate_token() in src-tauri/src/modules/user_token_db.rs checked if expires_at < Utc::now().timestamp(). Because 0 < now evaluated to true, non-expiring tokens were incorrectly flagged as expired (403 Forbidden).

This PR updates validate_token() to check if token.expires_type != "never" and expires_at > 0 before evaluating timestamp expiration, ensuring tokens set to never remain valid indefinitely. Unit tests for this behavior have also been added.

2. Fix Duplicate Test Module Collision

Renamed duplicate mod variant_tests in src-tauri/src/proxy/handlers/claude.rs to mod opus_variant_tests to resolve compiler error E0428 during test execution.

Testing

  • Ran cargo test for test_never_expire_token_validation and opus_variant_tests. All passed cleanly.
  • Verified live proxy requests against /v1/chat/completions with model claude-opus-4-6-thinking returning 200 OK using a non-expiring token.

Copilot AI review requested due to automatic review settings July 24, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes token validation so non-expiring user tokens (expires_type: "never") are not incorrectly rejected as expired, and resolves a Rust test module name collision that prevented tests from compiling.

Changes:

  • Update validate_token() to skip expiration timestamp checks when expires_type == "never".
  • Add a unit test ensuring "never" tokens validate successfully.
  • Rename a duplicate test module in the Claude proxy handler to avoid E0428 duplicate-definition errors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src-tauri/src/modules/user_token_db.rs Adjusts token expiration validation logic and adds a unit test for "never" tokens.
src-tauri/src/proxy/handlers/claude.rs Renames a test module to eliminate a duplicate module name collision during compilation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src-tauri/src/modules/user_token_db.rs Outdated
));
if token.expires_type != "never" {
if let Some(expires_at) = token.expires_at {
if expires_at > 0 && expires_at < Utc::now().timestamp() {
@lbjlaq
lbjlaq merged commit 634ef16 into lbjlaq:main Jul 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants