diff --git a/XcodeServerSDK.podspec b/XcodeServerSDK.podspec index e62b6b9..8c8d9cb 100644 --- a/XcodeServerSDK.podspec +++ b/XcodeServerSDK.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "XcodeServerSDK" - s.version = "0.3.6" + s.version = "0.3.7" s.summary = "Access Xcode Server API with native Swift objects." s.homepage = "https://github.com/czechboy0/XcodeServerSDK" diff --git a/XcodeServerSDK/XcodeServerConfig.swift b/XcodeServerSDK/XcodeServerConfig.swift index 4c2f4f0..19fb92a 100644 --- a/XcodeServerSDK/XcodeServerConfig.swift +++ b/XcodeServerSDK/XcodeServerConfig.swift @@ -17,6 +17,8 @@ public enum ConfigurationErrors : ErrorType { case InvalidHostProvided(String) /// Thrown when a host is provided with an invalid scheme (explanation message returned) case InvalidSchemeProvided(String) + /// Thrown when only one of (username, password) is provided, which is not valid + case InvalidCredentialsProvided } private struct Keys { @@ -87,6 +89,10 @@ public struct XcodeServerConfig : JSONSerializable { throw ConfigurationErrors.InvalidSchemeProvided(errMsg) } + guard user?.isEmpty == password?.isEmpty else { + throw ConfigurationErrors.InvalidCredentialsProvided + } + // validate if host is a valid URL if url.scheme.isEmpty { // exted host with https scheme diff --git a/XcodeServerSDKTests/XcodeServerConfigTests.swift b/XcodeServerSDKTests/XcodeServerConfigTests.swift index ba9bb7c..10bed80 100644 --- a/XcodeServerSDKTests/XcodeServerConfigTests.swift +++ b/XcodeServerSDKTests/XcodeServerConfigTests.swift @@ -22,6 +22,18 @@ class XcodeServerConfigTests: XCTestCase { } } + func testInvalidCredentials_MissingPassword() { + XCTempAssertThrowsSpecificError(ConfigurationErrors.InvalidCredentialsProvided) { + _ = try XcodeServerConfig(host: "127.0.0.1", user: "ICanCreateBots", password: nil) + } + } + + func testInvalidCredentials_MissingUsername() { + XCTempAssertThrowsSpecificError(ConfigurationErrors.InvalidCredentialsProvided) { + _ = try XcodeServerConfig(host: "127.0.0.1", user: "", password: "hello") + } + } + func testInvalidHostProvidingForManualInit() { XCTempAssertThrowsSpecificError(ConfigurationErrors.InvalidHostProvided("Invalid host name provided, please double check your host name")) { _ = try XcodeServerConfig(host: "<>127.0.0.1", user: "ICanCreateBots", password: "superSecr3t")