- SessionShare:把 userId / JSESSIONID / token 打成 Base64(JSON),Cookie 只保留 JSESSIONID 一项,粘贴时容忍换行与空白,QR 令牌与乱码解不出来 - 主页底部新增「导出连接信息」卡片,标记实验性:内容未加密,字符串在手即可操作账号 - 登录页识别到连接信息时把登录按钮换成「恢复会话」,不必再扫 QR 令牌 - 恢复优先沿用导入的 JSESSIONID(不重发 UserLoginApi,免得顶掉机台上的登录), Cookie 失效才退回用 token 登录;验证 Cookie 时顺手拉到的 GetUserDataApi 结果 直接交给主页展示,省一次请求 - 仅凭 Cookie 恢复的会话没有 loginId / loginDateTime,_gameLogin 保持 null, 票据与风险页照旧提示「尚未登录游戏服务器」,主页顶部给出说明横幅 - 关于页改用 AppCard / SectionTitle 脚手架,补基本信息与风险提示,把过时的 「jsQR (web)」致谢换成原生 MethodChannel(QR 解码早已不走 web 库)
116 lines
3.6 KiB
Dart
116 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:ichino/config/strings.dart';
|
|
import 'package:ichino/models/session_model.dart';
|
|
import 'package:ichino/models/session_share.dart';
|
|
import 'package:ichino/widgets/connection_share_card.dart';
|
|
|
|
void main() {
|
|
group('SessionShare', () {
|
|
test('编码后能解回同样的会话', () {
|
|
const share = SessionShare(
|
|
userId: 1234567,
|
|
token: 'SGWCMAIDABCDEF',
|
|
cookie: 'JSESSIONID=abc123DEF',
|
|
);
|
|
|
|
final decoded = SessionShare.tryDecode(share.encode());
|
|
|
|
expect(decoded, isNotNull);
|
|
expect(decoded!.userId, 1234567);
|
|
expect(decoded.token, 'SGWCMAIDABCDEF');
|
|
expect(decoded.jsessionid, 'JSESSIONID=abc123DEF');
|
|
});
|
|
|
|
test('只保留 JSESSIONID,忽略其它 Cookie', () {
|
|
const share = SessionShare(
|
|
userId: 1,
|
|
token: 't',
|
|
cookie: 'OTHER=x; JSESSIONID=keep-me; Path=/',
|
|
);
|
|
|
|
final decoded = SessionShare.tryDecode(share.encode())!;
|
|
|
|
expect(decoded.jsessionid, 'JSESSIONID=keep-me');
|
|
});
|
|
|
|
test('换行与空白不影响解析', () {
|
|
const share = SessionShare(
|
|
userId: 42,
|
|
token: 'tok',
|
|
cookie: 'JSESSIONID=z',
|
|
);
|
|
final wrapped =
|
|
' ${share.encode().replaceAllMapped(RegExp(r'.{8}'), (m) => '${m[0]}\n')} ';
|
|
|
|
expect(SessionShare.tryDecode(wrapped)?.userId, 42);
|
|
});
|
|
|
|
test('QR 令牌与乱码不是连接信息', () {
|
|
final qrToken = 'SGWCMAID${'0123456789ABCDEF' * 3}01234567';
|
|
expect(qrToken.length, 64);
|
|
expect(SessionShare.tryDecode(qrToken), isNull);
|
|
expect(SessionShare.tryDecode('not base64 at all !!'), isNull);
|
|
expect(SessionShare.tryDecode(''), isNull);
|
|
});
|
|
|
|
test('cookie 与 token 都空、或 userId 非法时拒绝', () {
|
|
expect(
|
|
SessionShare.tryDecode(
|
|
const SessionShare(
|
|
userId: 0,
|
|
token: '',
|
|
cookie: 'JSESSIONID=x',
|
|
).encode(),
|
|
),
|
|
isNull,
|
|
);
|
|
expect(
|
|
SessionShare.tryDecode(
|
|
const SessionShare(userId: 7, token: '', cookie: null).encode(),
|
|
),
|
|
isNull,
|
|
);
|
|
});
|
|
});
|
|
|
|
group('ConnectionShareCard', () {
|
|
Widget wrap(Widget child) => MaterialApp(
|
|
home: Scaffold(body: SingleChildScrollView(child: child)),
|
|
);
|
|
|
|
testWidgets('复制到剪贴板并展开 Base64 内容与外传警示', (tester) async {
|
|
final copied = <String>[];
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
|
if (call.method == 'Clipboard.setData') {
|
|
copied.add(((call.arguments as Map)['text'] as String?) ?? '');
|
|
}
|
|
return null;
|
|
});
|
|
addTearDown(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(SystemChannels.platform, null);
|
|
});
|
|
|
|
await tester.pumpWidget(
|
|
wrap(const ConnectionShareCard(userId: 7, token: 'tok')),
|
|
);
|
|
|
|
expect(find.text(AppStrings.experimentalBadge), findsOneWidget);
|
|
expect(find.text(AppStrings.connectionShareSecurity), findsNothing);
|
|
|
|
await tester.tap(find.text(AppStrings.connectionShareCopy));
|
|
await tester.pump();
|
|
|
|
final encoded = SessionModel.instance
|
|
.exportConnectionInfo(userId: 7, token: 'tok')
|
|
.encode();
|
|
expect(copied, [encoded]);
|
|
expect(find.text(AppStrings.connectionShareSecurity), findsOneWidget);
|
|
expect(find.text(encoded), findsOneWidget);
|
|
});
|
|
});
|
|
}
|