Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][locker] Preserve Secret password whitespace (#13584)

aman-pilotd0ec5d2492d4
diff --git a/mobile/apps/locker/changes/secret-password-whitespace.md b/mobile/apps/locker/changes/secret-password-whitespace.md
new file mode 100644
index 0000000000..2b270be890
--- /dev/null
+++ b/mobile/apps/locker/changes/secret-password-whitespace.md
@@ -0,0 +1,2 @@
+- Fixed Secret passwords losing leading or trailing whitespace when saving or editing.
+- Enabled copying whitespace-only values in displayed info fields.
diff --git a/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart b/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
index 09c744ea4e..76e3035fc9 100644
--- a/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/account_credentials_page.dart
@@ -92,7 +92,7 @@ class _AccountCredentialsPageState
bool get hasUnsavedChanges {
return _nameController.text.trim() != _initialName.trim() ||
_usernameController.text.trim() != _initialUsername.trim() ||
- _passwordController.text.trim() != _initialPassword.trim() ||
+ _passwordController.text != _initialPassword ||
_notesController.text.trim() != _initialNotes.trim();
}
@@ -101,7 +101,7 @@ class _AccountCredentialsPageState
return AccountCredentialData(
name: _nameController.text.trim(),
username: _usernameController.text.trim(),
- password: _passwordController.text.trim(),
+ password: _passwordController.text,
notes: _notesController.text.trim().isEmpty
? null
: _notesController.text.trim(),
@@ -166,7 +166,7 @@ class _AccountCredentialsPageState
);
}
- if (passwordText.trim().isNotEmpty) {
+ if (passwordText.isNotEmpty) {
if (fields.isNotEmpty) fields.add(const SizedBox(height: 24));
fields.add(
buildViewField(
diff --git a/mobile/apps/locker/lib/ui/pages/base_info_page.dart b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
index 6e8ec40004..07718d6475 100644
--- a/mobile/apps/locker/lib/ui/pages/base_info_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
@@ -692,7 +692,7 @@ class _InfoViewFieldState extends State<_InfoViewField> {
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
- final hasValue = widget.value.trim().isNotEmpty;
+ final hasValue = widget.value.isNotEmpty;
final onCopy = hasValue ? widget.onCopy : null;
if (widget.isSecret) {
diff --git a/mobile/apps/locker/test/ui/pages/required_info_fields_test.dart b/mobile/apps/locker/test/ui/pages/required_info_fields_test.dart
index 5ad2780d1a..7e3c68a00f 100644
--- a/mobile/apps/locker/test/ui/pages/required_info_fields_test.dart
+++ b/mobile/apps/locker/test/ui/pages/required_info_fields_test.dart
@@ -4,6 +4,7 @@ import 'dart:io';
import 'package:ente_components/ente_components.dart';
import 'package:ente_strings/ente_strings.dart';
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:locker/models/file_type.dart';
import 'package:locker/models/info/info_item.dart';
@@ -12,6 +13,7 @@ import 'package:locker/services/files/sync/models/file.dart';
import 'package:locker/services/files/sync/models/file_magic.dart';
import 'package:locker/ui/pages/account_credentials_page.dart';
import 'package:locker/ui/pages/base_info_page.dart';
+import 'package:locker/ui/pages/emergency_contact_page.dart';
import 'package:locker/ui/pages/personal_note_page.dart';
import 'package:locker/ui/pages/physical_records_page.dart';
@@ -87,6 +89,115 @@ void main() {
expect(state.validateForm(), isFalse);
});
+ for (final password in [' secret', 'secret ', ' secret ', ' ']) {
+ testWidgets('Secret saves, reopens and copies exact password "$password"', (
+ tester,
+ ) async {
+ await showPage(tester, const AccountCredentialsPage());
+ await tester.enterText(find.byType(TextField).first, ' Account ');
+ await tester.enterText(find.byType(TextField).at(1), ' username ');
+ await tester.enterText(find.byType(TextField).at(2), password);
+ await tester.enterText(find.byType(TextField).at(3), ' notes ');
+ final state =
+ tester.state(find.byType(AccountCredentialsPage)) as dynamic;
+ final data = state.createInfoData() as AccountCredentialData;
+ expect(data.password, password);
+ expect(data.name, 'Account');
+ expect(data.username, 'username');
+ expect(data.notes, 'notes');
+ final file = partialFile(
+ 'accountCredential',
+ jsonDecode(jsonEncode(data.toJson())) as Map<String, dynamic>,
+ );
+
+ await tester.pumpWidget(const SizedBox.shrink());
+ await showPage(tester, AccountCredentialsPage(existingFile: file));
+ expect(
+ tester.widget<TextField>(find.byType(TextField).at(2)).controller!.text,
+ password,
+ );
+ final reopened =
+ tester.state(find.byType(AccountCredentialsPage)) as dynamic;
+ expect(reopened.hasUnsavedChanges, isFalse);
+ await tester.enterText(find.byType(TextField).first, 'Renamed');
+ expect(reopened.createInfoData().password, password);
+
+ await tester.pumpWidget(const SizedBox.shrink());
+ await showPage(
+ tester,
+ AccountCredentialsPage(mode: InfoPageMode.view, existingFile: file),
+ );
+ expect(find.text('Password'), findsOneWidget);
+ expect(find.text('β€’β€’β€’β€’β€’β€’β€’β€’'), findsOneWidget);
+ String? copied;
+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
+ SystemChannels.platform,
+ (call) async {
+ if (call.method == 'Clipboard.setData') {
+ copied = (call.arguments as Map)['text'] as String;
+ }
+ return null;
+ },
+ );
+ await tester.tap(find.bySemanticsLabel('copy_password'));
+ await tester.pump();
+ expect(copied, password);
+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
+ SystemChannels.platform,
+ null,
+ );
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(seconds: 3));
+ });
+ }
+
+ testWidgets('Secret detects edits that only change password whitespace', (
+ tester,
+ ) async {
+ await showPage(
+ tester,
+ AccountCredentialsPage(
+ existingFile: partialFile('accountCredential', {
+ 'name': 'Account',
+ 'password': 'secret',
+ }),
+ ),
+ );
+ final state = tester.state(find.byType(AccountCredentialsPage)) as dynamic;
+ for (final password in [' secret', 'secret ', ' secret ']) {
+ await tester.enterText(find.byType(TextField).at(2), password);
+ expect(state.hasUnsavedChanges, isTrue);
+ }
+ await tester.enterText(find.byType(TextField).at(2), 'secret');
+ expect(state.hasUnsavedChanges, isFalse);
+
+ await tester.pumpWidget(const SizedBox.shrink());
+ await showPage(tester, const AccountCredentialsPage());
+ await tester.enterText(find.byType(TextField).at(2), ' ');
+ final blankState =
+ tester.state(find.byType(AccountCredentialsPage)) as dynamic;
+ expect(blankState.hasUnsavedChanges, isTrue);
+ await tester.enterText(find.byType(TextField).at(2), '');
+ expect(blankState.hasUnsavedChanges, isFalse);
+ });
+
+ testWidgets('saved whitespace-only Secret password is visible and copyable', (
+ tester,
+ ) async {
+ await showPage(
+ tester,
+ AccountCredentialsPage(
+ mode: InfoPageMode.view,
+ existingFile: partialFile('accountCredential', {
+ 'name': 'Account',
+ 'password': ' ',
+ }),
+ ),
+ );
+ expect(find.text('Password'), findsOneWidget);
+ expect(find.bySemanticsLabel('copy_password'), findsOneWidget);
+ });
+
testWidgets('partial Secret shows Notes without phantom credentials', (
tester,
) async {
@@ -107,6 +218,55 @@ void main() {
expect(find.text('β€’β€’β€’β€’β€’β€’β€’β€’'), findsNothing);
});
+ for (final name in [' ', '']) {
+ testWidgets(
+ 'shared view field uses exact emptiness for contact name "$name"',
+ (tester) async {
+ await showPage(
+ tester,
+ EmergencyContactPage(
+ mode: InfoPageMode.view,
+ existingFile: partialFile('emergencyContact', {
+ 'name': name,
+ 'contactDetails': '555-0100',
+ }),
+ ),
+ );
+
+ final fieldFinder = find.byType(TextInputComponent).first;
+ final field = tester.widget<TextInputComponent>(fieldFinder);
+ expect(field.initialValue, name);
+ if (name.isEmpty) {
+ expect(field.suffix, isNull);
+ expect(field.onSuffixTap, isNull);
+ } else {
+ expect(field.suffix, isNotNull);
+ String? copied;
+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
+ SystemChannels.platform,
+ (call) async {
+ if (call.method == 'Clipboard.setData') {
+ copied = (call.arguments as Map)['text'] as String;
+ }
+ return null;
+ },
+ );
+ addTearDown(() {
+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
+ SystemChannels.platform,
+ null,
+ );
+ });
+ await tester.tap(find.byWidget(field.suffix!));
+ await tester.pump();
+ expect(copied, name);
+ await tester.pumpWidget(const SizedBox.shrink());
+ await tester.pump(const Duration(seconds: 3));
+ }
+ },
+ );
+ }
+
testWidgets('partial Thing omits empty Location', (tester) async {
await showPage(
tester,