Skip to content

Commit bc679dc

Browse files
authored
[#794] 배포 환경별 API 주소 검증 정책을 분리한다 (#796)
chore: 배포 환경별 API 주소 검증 정책 분리
1 parent adff530 commit bc679dc

3 files changed

Lines changed: 82 additions & 15 deletions

File tree

fastlane/Fastfile

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative "function_api_base_url_policy"
2+
13
XCODE_WORKSPACE = "DevLog.xcworkspace"
24
XCODE_PROJ = "Application/App/App.xcodeproj"
35
WIDGET_XCODE_PROJ = "Widget/WidgetExtension/WidgetExtension.xcodeproj"
@@ -13,7 +15,8 @@ TESTFLIGHT_APP_ENVIRONMENT = "staging"
1315
APPSTORE_APP_ENVIRONMENT = "prod"
1416
TESTFLIGHT_DATABASE_ID = "(default)"
1517
APPSTORE_DATABASE_ID = "(default)"
16-
SHARED_FUNCTION_API_PATH = "/api/api"
18+
TESTFLIGHT_FUNCTION_API_PATH = "/api"
19+
APPSTORE_FUNCTION_API_PATH = "/api/api"
1720
APP_CONFIG_XCCONFIG_PATH = File.expand_path(
1821
"../Application/App/Sources/Resource/Config.xcconfig",
1922
__dir__
@@ -114,19 +117,13 @@ rescue SystemCallError => error
114117
UI.user_error!("Could not read app configuration file at #{expanded_path}: #{error.message}")
115118
end
116119

117-
def verify_function_api_base_url_policy(function_api_base_url)
118-
require "uri"
119-
120-
uri = URI.parse(function_api_base_url)
121-
is_valid = uri.is_a?(URI::HTTPS) &&
122-
!uri.host.to_s.empty? &&
123-
uri.path == SHARED_FUNCTION_API_PATH &&
124-
uri.query.nil? &&
125-
uri.fragment.nil?
120+
def verify_function_api_base_url_policy(function_api_base_url, expected_path:)
121+
is_valid = FunctionAPIBaseURLPolicy.valid?(
122+
function_api_base_url,
123+
expected_path: expected_path
124+
)
126125

127126
UI.user_error!("Invalid FUNCTION_API_BASE_URL for store build") if !is_valid
128-
rescue URI::InvalidURIError
129-
UI.user_error!("Invalid FUNCTION_API_BASE_URL for store build")
130127
end
131128

132129
default_platform(:ios)
@@ -180,12 +177,14 @@ platform :ios do
180177
when TESTFLIGHT_CONFIGURATION
181178
{
182179
database_id: TESTFLIGHT_DATABASE_ID,
183-
function_api_base_url: function_api_base_url_from_xcconfig(TESTFLIGHT_CONFIGURATION)
180+
function_api_base_url: function_api_base_url_from_xcconfig(TESTFLIGHT_CONFIGURATION),
181+
function_api_path: TESTFLIGHT_FUNCTION_API_PATH
184182
}
185183
when APPSTORE_CONFIGURATION
186184
{
187185
database_id: APPSTORE_DATABASE_ID,
188-
function_api_base_url: function_api_base_url_from_xcconfig(APPSTORE_CONFIGURATION)
186+
function_api_base_url: function_api_base_url_from_xcconfig(APPSTORE_CONFIGURATION),
187+
function_api_path: APPSTORE_FUNCTION_API_PATH
189188
}
190189
else
191190
UI.user_error!("Unsupported store configuration: #{configuration}")
@@ -194,7 +193,10 @@ platform :ios do
194193
UI.user_error!("Missing Firestore database ID for #{configuration}") if database_id.empty?
195194
UI.user_error!("Missing Function API base URL for #{configuration}") if function_api_base_url.empty?
196195

197-
verify_function_api_base_url_policy(function_api_base_url)
196+
verify_function_api_base_url_policy(
197+
function_api_base_url,
198+
expected_path: expected_configuration[:function_api_path]
199+
)
198200

199201
if database_id != expected_configuration[:database_id]
200202
UI.user_error!(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require "uri"
4+
5+
module FunctionAPIBaseURLPolicy
6+
module_function
7+
8+
def valid?(function_api_base_url, expected_path:)
9+
uri = URI.parse(function_api_base_url)
10+
11+
uri.is_a?(URI::HTTPS) &&
12+
!uri.host.to_s.empty? &&
13+
uri.path == expected_path &&
14+
uri.query.nil? &&
15+
uri.fragment.nil?
16+
rescue URI::InvalidURIError
17+
false
18+
end
19+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../function_api_base_url_policy"
4+
5+
def assert_policy(function_api_base_url, expected_path:, expected:)
6+
actual = FunctionAPIBaseURLPolicy.valid?(
7+
function_api_base_url,
8+
expected_path: expected_path
9+
)
10+
return if actual == expected
11+
12+
raise "Expected #{function_api_base_url.inspect} with #{expected_path.inspect} to be #{expected}, got #{actual}"
13+
end
14+
15+
valid_cases = [
16+
["https://example.com/api", "/api"],
17+
["https://example.com/api/api", "/api/api"]
18+
]
19+
20+
invalid_cases = [
21+
["https://example.com/api/api", "/api"],
22+
["https://example.com/api", "/api/api"],
23+
["http://example.com/api", "/api"],
24+
["https:///api", "/api"],
25+
["https://example.com/api?source=testflight", "/api"],
26+
["https://example.com/api#fragment", "/api"],
27+
["https://example .com/api", "/api"]
28+
]
29+
30+
valid_cases.each do |function_api_base_url, expected_path|
31+
assert_policy(
32+
function_api_base_url,
33+
expected_path: expected_path,
34+
expected: true
35+
)
36+
end
37+
38+
invalid_cases.each do |function_api_base_url, expected_path|
39+
assert_policy(
40+
function_api_base_url,
41+
expected_path: expected_path,
42+
expected: false
43+
)
44+
end
45+
46+
puts "FunctionAPIBaseURLPolicy: #{valid_cases.count + invalid_cases.count} checks passed"

0 commit comments

Comments
 (0)