Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite sub expire date #334

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/features/profile/data/profile_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import 'package:uuid/uuid.dart';
/// - url filename extension (example: `https://example.com/config.json`) -> name=`config`
/// - if none of these methods return a non-blank string, fallback to `Remote Profile`
abstract class ProfileParser {
static const infiniteTrafficThreshold = 9223372036854775807;
static const infiniteTimeThreshold = 92233720368;

static RemoteProfileEntity parse(
String url,
Map<String, List<String>> headers,
Expand Down Expand Up @@ -89,16 +92,15 @@ abstract class ProfileParser {
"upload": final upload?,
"download": final download?,
"total": var total,
"expire": final expire
"expire": var expire
}) {
total = total ?? 0;
total = (total == null || total == 0) ? infiniteTrafficThreshold : total;
expire = (expire == null || expire == 0) ? infiniteTimeThreshold : expire;
return SubscriptionInfo(
upload: upload,
download: download,
total: total == 0 ? 9223372036854775807 : total,
expire: DateTime.fromMillisecondsSinceEpoch(
(expire ?? 92233720368) * 1000,
),
total: total,
expire: DateTime.fromMillisecondsSinceEpoch(expire * 1000),
);
}
return null;
Expand Down
30 changes: 30 additions & 0 deletions test/features/profile/data/profile_parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ void main() {
);
},
);

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,
),
),
);
},
);
},
);
}
Loading