From 41c601e4786b544fdd1fca138b0e0c61dbb8eba2 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Date: Thu, 25 Jan 2024 02:04:18 -0800 Subject: [PATCH] Remove ATS config patch from react_native_post_install (#42637) Summary: This PR removes the `apply_ats_config` function of ReactNativePodsUtils that was used inside `react_native_post_install` because it was preventing users from configuring `NSAllowsArbitraryLoads` to true in their projects, especially when building in CI as the plist file would be reset after running pod install. ## Changelog: [IOS] [CHANGED] - Remove ATS config patch from react_native_post_install Pull Request resolved: https://github.com/facebook/react-native/pull/42637 Test Plan: Edit `Info.plist`, run `pod install` and check if changes have not been overwritten Reviewed By: cortinico Differential Revision: D53048299 Pulled By: cipolleschi fbshipit-source-id: 8dc335fae2e05a62daf931a50fa3f7a314e76a2e --- .../scripts/cocoapods/__tests__/utils-test.rb | 52 ------------------- .../react-native/scripts/cocoapods/utils.rb | 37 ------------- .../react-native/scripts/react_native_pods.rb | 3 +- 3 files changed, 1 insertion(+), 91 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb index 206496899513c9..2b25929fe32d62 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb @@ -837,58 +837,6 @@ def test_updateSearchPaths_whenNotUseFrameworks_addsSearchPaths end end - # ============================== # - # Test - Apply ATS configuration # - # ============================== # - - def test_applyATSConfig_plistNil - # Arrange - user_project_mock = prepare_user_project_mock_with_plists() - pods_projects_mock = PodsProjectMock.new([], {"some_pod" => {}}) - installer = InstallerMock.new(pods_projects_mock, [ - AggregatedProjectMock.new(user_project_mock) - ]) - - # # Act - ReactNativePodsUtils.apply_ats_config(installer) - - # # Assert - assert_equal(user_project_mock.files.length, 2) - user_project_mock.files.each do |file| - path = File.join(user_project_mock.path.parent, file.name) - plist = Xcodeproj::Plist.read_from_path(path) - assert_equal(plist['NSAppTransportSecurity'], { - 'NSAllowsArbitraryLoads' => false, - 'NSAllowsLocalNetworking' => true, - }); - end - end - - def test_applyATSConfig_plistNonNil - # Arrange - user_project_mock = prepare_user_project_mock_with_plists() - pods_projects_mock = PodsProjectMock.new([], {"some_pod" => {}}) - installer = InstallerMock.new(pods_projects_mock, [ - AggregatedProjectMock.new(user_project_mock) - ]) - Xcodeproj::Plist.write_to_path({}, "/test/Info.plist") - Xcodeproj::Plist.write_to_path({}, "/test/Extension-Info.plist") - - # # Act - ReactNativePodsUtils.apply_ats_config(installer) - - # # Assert - assert_equal(user_project_mock.files.length, 2) - user_project_mock.files.each do |file| - path = File.join(user_project_mock.path.parent, file.name) - plist = Xcodeproj::Plist.read_from_path(path) - assert_equal(plist['NSAppTransportSecurity'], { - 'NSAllowsArbitraryLoads' => false, - 'NSAllowsLocalNetworking' => true, - }); - end - end - # =============================================== # # Test - Create Header Search Path For Frameworks # # =============================================== # diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 2692733cb984d9..6df005cee4fc1e 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -556,43 +556,6 @@ def self.set_imagemanager_search_path(target_installation_result) ReactNativePodsUtils.update_header_paths_if_depends_on(target_installation_result, "React-ImageManager", header_search_paths) end - def self.get_plist_paths_from(user_project) - info_plists = user_project - .files - .select { |p| - p.name&.end_with?('Info.plist') - } - return info_plists - end - - def self.update_ats_in_plist(plistPaths, parent) - plistPaths.each do |plistPath| - fullPlistPath = File.join(parent, plistPath.path) - plist = Xcodeproj::Plist.read_from_path(fullPlistPath) - ats_configs = { - "NSAllowsArbitraryLoads" => false, - "NSAllowsLocalNetworking" => true, - } - if plist.nil? - plist = { - "NSAppTransportSecurity" => ats_configs - } - else - plist["NSAppTransportSecurity"] ||= {} - plist["NSAppTransportSecurity"] = plist["NSAppTransportSecurity"].merge(ats_configs) - end - Xcodeproj::Plist.write_to_path(plist, fullPlistPath) - end - end - - def self.apply_ats_config(installer) - user_project = installer.aggregate_targets - .map{ |t| t.user_project } - .first - plistPaths = self.get_plist_paths_from(user_project) - self.update_ats_in_plist(plistPaths, user_project.path.parent) - end - def self.react_native_pods return [ "DoubleConversion", diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index db8fd0140883c6..91a241c2301379 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -285,8 +285,7 @@ def react_native_post_install( ReactNativePodsUtils.set_use_hermes_build_setting(installer, hermes_enabled) ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path) ReactNativePodsUtils.set_ccache_compiler_and_linker_build_settings(installer, react_native_path, ccache_enabled) - ReactNativePodsUtils.apply_xcode_15_patch(installer) - ReactNativePodsUtils.apply_ats_config(installer) + ReactNativePodsUtils.apply_xcode_15_patch(installer) ReactNativePodsUtils.updateOSDeploymentTarget(installer) ReactNativePodsUtils.set_dynamic_frameworks_flags(installer) ReactNativePodsUtils.add_ndebug_flag_to_pods_in_release(installer)