Ask for the password once and retry when a machine requires elevation
Carry the protocol error code, wrap each machine's gateway so an elevation_required refusal shows one native password dialog, elevates that connection and retries; send the upload token with file uploads; add a Settings sign-in security section with the weak-password warning and sign out everywhere; accept the __Host- session cookie.
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/session/server_session.dart';
|
||||
import 'package:pipelines_app/features/settings/security/session_security_api.dart';
|
||||
import 'package:pipelines_app/features/settings/security/settings_security_section.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
late SecurityRequest originalSend;
|
||||
late void Function() originalOpen;
|
||||
final requests = <String>[];
|
||||
var weak = true;
|
||||
|
||||
setUp(() async {
|
||||
originalSend = sendSecurityRequest;
|
||||
originalOpen = openWebSignIn;
|
||||
requests.clear();
|
||||
weak = true;
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await ServerSession.load();
|
||||
sendSecurityRequest = (method, uri) async {
|
||||
requests.add('$method $uri');
|
||||
if (uri.path == '/api/session') {
|
||||
return (
|
||||
status: 200,
|
||||
body:
|
||||
'{"weak_password":$weak,"password_rule":"Use 16 or more characters."}',
|
||||
);
|
||||
}
|
||||
return (status: 200, body: '{"revoked":true}');
|
||||
};
|
||||
});
|
||||
tearDown(() {
|
||||
sendSecurityRequest = originalSend;
|
||||
openWebSignIn = originalOpen;
|
||||
});
|
||||
|
||||
Future<void> pump(
|
||||
WidgetTester tester, {
|
||||
bool web = false,
|
||||
VoidCallback? onSignedOut,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SettingsSecuritySection(
|
||||
endpoint: 'wss://box.ts.net:8443/connect',
|
||||
onSignedOut: onSignedOut ?? () {},
|
||||
web: web,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('warns about a weak password with the rule', (tester) async {
|
||||
await pump(tester);
|
||||
expect(requests, ['GET https://box.ts.net:8443/api/session']);
|
||||
final warning = find.byKey(const Key('settings-weak-password'));
|
||||
expect(warning, findsOneWidget);
|
||||
expect(
|
||||
tester.widget<Text>(warning).data,
|
||||
contains('Use 16 or more characters. Run ./password on the server'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a strong password shows no warning', (tester) async {
|
||||
weak = false;
|
||||
await pump(tester);
|
||||
expect(find.byKey(const Key('settings-weak-password')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('sign out everywhere confirms, revokes and signs out', (
|
||||
tester,
|
||||
) async {
|
||||
var signedOut = 0;
|
||||
await pump(tester, onSignedOut: () => signedOut++);
|
||||
await tester.tap(find.byKey(const Key('settings-revoke-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(requests, hasLength(1));
|
||||
await tester.tap(find.byKey(const Key('settings-revoke-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('settings-revoke-all-confirm')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
requests.last,
|
||||
'POST https://box.ts.net:8443/api/sessions/revoke-all',
|
||||
);
|
||||
expect(signedOut, 1);
|
||||
expect(ServerSession.cookie, isNull);
|
||||
expect(find.textContaining('Signed out everywhere'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the web app leaves for the sign-in page', (tester) async {
|
||||
var opened = 0;
|
||||
openWebSignIn = () => opened++;
|
||||
await pump(tester, web: true);
|
||||
await tester.tap(find.byKey(const Key('settings-revoke-all')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('settings-revoke-all-confirm')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, 1);
|
||||
});
|
||||
|
||||
testWidgets('a signed-out device says so', (tester) async {
|
||||
sendSecurityRequest = (method, uri) async => (status: 401, body: '');
|
||||
await pump(tester);
|
||||
expect(find.textContaining('Sign in to see'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user