Skip to content

Commit

Permalink
Remove ATS config patch from react_native_post_install (#42637)
Browse files Browse the repository at this point in the history
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: #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
  • Loading branch information
gabrieldonadel authored and facebook-github-bot committed Jan 25, 2024
1 parent f4dbd15 commit 41c601e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 91 deletions.
52 changes: 0 additions & 52 deletions packages/react-native/scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
# =============================================== #
Expand Down
37 changes: 0 additions & 37 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native/scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 41c601e

Please sign in to comment.