[PM-31159] Full state service re-write - #1029
Conversation
|
New Issues (34)Checkmarx found the following issues in this Pull Request
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1029 +/- ##
==========================================
+ Coverage 6.79% 25.68% +18.89%
==========================================
Files 67 73 +6
Lines 2798 2955 +157
Branches 483 539 +56
==========================================
+ Hits 190 759 +569
+ Misses 2576 2072 -504
- Partials 32 124 +92 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
eliykat
left a comment
There was a problem hiding this comment.
Thank you for tackling this! I think spending some time getting proper tests on stateService and stateMigrationService will give us some peace of mind that we won't get an influx of tickets on release.
|
@eliykat this is ready for another look when you have a moment, thanks. |
- State v4 was never properly migrated, handle migration directly from v3 - fix access token not properly migrated - fix environment urls not properly migrated - update tests - fix fresh install (missing state version) being set to v1 -> v5 (current)
eliykat
left a comment
There was a problem hiding this comment.
Great job improving the tests for StateService and StateMigrationService in particular.
| const ldapConfig = { ...account.directoryConfigurations.ldap }; | ||
| if ( | ||
| useSecureStorageForSecrets && | ||
| ldapConfig.password && | ||
| ldapConfig.password !== StoredSecurely | ||
| ) { | ||
| await this.secureStorageService.save(SecureStorageKeys.ldap, ldapConfig.password); | ||
| ldapConfig.password = StoredSecurely; | ||
| } |
There was a problem hiding this comment.
Is this necessary? As long as we're migrating from plain storage to plain storage, and from secure storage to secure storage, I don't think we need to read the useSecureStorageForSecrets value. It'll just maintain wherever they have secrets stored at the moment.
|
I can't see that this comment has been addressed. Is it that the current secure storage prepends the orgId, and we're now dropping that? |
Yes, sorry I forgot the address this in a comment. That is correct, they were prepended with the org id and this moved them off of that. |
- Rename state.service.ts to default-state.service.ts - Rename state.service.spec.ts to default-state.service.spec.ts - Clean up state service interface to remove unused StorageOptions - More type saftey for storage keys - Clean up migration logic
eliykat
left a comment
There was a problem hiding this comment.
Only 1 actual change below, then feel free to pass to QA. I can approve when I'm back from OOO next week but that doesn't need to hold up QA.
| get: <T>(key: StorageKey | SecureStorageKey, options?: StorageOptions) => Promise<T>; | ||
| has: (key: StorageKey | SecureStorageKey, options?: StorageOptions) => Promise<boolean>; | ||
| save: (key: StorageKey | SecureStorageKey, obj: any, options?: StorageOptions) => Promise<any>; | ||
| remove: (key: StorageKey | SecureStorageKey, options?: StorageOptions) => Promise<any>; |
There was a problem hiding this comment.
d'oh. Didn't realise both Storage and SecureStorage implemented the same interface, so this doesn't prevent keys from being mixed up between them. oh well :)
| await this.secureStorageService.save(SecureStorageKeys.ldap, ldapConfig.password); | ||
| ldapConfig.password = StoredSecurely; |
There was a problem hiding this comment.
Secure storage keys are migrated below, so I meant we don't have to deal with them at all here.
This section: migrate old plaintext keys -> new plaintext keys
Below: migrate secure storage keys -> secure storage keys
So here I would just do:
const ldapConfig = { ...account.directoryConfigurations.ldap };
await this.set(StorageKeys.directoryLdap, ldapConfig);... and so on.
Let me know if this doesn't work for whatever reason.
… directory config
|








🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-31159
📔 Objective
This PR encompasses the totality of the state service re-write. This includes:
state.service.tsjslibjslibservices into the main directory structurejslibservice dependencies (e.g.crypto-service)jslibstate into DC app state (mostly electron related state).jslibcompatibility (stub files)jslibstate migration logic into DC's state migration servicejslibmodels📸 Screenshots