Files
umbrix/test/features/profile/data/profile_parser_test.dart

106 lines
3.2 KiB
Dart
Raw Normal View History

2023-07-25 21:41:12 +03:30
import 'package:flutter_test/flutter_test.dart';
2023-11-26 21:20:58 +03:30
import 'package:hiddify/features/profile/data/profile_parser.dart';
import 'package:hiddify/features/profile/model/profile_entity.dart';
2023-07-25 21:41:12 +03:30
void main() {
const validBaseUrl = "https://example.com/configurations/user1/filename.yaml";
const validExtendedUrl =
"https://example.com/configurations/user1/filename.yaml?test#b";
const validSupportUrl = "https://example.com/support";
group(
2023-11-26 21:20:58 +03:30
"parse",
2023-07-25 21:41:12 +03:30
() {
test(
2023-11-26 21:20:58 +03:30
"url with file extension, no headers",
2023-07-25 21:41:12 +03:30
() {
2023-11-26 21:20:58 +03:30
final profile = ProfileParser.parse(validBaseUrl, {});
2023-07-25 21:41:12 +03:30
expect(profile.name, equals("filename"));
2023-11-26 21:20:58 +03:30
expect(profile.url, equals(validBaseUrl));
expect(profile.options, isNull);
expect(profile.subInfo, isNull);
},
);
test(
"url with url, no headers",
() {
final profile = ProfileParser.parse(validExtendedUrl, {});
expect(profile.name, equals("b"));
2023-07-25 21:41:12 +03:30
expect(profile.url, equals(validExtendedUrl));
expect(profile.options, isNull);
expect(profile.subInfo, isNull);
},
);
test(
2023-11-26 21:20:58 +03:30
"with base64 profile-title header",
2023-07-25 21:41:12 +03:30
() {
final headers = <String, List<String>>{
"profile-title": ["base64:ZXhhbXBsZVRpdGxl"],
"profile-update-interval": ["1"],
"subscription-userinfo": [
2023-10-06 17:31:53 +03:30
"upload=0;download=1024;total=10240.5;expire=1704054600.55",
2023-07-25 21:41:12 +03:30
],
"profile-web-page-url": [validBaseUrl],
"support-url": [validSupportUrl],
};
2023-11-26 21:20:58 +03:30
final profile = ProfileParser.parse(validExtendedUrl, headers);
2023-07-25 21:41:12 +03:30
expect(profile.name, equals("exampleTitle"));
expect(profile.url, equals(validExtendedUrl));
expect(
profile.options,
equals(const ProfileOptions(updateInterval: Duration(hours: 1))),
);
expect(
profile.subInfo,
equals(
SubscriptionInfo(
upload: 0,
download: 1024,
total: 10240,
expire: DateTime(2024),
webPageUrl: validBaseUrl,
supportUrl: validSupportUrl,
),
),
);
},
);
test(
"with infinite traffic and time",
() {
final headers = <String, List<String>>{
"profile-title": ["title"],
"profile-update-interval": ["1"],
"subscription-userinfo": [
"upload=0;download=1024;total=0;expire=0",
],
"profile-web-page-url": [validBaseUrl],
"support-url": [validSupportUrl],
};
final profile = ProfileParser.parse(validExtendedUrl, headers);
expect(profile.subInfo, isNotNull);
expect(
profile.subInfo!.total,
equals(ProfileParser.infiniteTrafficThreshold),
);
expect(
profile.subInfo!.expire,
equals(
DateTime.fromMillisecondsSinceEpoch(
ProfileParser.infiniteTimeThreshold * 1000,
),
),
);
},
);
2023-07-25 21:41:12 +03:30
},
);
}