Skip to content

Commit fa902c6

Browse files
Mehul-Kumar-27chrisbobbe
authored andcommitted
login: Send trimmed username/email in fetch-API-key request, using .trim()
Fixes: zulip#547 [chris: edited commit message to match style; adjusted blank lines and indentation in test for consistency with neighboring tests]
1 parent 1a5425e commit fa902c6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/widgets/login.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class _UsernamePasswordFormState extends State<_UsernamePasswordForm> {
490490
if (!usernameValid || !passwordValid) {
491491
return;
492492
}
493-
final String username = usernameFieldState.value!;
493+
final String username = usernameFieldState.value!.trim();
494494
final String password = passwordFieldState.value!;
495495

496496
widget.loginPageState.setState(() {

test/widgets/login_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ void main() {
135135
id: testBinding.globalStore.accounts.single.id));
136136
});
137137

138+
testWidgets('trims whitespace on username', (tester) async {
139+
final serverSettings = eg.serverSettings();
140+
await prepare(tester, serverSettings);
141+
check(testBinding.globalStore.accounts).isEmpty();
142+
143+
await tester.enterText(findUsernameInput, ' ${eg.selfAccount.email} ');
144+
await tester.enterText(findPasswordInput, 'p455w0rd');
145+
connection.prepare(json: FetchApiKeyResult(
146+
apiKey: eg.selfAccount.apiKey,
147+
email: eg.selfAccount.email,
148+
userId: eg.selfAccount.userId,
149+
).toJson());
150+
await tester.tap(findSubmitButton);
151+
checkFetchApiKey(username: eg.selfAccount.email, password: 'p455w0rd');
152+
await tester.idle();
153+
check(testBinding.globalStore.accounts).single
154+
.equals(eg.selfAccount.copyWith(
155+
id: testBinding.globalStore.accounts.single.id));
156+
});
157+
138158
testWidgets('account already exists', (tester) async {
139159
final serverSettings = eg.serverSettings();
140160
await prepare(tester, serverSettings);

0 commit comments

Comments
 (0)