AnalogIO / coffeecard_app

Cross-platform coffee card app for Cafe Analog
https://www.cafeanalog.dk/app
MIT License
6 stars 1 forks source link

fix(utils): Fix reactivation authenticator not evicting; refactor & test #429

Closed marfavi closed 1 year ago

marfavi commented 1 year ago

Summary

This pull request introduces changes to the reactivation_authenticator.dart file, including a bug fix. The utility class mutex.dart is also rewritten (but unused), and a new utility class throttler.dart is added. All these files have corresponding tests.

Closes #416 Closes #492

Bug fixes

Fixed a bug where the user was not evicted if the token was expired. The method ReactivationAuthenticator.authenticate() now checks the request body type against the LoginDto type to check if a failed request was an attempt to refresh the token; if it was, we stop execution to avoid infinite recursion. This change fixes #492.

Utility classes

ReactivationAuthenticator

The ReactivationAuthenticator class has been rewritten to use the new Throttler class instead of the Mutex class. The ReactivationAuthenticator class has also been simplified and cleaned up.

For example, we no longer needs to maintain internal state about whether we should throttle a token refresh attempt, and we don't need to check whether a Mutex is locked, since the Throttler class handles both cases for us.

The class is also tested with full coverage. This change closes #416.

Service locator

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

ghost commented 1 year ago
👇 Click on the image for a new way to code review #### [![Review these changes using an interactive CodeSee Map](https://s3.us-east-2.amazonaws.com/maps.codesee.io/images/github/AnalogIO/coffeecard_app/429/ae554d37/dfd6165fba14a29a7cc0e51915ebebcb1f8d728e.svg)](https://app.codesee.io/r/reviews?pr=429&src=https%3A%2F%2Fgithub.com%2FAnalogIO%2Fcoffeecard_app) #### Legend CodeSee Map legend
codecov[bot] commented 1 year ago

Codecov Report

Merging #429 (dfd6165) into develop (2bb7da1) will increase coverage by 4.74%. The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop     #429      +/-   ##
===========================================
+ Coverage    71.44%   76.19%   +4.74%     
===========================================
  Files          114      115       +1     
  Lines         1194     1218      +24     
===========================================
+ Hits           853      928      +75     
+ Misses         341      290      -51     
Flag Coverage Δ
unittests 76.19% <100.00%> (+4.74%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/utils/mutex.dart 100.00% <100.00%> (+100.00%) :arrow_up:
lib/utils/reactivation_authenticator.dart 100.00% <100.00%> (+100.00%) :arrow_up:
lib/utils/throttler.dart 100.00% <100.00%> (ø)