Skip to content

Commit

Permalink
validating credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
czechboy0 committed Oct 4, 2015
1 parent 2b5da49 commit 10fc0c4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 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"
Expand Down
6 changes: 6 additions & 0 deletions XcodeServerSDK/XcodeServerConfig.swift
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions XcodeServerSDKTests/XcodeServerConfigTests.swift
Expand Up @@ -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")
Expand Down

0 comments on commit 10fc0c4

Please sign in to comment.