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

feat: add validator to check for macOS app network entitlement #2676

Merged
merged 81 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
fde077e
feat: add macos release type to shorebird_code_push_protocol
bryanoltman Nov 26, 2024
3aee1a1
feat: add support for releasing and patching macOS apps
bryanoltman Nov 26, 2024
f614b30
Merge branch 'main' into bo/macos
bryanoltman Dec 2, 2024
81870f7
wip
bryanoltman Dec 2, 2024
dfb50a6
merge main
bryanoltman Dec 5, 2024
56bb42c
merge
bryanoltman Dec 5, 2024
0f510fc
update artifact proxy
bryanoltman Dec 5, 2024
3fd6c22
clean
bryanoltman Dec 5, 2024
7694fa5
add support for supplementary release data
bryanoltman Dec 5, 2024
0b30046
Merge branch 'main' into bo/macos
bryanoltman Dec 5, 2024
9f692fb
fix merge
bryanoltman Dec 5, 2024
15830d1
wip
bryanoltman Dec 5, 2024
21ebe63
fix macos patch logic
bryanoltman Dec 6, 2024
3a369d0
remove unused import
bryanoltman Dec 6, 2024
8200548
add separate gen_snapshot for mac
bryanoltman Dec 9, 2024
1922b5e
merge main
bryanoltman Dec 9, 2024
80f4308
chore: add test files for macos releaser/patcher
bryanoltman Dec 9, 2024
88a4954
tests, more wip
bryanoltman Dec 9, 2024
3e9e458
coverage
bryanoltman Dec 9, 2024
cfbd3d5
coverage, cleanup
bryanoltman Dec 9, 2024
274d284
Merge branch 'main' into bo/macos
felangel Dec 10, 2024
fddaced
use correct gen_snapshot when buildElfAotSnapshot
bryanoltman Dec 10, 2024
788badf
fix macos preview
felangel Dec 10, 2024
e1f43f7
fix: use ditto in macos_patcher
felangel Dec 10, 2024
ac4f357
Split macos/ios analyze_snapshot
bryanoltman Dec 10, 2024
ed1adb4
chore: bump flutter rev
bryanoltman Dec 10, 2024
ddfd5e3
wip
bryanoltman Dec 10, 2024
2008b60
fix macos_releaser test
felangel Dec 10, 2024
e1d4141
more test fixes
felangel Dec 10, 2024
b0029aa
fix snapshot paths
bryanoltman Dec 10, 2024
1ef87b1
create `Ditto` wrapper
felangel Dec 10, 2024
6589301
use ditto in code_push_client_wrapper
felangel Dec 11, 2024
9b83494
refactor: use ditto.archive in mac_patcher
felangel Dec 11, 2024
082147d
test: add `ditto` tests
felangel Dec 11, 2024
189176e
passing unit tests
felangel Dec 11, 2024
f3b4ffa
tests: code_push_client_wrapper_test
felangel Dec 11, 2024
0d3cfbb
tests: shorebird_artifacts_test
felangel Dec 11, 2024
8cfcab6
tests: artifact_manager_test
felangel Dec 11, 2024
88b2a61
tests: artifact_manager_test
felangel Dec 11, 2024
3742f45
format
felangel Dec 11, 2024
db17846
fix MacosPatcher tests
bryanoltman Dec 11, 2024
470dd3c
Merge branch 'bo/macos' of github.com:shorebirdtech/shorebird into bo…
bryanoltman Dec 11, 2024
cfc7d4b
cspell
bryanoltman Dec 11, 2024
e80b1d0
cspell
bryanoltman Dec 11, 2024
fc9d430
CSPELL
bryanoltman Dec 11, 2024
0335474
coverage
bryanoltman Dec 11, 2024
38aea73
preview coverage
felangel Dec 11, 2024
fffaa13
coverage
bryanoltman Dec 11, 2024
7d17f5d
artifact build tests/coverage
bryanoltman Dec 11, 2024
9aa731b
format
bryanoltman Dec 11, 2024
02cca6e
formatting
bryanoltman Dec 11, 2024
0e01803
dart pub upgrade with dart 3.6.0
bryanoltman Dec 11, 2024
2d67829
coverage
bryanoltman Dec 11, 2024
07f9ff3
cleanup
bryanoltman Dec 11, 2024
b64b774
coverage
bryanoltman Dec 11, 2024
ed71434
patcher coverage, completeness
bryanoltman Dec 11, 2024
3489664
coverage
bryanoltman Dec 11, 2024
1f4f02a
fix linux tests
bryanoltman Dec 11, 2024
8050350
coverage
bryanoltman Dec 11, 2024
8c8eff7
cleanup, pr feedback
bryanoltman Dec 11, 2024
b9f9bd1
cleanup
bryanoltman Dec 11, 2024
3851d97
lints
bryanoltman Dec 11, 2024
e0d81d6
polish
bryanoltman Dec 11, 2024
1f3cf0e
coverage
bryanoltman Dec 11, 2024
7f5b77f
fix tests
bryanoltman Dec 11, 2024
a39e7f5
print beta warning when releasing or patching macos
bryanoltman Dec 11, 2024
ffe9044
coverage
bryanoltman Dec 11, 2024
9396c17
feat: add validator to check for macOS app network entitlement
bryanoltman Dec 12, 2024
56e9c34
Merge branch 'main' into bo/macos-entitlement-validator
bryanoltman Dec 12, 2024
6c35229
coverage
bryanoltman Dec 12, 2024
731d26c
Use macos podfile.lock for macos builds
bryanoltman Dec 12, 2024
f798345
Merge branch 'bo/macos' into bo/macos-entitlement-validator
bryanoltman Dec 12, 2024
81673c0
Don't pass sequesterRsrc flag to ditto
bryanoltman Dec 12, 2024
b90c7d0
Merge branch 'bo/macos' into bo/macos-entitlement-validator
bryanoltman Dec 12, 2024
e1e4ddf
Merge branch 'main' into bo/macos
felangel Dec 12, 2024
f03cc46
coverage
bryanoltman Dec 13, 2024
1d80e45
Merge branch 'bo/macos' into bo/macos-entitlement-validator
bryanoltman Dec 13, 2024
5a3119d
Merge branch 'main' into bo/macos
bryanoltman Dec 13, 2024
bb477d2
Merge branch 'bo/macos' into bo/macos-entitlement-validator
bryanoltman Dec 13, 2024
fd5b7a4
Merge branch 'main' into bo/macos-entitlement-validator
bryanoltman Dec 16, 2024
2a936a6
fix tests
bryanoltman Dec 16, 2024
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
4 changes: 4 additions & 0 deletions packages/shorebird_cli/lib/src/archive_analysis/plist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ class Plist {
? releaseVersion
: '$releaseVersion+$buildNumber';
}

