mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-03-06 00:00:02 +08:00
Add port property and test get/set its value
This commit is contained in:
@@ -43,6 +43,12 @@ typedef NS_ENUM(NSInteger, OpenVPNTLSCertProfile);
|
||||
*/
|
||||
@property (nullable, nonatomic) NSString *server;
|
||||
|
||||
/**
|
||||
Use a different port than that specified in "remote"
|
||||
option of profile
|
||||
*/
|
||||
@property (nonatomic) NSUInteger port;
|
||||
|
||||
/**
|
||||
Force a given transport protocol
|
||||
*/
|
||||
|
||||
@@ -268,6 +268,18 @@ NSString *const OpenVPNTLSCertProfileDefaultValue = @"default";
|
||||
_config.serverOverride = serverOverride ? std::string([serverOverride UTF8String]) : "";
|
||||
}
|
||||
|
||||
- (NSUInteger)port {
|
||||
try {
|
||||
return std::stoul(_config.portOverride, NULL);
|
||||
} catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setPort:(NSUInteger)port {
|
||||
_config.portOverride = std::to_string(port);
|
||||
}
|
||||
|
||||
- (OpenVPNTransportProtocol)proto {
|
||||
NSString *currentValue = [NSString stringWithUTF8String:_config.protoOverride.c_str()];
|
||||
return [OpenVPNConfiguration getTransportProtocolFromValue:currentValue];
|
||||
|
||||
@@ -82,6 +82,26 @@ class OpenVPNConfigurationTests: XCTestCase {
|
||||
XCTAssert(configuration.settings == nil, "Empty settings should return nil")
|
||||
}
|
||||
|
||||
func testGetSetRemote() {
|
||||
guard let originalProfile = VPNProfile.configuration.data(using: .utf8) else { fatalError() }
|
||||
|
||||
let originalServer = "192.168.1.200"
|
||||
let originalPort: UInt = 12000
|
||||
|
||||
let configuration = OpenVPNConfiguration()
|
||||
configuration.fileContent = originalProfile
|
||||
|
||||
XCTAssertNil(configuration.server)
|
||||
XCTAssertEqual(configuration.port, 0)
|
||||
|
||||
configuration.server = originalServer
|
||||
configuration.port = originalPort
|
||||
|
||||
XCTAssertNotNil(configuration.server)
|
||||
XCTAssertEqual(configuration.server, originalServer)
|
||||
XCTAssertEqual(configuration.port, originalPort)
|
||||
}
|
||||
|
||||
func testGetSetProto() {
|
||||
let originalOption: OpenVPNTransportProtocol = .UDP
|
||||
|
||||
|
||||
Reference in New Issue
Block a user