Skip to content

Fix 2FA completion, token refresh, inventory, and news handling - #8

Merged
Maho-Yoshino merged 2 commits into
cleanup-returnsfrom
alex_pr7_review_fixes
Nov 21, 2026
Merged

Maho-Yoshino merged 2 commits into
cleanup-returnsfrom
alex_pr7_review_fixes

Conversation

@MrMindBlow

Copy link
Copy Markdown
Member

This PR addresses the nine open findings in the review of #7. It targets cleanup-returns, so merging it first brings the fixes into #7 for its final review against main.

Changes

  • Keep an approved Gaijin Pass challenge available for one password-verified retry. Return terminal exchange errors to the waiting caller, renew disconnected or timed-out device polls within a bounded deadline, and validate server-account 2FA results before accessing tokens.
  • Return integer user IDs from both login routes. Preserve leading zeroes in submitted email codes. The existing Gaijin Pass success check now collects the result through the login entry point.
  • Return HTTP 429 when an explicit token refresh is rate-limited. During startup and scheduled refreshes, defer that account and continue refreshing the others.
  • Default a missing inventory commodity flag to false, select forum announcements in publication order, and parse adjacent bracketed news tags individually.

Verification

Manually exercised the FastAPI authentication routes with synthetic upstream responses and a temporary SQLite database. Approval before retry returned a token after a single upstream challenge. A disconnected poll renewed its request ID. A failed email exchange returned 502 immediately and allowed a fresh challenge. A rejected server-account code returned 403. The refresh route returned 429, and the background refresh preserved the throttled account and renewed another.

The inventory response model accepted an asset without commodity. A public forum request confirmed creation order, and a two-tag title produced two distinct tags. Ruff, Python 3.14 compilation, and git diff --check passed. Account-backed Gaijin endpoints were not exercised.

@MrMindBlow MrMindBlow self-assigned this Nov 21, 2026

@Maho-Yoshino Maho-Yoshino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the diff (alex_pr7_review_fixes -> cleanup-returns), syntax-checked the changed files, ran the test suite on the branch (3/3 pass), and verified the forum ordering change against the live Discourse page. The 2FA rewrite is a solid improvement over the previous Event-based state machine; nothing below blocks the merge, but a few items are worth addressing.

Verified correct:

  • [A-z] -> [A-Za-z] genuinely fixes adjacent-tag parsing (the old class included ]/[); dropping re.IGNORECASE is safe.
  • WeakValueDictionary + per-email asyncio.Lock works (confirmed asyncio.Lock is weak-referenceable and setdefault exists).
  • compare_digest on bytes is consistent with the sha256 digest.
  • _checked_login status handling and int() validation are sound.
  • The timeout/shield/wait_for(60) split correctly separates the 15-minute challenge lifetime from the caller's 60s wait.

Inline comments below map each finding to its line.

Comment thread src/utils/auth.py Resolved
Comment thread src/utils/news.py Resolved
Comment thread src/utils/auth.py Resolved
Comment thread src/utils/auth.py Resolved
Comment thread src/api/v1/marketplace/backend.py Resolved
Comment thread src/utils/auth.py Resolved
Comment thread src/utils/auth.py Resolved

@Maho-Yoshino Maho-Yoshino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Maho-Yoshino
Maho-Yoshino merged commit 4ff583b into cleanup-returns Nov 21, 2026
2 checks passed
@Maho-Yoshino
Maho-Yoshino deleted the alex_pr7_review_fixes branch November 21, 2026 18:13
Maho-Yoshino added a commit that referenced this pull request Nov 21, 2026
* Beginning

* Rename 'app' to 'src'

This better fits the whole project's scope, and it is a more standardized name

* Finish AGENTS.md migration to new structure

* Major dict helper rewrite

Now it is less monolithic in design, with separate classes for different actions

* more dict util improvements

* Hosting files improvements

* Endpoints return data cleanup work

* Major news utility rework

Removed the part, which stores the latest IDs in an external JSON file

