scottlamb / moonfire-nvr

Moonfire NVR, a security camera network video recorder
Other
1.18k stars 138 forks source link

Incorrect revocation reason stored on the DB on logout #288

Closed ldfsilva closed 8 months ago

ldfsilva commented 12 months ago

Describe the bug

The revocation_reason stored on the DB on a logout action differs from the one specified on the DB schema; 1 is stored instead of 0.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Moonfire UI'
  2. Click on 'Login'
  3. Authenticate with user/password
  4. Click on 'User icon' on top right corner
  5. Click on 'Logout'
  6. Check user_session DB table data

Note all revocation_reason are set to 1 where the sessions were ended through Logout:

$ sqlite3 db/db "select use_count, last_use_time_sec, revocation_reason, revocation_time_sec, revocation_reason_detail from user_session order by creation_time_sec;"
3|1688842276|1|1688842276|
5|1688843878|1|1688843878|
15|1688843589|1|1688843589|
7|1688843823|1|1688843823|
5|1688843840|1|1688843840|
12|1688844227|1|1688844227|
12|1688845438|1|1688845438|
10|1688845421|1|1688845421|
9|1688845473|1|1688845473|
7|1688845430|1|1688845430|
5|1688845411|1|1688845411|
11|1688846726|1|1688846726|
10|1688857966|1|1688857966|

Expected behavior The revocation_reason should match what we have in the specification, so far that value is 0. So we need to either correct the spec or the storage of that value for the correct representation and later categorization of sessions' ending reasons, this would also come handy during troubleshooting.

Screenshots N/A

Server (please complete the following information):

Desktop (please complete the following information): N/A

Additional context

Noticed while investigating https://github.com/scottlamb/moonfire-nvr/issues/277

scottlamb commented 12 months ago

Looks like the actual code and the comment are inconsistent; I think I'll just update the comment to match the code to fix this without requiring a migration.

https://github.com/scottlamb/moonfire-nvr/blob/4ad627b99767d8396397bcd0f7f0559021df3ca8/server/db/auth.rs#L246

https://github.com/scottlamb/moonfire-nvr/blob/4ad627b99767d8396397bcd0f7f0559021df3ca8/server/db/schema.sql#L364