@override
String toString() =>
PropertyListSerialization.stringWithPropertyList(properties);
}
13 changes: 8 additions & 5 deletions packages/shorebird_cli/lib/src/doctor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ class Doctor {

/// Validators that verify shorebird will work on macOS.
final List<Validator> macosCommandValidators = [
// TODO(bryanoltman): ensure app has network capabilities
MacosNetworkEntitlementValidator(),
];

/// Validators that should run on all commands.
List<Validator> generalValidators = [
ShorebirdVersionValidator(),
ShorebirdFlutterValidator(),
AndroidInternetPermissionValidator(),
MacosNetworkEntitlementValidator(),
ShorebirdYamlAssetValidator(),
];

Expand All @@ -46,7 +47,7 @@ class Doctor {
final allIssues = <ValidationIssue>[];
final allFixableIssues = <ValidationIssue>[];

var numIssuesFixed = 0;
var totalIssuesFixed = 0;
for (final validator in validators) {
if (!validator.canRunInCurrentContext()) {
continue;
Expand Down Expand Up @@ -76,13 +77,15 @@ class Doctor {
// Re-run the validator to see if there are any remaining issues that
// we couldn't fix.
unresolvedIssues = await validator.validate();
if (unresolvedIssues.isEmpty) {
numIssuesFixed += issues.length - unresolvedIssues.length;
final numIssuesFixed = issues.length - unresolvedIssues.length;
if (numIssuesFixed > 0) {
totalIssuesFixed += numIssuesFixed;
final fixAppliedMessage =
'''($numIssuesFixed fix${numIssuesFixed == 1 ? '' : 'es'} applied)''';
validatorProgress.complete(
'''${validator.description} ${green.wrap(fixAppliedMessage)}''',
);

continue;
}
} else {
Expand Down Expand Up @@ -125,7 +128,7 @@ class Doctor {
allIssues.addAll(unresolvedIssues);
}

if (numIssuesFixed > 0) {
if (totalIssuesFixed > 0) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import 'dart:io';

import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/archive_analysis/plist.dart';
import 'package:shorebird_cli/src/shorebird_env.dart';
import 'package:shorebird_cli/src/validators/validators.dart';

/// Checks that the macOS app has the network client entitlement. Without this
/// entitlement, the app will not be able to make network requests, and
/// Shorebird will not be able to check for patches.
class MacosNetworkEntitlementValidator extends Validator {
/// The plist key for the Outgoing Connections (Client) entitlement, which
/// allows macOS apps to make network requests.
static const networkClientEntitlementKey =
'com.apple.security.network.client';

Directory? get _macosDirectory {
final projectRoot = shorebirdEnv.getFlutterProjectRoot();
if (projectRoot == null) {
return null;
}

return Directory(p.join(projectRoot.path, 'macos'));
}

/// The entitlements plist file for the release build. This lives in
/// project_root/macos/Runner/Release.entitlements, where "Runner" may have
/// been renamed.
File? get _releaseEntitlementsPlist {
final entitlementParentCandidateDirectories =
_macosDirectory!.listSync().whereType<Directory>();

for (final appDir in entitlementParentCandidateDirectories) {
final entitlementsPlist = File(
p.join(appDir.path, 'Release.entitlements'),
);

if (entitlementsPlist.existsSync()) {
return entitlementsPlist;
}
}

return null;
}

@override
String get description => 'macOS app has Outgoing Connections entitlement';

@override
bool canRunInCurrentContext() =>
_macosDirectory != null && _macosDirectory!.existsSync();

@override
Future<List<ValidationIssue>> validate() async {
if (_releaseEntitlementsPlist == null) {
return [
const ValidationIssue(
severity: ValidationIssueSeverity.error,
message: 'Unable to find a Release.entitlements file',
),
];
}

if (!hasNetworkClientEntitlement(plistFile: _releaseEntitlementsPlist!)) {
return [
ValidationIssue(
severity: ValidationIssueSeverity.error,
message:
'''${_releaseEntitlementsPlist!.path} is missing the Outgoing Connections ($networkClientEntitlementKey) entitlement.''',
fix: () => addNetworkEntitlementToPlist(_releaseEntitlementsPlist!),
),
];
}

return [];
}

/// Whether the given entitlements plist file has the network client
/// entitlement.
@visibleForTesting
static bool hasNetworkClientEntitlement({required File plistFile}) =>
Plist(file: plistFile).properties[networkClientEntitlementKey] == true;

/// Adds the network client entitlement to the given entitlements plist file.
@visibleForTesting
static void addNetworkEntitlementToPlist(File entitlementsPlist) {
final plist = Plist(file: entitlementsPlist);
plist.properties[networkClientEntitlementKey] = true;
entitlementsPlist.writeAsStringSync(plist.toString());
}
}
1 change: 1 addition & 0 deletions packages/shorebird_cli/lib/src/validators/validators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:shorebird_cli/src/shorebird_process.dart';

export 'android_internet_permission_validator.dart';
export 'flavor_validator.dart';
export 'macos_network_entitlement_validator.dart';
export 'shorebird_flutter_validator.dart';
export 'shorebird_version_validator.dart';
export 'shorebird_yaml_asset_validator.dart';
Expand Down
Loading
Loading