Skip to content

Commit 2b5150e

Browse files
committed
wda: add USE_IP env var to override what IP to bind to for multi-simulator scenarios
Signed-off-by: Karl Baumgartner <178656887+karlbaumg@users.noreply.github.com>
1 parent e81e614 commit 2b5150e

6 files changed

Lines changed: 45 additions & 0 deletions

File tree

WebDriverAgent.xcodeproj/xcshareddata/xcschemes/WebDriverAgentRunner.xcscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
value = "$(USE_PORT)"
6767
isEnabled = "YES">
6868
</EnvironmentVariable>
69+
<EnvironmentVariable
70+
key = "USE_IP"
71+
value = "$(USE_IP)"
72+
isEnabled = "YES">
73+
</EnvironmentVariable>
6974
<EnvironmentVariable
7075
key = "UPGRADE_TIMESTAMP"
7176
value = "$(UPGRADE_TIMESTAMP)"

WebDriverAgent.xcodeproj/xcshareddata/xcschemes/WebDriverAgentRunner_tvOS.xcscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
value = "$(USE_PORT)"
7676
isEnabled = "YES">
7777
</EnvironmentVariable>
78+
<EnvironmentVariable
79+
key = "USE_IP"
80+
value = "$(USE_IP)"
81+
isEnabled = "YES">
82+
</EnvironmentVariable>
7883
<EnvironmentVariable
7984
key = "UPGRADE_TIMESTAMP"
8085
value = "$(UPGRADE_TIMESTAMP)"

WebDriverAgentLib/Routing/FBWebServer.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ - (void)startHTTPServer
9292
[self registerServerKeyRouteHandlers];
9393

9494
NSRange serverPortRange = FBConfiguration.bindingPortRange;
95+
NSString *bindingIP = FBConfiguration.bindingIPAddress;
96+
if (bindingIP != nil) {
97+
[self.server setInterface:bindingIP];
98+
[FBLogger logFmt:@"Using custom binding IP address: %@", bindingIP];
99+
}
100+
95101
NSError *error;
96102
BOOL serverStarted = NO;
97103

WebDriverAgentLib/Utilities/FBConfiguration.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ extern NSString *const FBSnapshotMaxDepthKey;
124124
*/
125125
+ (NSRange)bindingPortRange;
126126

127+
/**
128+
The IP address that the HTTP Server should bind to on launch.
129+
Returns nil if not specified, which causes the server to listen on all interfaces.
130+
*/
131+
+ (NSString * _Nullable)bindingIPAddress;
132+
127133
/**
128134
The port number where the background screenshots broadcaster is supposed to run
129135
*/

WebDriverAgentLib/Utilities/FBConfiguration.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ + (NSRange)bindingPortRange
137137
return NSMakeRange(DefaultStartingPort, DefaultPortRange);
138138
}
139139

140+
+ (NSString *)bindingIPAddress
141+
{
142+
// Existence of USE_IP in the environment allows specifying which interface to bind to
143+
if (NSProcessInfo.processInfo.environment[@"USE_IP"] &&
144+
[NSProcessInfo.processInfo.environment[@"USE_IP"] length] > 0) {
145+
return NSProcessInfo.processInfo.environment[@"USE_IP"];
146+
}
147+
148+
return nil;
149+
}
150+
140151
+ (NSInteger)mjpegServerPort
141152
{
142153
if (self.mjpegServerPortFromArguments != NSNotFound) {

WebDriverAgentTests/UnitTests/FBConfigurationTests.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ - (void)setUp
2020
{
2121
[super setUp];
2222
unsetenv("USE_PORT");
23+
unsetenv("USE_IP");
2324
unsetenv("VERBOSE_LOGGING");
2425
}
2526

@@ -45,4 +46,15 @@ - (void)testVerboseLoggingEnvironmentOverwrite
4546
XCTAssertTrue([FBConfiguration verboseLoggingEnabled]);
4647
}
4748

49+
- (void)testBindingIPDefault
50+
{
51+
XCTAssertNil([FBConfiguration bindingIPAddress]);
52+
}
53+
54+
- (void)testBindingIPEnvironmentOverwrite
55+
{
56+
setenv("USE_IP", "192.168.1.100", 1);
57+
XCTAssertEqualObjects([FBConfiguration bindingIPAddress], @"192.168.1.100");
58+
}
59+
4860
@end

0 commit comments

Comments
 (0)