New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(secure_storage): handle package uninstall/re-install on Linux and Windows #2044
feat(secure_storage): handle package uninstall/re-install on Linux and Windows #2044
Conversation
packages/secure_storage/amplify_secure_storage_dart/lib/src/ffi/utils/linux_utils.dart
Outdated
Show resolved
Hide resolved
packages/secure_storage/amplify_secure_storage_dart/lib/src/utils/file_key_value_store.dart
Outdated
Show resolved
Hide resolved
packages/secure_storage/amplify_secure_storage_dart/lib/src/utils/file_key_value_store.dart
Outdated
Show resolved
Hide resolved
packages/secure_storage/amplify_secure_storage_dart/lib/src/utils/file_key_value_store.dart
Outdated
Show resolved
Hide resolved
directory: appDirectory, | ||
fileName: 'amplify_secure_storage_scopes.json', | ||
); | ||
fileStore.writeAll({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use the in-mem fs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be updated to use in-mem. AmplifySecureStorageDart
would also have to be updated to use in-mem for these tests in that case.
This is more of an integration tests since it isn't mocking libsecret / secret service, so I think it is fine as is.
packages/secure_storage/amplify_secure_storage_dart/lib/src/utils/file_key_value_store.dart
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## next #2044 +/- ##
=======================================
Coverage 42.86% 42.86%
=======================================
Files 114 114
Lines 7502 7502
=======================================
Hits 3216 3216
Misses 4286 4286
Flags with carried forward coverage won't be shown. Click here to find out more. |
…at/package-uninstall
d256334
to
857eae4
Compare
@@ -5,6 +5,8 @@ | |||
import FlutterMacOS | |||
import Foundation | |||
|
|||
import path_provider_macos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need path_provider_macos, but it is brought in as part of path_provider. We could bring in path_provider_linux and path_provider_windows. They are unlisted packages though. Not sure if we want to bring in unlisted packages or not.
// Android is already run on a background thread via pigeon | ||
skip: !zIsWeb && Platform.isAndroid, | ||
); | ||
group('Secure Storage', () => runTests(storageFactory)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is just clean up. It isn't related to this PR. AmplifySecureStorage
uses AmplifySecureStorageWorker
by default, so these tests were redundant.
@@ -148,31 +155,26 @@ void runStandardTests( | |||
}); | |||
}); | |||
|
|||
group('write', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: These tests were duplicates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments. Looks good, though. Thanks!
if (directory != null) { | ||
return FileKeyValueStore(fileName: _fileName, path: directory); | ||
} | ||
return FileKeyValueStore( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the use case for this? Just testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, tests/examples. Could also be a reasonable fallback if/when we support non-flutter use cases for amplify.
/// | ||
/// Used to store encrypted data on Windows. If no value | ||
/// is provided, data will be stored in memory on Windows. | ||
final String? applicationDirectory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be part of the config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. This was unnecessary. I had added storagePath
to WindowsSecureStorageOptions
already. I was passing both to the _dart package, with storagePath
taking priority over applicationDirectory
. This made sense when I was using applicationDirectory
in the _dart package on linux as well to read/write scope names, but with that happening on the flutter side, passing two values for the same thing didn't make sense.
Updated 👍
Future<void> _initializeScope(String? accessGroup) async { | ||
// if accessGroup is set, do not clear data on initialization | ||
// since the data can be shared across applications. | ||
if (accessGroup != null) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reformat this to not call _initalizeScope
if accessGroup is set since the only reason this method has a parameter is to check if it's not null which is kind of confusing.
} | ||
final Uint8List encrypted; | ||
try { | ||
encrypted = Uint8List.fromList(List<int>.from(rawData as List)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes two copies of the list (List.from, then Uint8List.fromList). I would do Uint8List.fromList((rawData as List).cast());
to avoid that. Is the only failure because of the cast? It's probably more reasonable to do an is
check if that's the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use .cast() over List.from.
I kept the try/catch block. rawData
could not be a list, or it could be a List that contains data other than integers. Either of those would be problematic. I could do an is
check to confirm it is a list, but I would still need to cast to get it to List rather than List.
expect(value2, 'test_update'); | ||
}); | ||
group('read/write/delete can handle key value pairs of varying length', () { | ||
for (var entry in keyValuePairs.entries) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (var entry in keyValuePairs.entries) { | |
for (final entry in keyValuePairs.entries) { |
Don't necessarily need to change since I don't care as much about the style of test code but I thought this was a lint
Issue #, if available:
Changes:
General / Utils
FileKeyValueStore
for file simple key/value storage in the file systempath_provider
in as dependency inamplify_secure_storage
to get the application support directoryLinux
gio
bindings to get app ID on linuxaccessGroup
to linux config as an optional override to App ID to allow for sharing of data across appsFileKeyValueStore
Windows
FileKeyValueStore
to store the dataMotivation:
If a user uninstalls and re-installs an app installed via snap or the Windows app store, the expectation would be that data from their previous install would not persist.
Implementation:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.