This code used to be part of [PECK Bot](https://github.com/Order-Of-The-Birb/peck-bot), however the API doesn't require any persistent check for already-sent data

Added forum parsing
Implemented parralel fetching to speed it up
Restructured the code

* A lot of fixes + cache module

Got tired of writing caches manually

* Fix error between brackets on `/v1/clans/sqb/current`

* implement cache into news module

* Fixes

* Marketplace endpoints improvements

Also added new functionality while i was at it

* Fixes

* Fix Swagger UI modify js

Now websockets get hidden properly

* Implement basis for automated testing

* Create pyproject.toml

* Update pyproject.toml

* Add vehicleParser to ruff ignore

* Ruff suggested fixes

* Update const.py

* Fixing some pytest complaints

* Bugfix and raising supported FastAPI version

This bugfix allowed us to raise the FastAPI version from 0.136.1 to 0.162.0

* Add basic login tests

more to come in the future

* Fixing network return model

* Added github workflows

Automatic linting and pytest running should now work in theory

* Testing newly added workflows

* More testing

Ruff one didnt work because i was stupid

* style: apply ruff fixes

* Bugfixes

Websockets are back again

Network.request had return_type at the wrong place, so it raised an error

* Fixing routing issue

Previous method only did "/news_ws" instead of "/v1/news_ws"

* style: apply ruff fixes

* Remove redundant nonlocal declaration

* Fixing issues proposed by Deepseek

* Cleanup

* style: apply ruff fixes

* More fixes

Removed some redundant files
Detached the vehicle parser from the code (no longer blocks on startup)
Added some more edge case checks
Moved the terse key to a string, due to JSON's floating point errors with large numbers
added an event setter for providing 2FA codes, now login should work (in theory, cant be sure due to untested code)

* Remove unused AuthenticationError import

* style: apply ruff fixes

* A few more bugfixes

* Fix return name of clan search

Changes the return to IntString, and from "_id" to "id"

* style: apply ruff fixes

* Added returning the next bracket

* style: apply ruff fixes

* Improve localization + get endpoint

Improves the localization part of the vehicles processor
Adds an endpoint for requesting localization

* style: apply ruff fixes

* Restructure

Restructured routers for ease of finding related files

* Linter fixes

* Marketplace backend restructuring

* Code fixes

* Refactoring VehicleParser

* Update workflows to stop deprecation notices

* Attach HEAD to linting workflow

* Make linter only run in PRs

Non-PR pushes do not get automatically linted anymore

* Remove redundant list from linter

* Make tests run on pull requests

* Fixing issues

* Improving testing response provider structure

* Improve network manager

Now it doesn't have to generate a new session for each request

* Migrating replays logic to updated networkmanager

* style: apply ruff fixes

* Major whitespace cleanup

* error fixing

* Added more linting checks

* Fix test network manager reference

* Deepseek proposed fixes

* Implementing fixes

* style: apply ruff fixes

* Fixes

* Return type standardization

Now instead of a mix of `response_model` and return annotations, all methods use `response_model`

* style: apply ruff fixes

* Add return types to endpoints without one

+ fix some endpoints that don't return dicts

* style: apply ruff fixes

* Improve pytest harness

* Removed unused ServerBearer usage

Several endpoints were protected by `ServerBearer` for no reason, as these endpoints did not require any authentication in the backend for use

* Fixes

* Fixes pt.1

* style: apply ruff fixes

* Fixes pt.2

* style: apply ruff fixes

* Fixes pt. 3

* Make code required parameter again for 2FA

* Fixes pt.4

* style: apply ruff fixes

* Fixes pt.5

* Fixes pt.6

* Fix forwarded IPs config

* style: apply ruff fixes

* Improve contact info display

* style: apply ruff fixes

* Fix 2FA completion, token refresh, inventory, and news handling (#8)

* Fix two-factor login, token refresh, inventory, and news handling

* Fix token refresh, 2FA retries, and marketplace and forum responses

---------

Co-authored-by: MrMindBlow <49791075+MrMindBlow@users.noreply.github.com>
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.

2 participants