mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
tests for ats settings (#38084)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38084 Changelog: [Internal] addings tests for D47041590 Reviewed By: cipolleschi Differential Revision: D46961587 fbshipit-source-id: 6b93a20c8539d692db2f84836a0ab79d899197fa
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c86f15af30
commit
d320334da8
@@ -114,14 +114,15 @@ class UserProjectMock
|
||||
attr_reader :path
|
||||
attr_reader :build_configurations
|
||||
attr_reader :native_targets
|
||||
attr_reader :files
|
||||
|
||||
attr_reader :save_invocation_count
|
||||
|
||||
|
||||
def initialize(path = "/test/path.xcproj", build_configurations = [], native_targets: [])
|
||||
@path = Pathname.new(path)
|
||||
def initialize(path = "/test/path.xcproj", build_configurations = [], parent = "/test", native_targets: [], files: [])
|
||||
@path = Pathname.new(path, parent)
|
||||
@build_configurations = build_configurations
|
||||
@native_targets = native_targets
|
||||
@files = files
|
||||
@save_invocation_count = 0
|
||||
end
|
||||
|
||||
@@ -130,6 +131,16 @@ class UserProjectMock
|
||||
end
|
||||
end
|
||||
|
||||
class PBXFileRefMock
|
||||
attr_reader :name
|
||||
attr_reader :path
|
||||
|
||||
def initialize(name)
|
||||
@name = name
|
||||
@path = name
|
||||
end
|
||||
end
|
||||
|
||||
class XCConfigMock
|
||||
attr_reader :name
|
||||
attr_accessor :attributes
|
||||
|
||||
@@ -9,8 +9,9 @@ class Pathname
|
||||
|
||||
attr_reader :path
|
||||
|
||||
def initialize(path)
|
||||
def initialize(path, parent = "")
|
||||
@path = path
|
||||
@parent = parent
|
||||
end
|
||||
|
||||
def realpath
|
||||
@@ -21,6 +22,10 @@ class Pathname
|
||||
return @path
|
||||
end
|
||||
|
||||
def parent
|
||||
return @parent
|
||||
end
|
||||
|
||||
def self.pwd!(pwd)
|
||||
@@pwd = pwd
|
||||
end
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
module Xcodeproj
|
||||
class Plist
|
||||
@@path_to_file_mapping = Hash.new
|
||||
def self.read_from_path(path)
|
||||
return @@path_to_file_mapping[path]
|
||||
end
|
||||
|
||||
def self.write_to_path(hash, path)
|
||||
@@path_to_file_mapping[path] = hash
|
||||
end
|
||||
|
||||
def self.reset()
|
||||
@@path_to_file_mapping.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -14,6 +14,7 @@ require_relative "./test_utils/FileMock.rb"
|
||||
require_relative "./test_utils/systemUtils.rb"
|
||||
require_relative "./test_utils/PathnameMock.rb"
|
||||
require_relative "./test_utils/TargetDefinitionMock.rb"
|
||||
require_relative "./test_utils/XcodeprojMock.rb"
|
||||
|
||||
class UtilsTests < Test::Unit::TestCase
|
||||
def setup
|
||||
@@ -28,6 +29,7 @@ class UtilsTests < Test::Unit::TestCase
|
||||
Pod::Config.reset()
|
||||
SysctlChecker.reset()
|
||||
Environment.reset()
|
||||
Xcodeproj::Plist.reset()
|
||||
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
|
||||
ENV['USE_HERMES'] = '1'
|
||||
ENV['USE_FRAMEWORKS'] = nil
|
||||
@@ -772,6 +774,59 @@ class UtilsTests < Test::Unit::TestCase
|
||||
assert_equal(config.build_settings["OTHER_CFLAGS"], "$(inherited)")
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
# ===== #
|
||||
@@ -785,6 +840,13 @@ def prepare_empty_user_project_mock
|
||||
])
|
||||
end
|
||||
|
||||
def prepare_user_project_mock_with_plists
|
||||
return UserProjectMock.new(:files => [
|
||||
PBXFileRefMock.new("Info.plist"),
|
||||
PBXFileRefMock.new("Extension-Info.plist"),
|
||||
])
|
||||
end
|
||||
|
||||
def prepare_config(config_name)
|
||||
return BuildConfigurationMock.new(config_name, {"LIBRARY_SEARCH_PATHS" => [
|
||||
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)",
|
||||
|
||||
Reference in New Issue
Block a user