Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let package = Package(
.package(url: "https://github.com/wordpress-mobile/FSInteractiveMap", from: "0.3.0"),
.package(url: "https://github.com/wordpress-mobile/MediaEditor-iOS", branch: "task/spm-support"),
.package(url: "https://github.com/wordpress-mobile/NSObject-SafeExpectations", from: "0.0.6"),
.package(url: "https://github.com/wordpress-mobile/wpxmlrpc", from: "0.9.0"),
.package(url: "https://github.com/wordpress-mobile/NSURL-IDN", revision: "b34794c9a3f32312e1593d4a3d120572afa0d010"),
.package(
url: "https://github.com/wordpress-mobile/WordPressKit-iOS",
Expand Down Expand Up @@ -221,6 +222,7 @@ enum XcodeSupport {
.library(name: "XcodeTarget_App", targets: ["XcodeTarget_App"]),
.library(name: "XcodeTarget_Keystone", targets: ["XcodeTarget_Keystone"]),
.library(name: "XcodeTarget_WordPressTests", targets: ["XcodeTarget_WordPressTests"]),
.library(name: "XcodeTarget_WordPressKitTests", targets: ["XcodeTarget_WordPressKitTests"]),
.library(name: "XcodeTarget_WordPressData", targets: ["XcodeTarget_WordPressData"]),
.library(name: "XcodeTarget_WordPressAuthentificator", targets: ["XcodeTarget_WordPressAuthentificator"]),
.library(name: "XcodeTarget_WordPressAuthentificatorTests", targets: ["XcodeTarget_WordPressAuthentificatorTests"]),
Expand Down Expand Up @@ -350,6 +352,10 @@ enum XcodeSupport {
.product(name: "WordPressAPI", package: "wordpress-rs"),
.product(name: "WordPressKit", package: "WordPressKit-iOS"),
]),
.xcodeTarget("XcodeTarget_WordPressKitTests", dependencies: testDependencies + [
"wpxmlrpc",
.product(name: "WordPressKit", package: "WordPressKit-iOS"),
]),
.xcodeTarget("XcodeTarget_WordPressAuthentificator", dependencies: wordPresAuthentificatorDependencies),
.xcodeTarget("XcodeTarget_WordPressAuthentificatorTests", dependencies: wordPresAuthentificatorDependencies + testDependencies),
.xcodeTarget("XcodeTarget_ShareExtension", dependencies: shareAndDraftExtensionsDependencies),
Expand Down
39 changes: 23 additions & 16 deletions Tests/KeystoneTests/WordPressUnitTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,8 @@
{
"target" : {
"containerPath" : "container:..\/Modules",
"identifier" : "AsyncImageKitTests",
"name" : "AsyncImageKitTests"
}
},
{
"target" : {
"containerPath" : "container:WordPress.xcodeproj",
"identifier" : "4AD953BA2C21451700D0EEFA",
"name" : "WordPressAuthenticatorTests"
"identifier" : "WordPressFluxTests",
"name" : "WordPressFluxTests"
}
},
{
Expand All @@ -62,15 +55,15 @@
{
"target" : {
"containerPath" : "container:..\/Modules",
"identifier" : "WordPressUIUnitTests",
"name" : "WordPressUIUnitTests"
"identifier" : "WordPressSharedTests",
"name" : "WordPressSharedTests"
}
},
{
"target" : {
"containerPath" : "container:..\/Modules",
"identifier" : "WordPressSharedTests",
"name" : "WordPressSharedTests"
"containerPath" : "container:WordPress.xcodeproj",
"identifier" : "4A8280FC2E5FE9B60037E180",
"name" : "WordPressKitTests"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the new test target to the existing test plan file. I guess Xcode did not care about the order of the target which made the diff pretty difficult to review.

}
},
{
Expand All @@ -80,11 +73,18 @@
"name" : "JetpackStatsWidgetsCoreTests"
}
},
{
"target" : {
"containerPath" : "container:WordPress.xcodeproj",
"identifier" : "4AD953BA2C21451700D0EEFA",
"name" : "WordPressAuthenticatorTests"
}
},
{
"target" : {
"containerPath" : "container:..\/Modules",
"identifier" : "WordPressFluxTests",
"name" : "WordPressFluxTests"
"identifier" : "WordPressUIUnitTests",
"name" : "WordPressUIUnitTests"
}
},
{
Expand All @@ -93,6 +93,13 @@
"identifier" : "WordPressSharedObjCTests",
"name" : "WordPressSharedObjCTests"
}
},
{
"target" : {
"containerPath" : "container:..\/Modules",
"identifier" : "AsyncImageKitTests",
"name" : "AsyncImageKitTests"
}
}
],
"version" : 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import XCTest
#if SWIFT_PACKAGE
@testable import CoreAPI
#else
@testable import WordPressKit
#endif

final class AppTransportSecuritySettingsTests: XCTestCase {

private var exampleURL = URL(string: "https://example.com")!

func testReturnsTrueIfAllowsLocalNetworkingIsTrue() throws {
// Given
let provider = FakeInfoDictionaryObjectProvider(appTransportSecurity: [
"NSAllowsLocalNetworking": true,
// This will be ignored
"NSAllowsArbitraryLoads": true
])
let appTransportSecurity = AppTransportSecuritySettings(provider)

// When
let secureAccessOnly = appTransportSecurity.secureAccessOnly(for: exampleURL)

// Then
XCTAssertTrue(secureAccessOnly)
}

func testReturnsFalseIfAllowsArbitraryLoadsIsTrue() throws {
// Given
let provider = FakeInfoDictionaryObjectProvider(appTransportSecurity: [
"NSAllowsArbitraryLoads": true
])
let appTransportSecurity = AppTransportSecuritySettings(provider)

// When
let secureAccessOnly = appTransportSecurity.secureAccessOnly(for: exampleURL)

// Then
XCTAssertFalse(secureAccessOnly)
}

func testReturnsTrueByDefault() throws {
// Given
let provider = FakeInfoDictionaryObjectProvider(appTransportSecurity: nil)
let appTransportSecurity = AppTransportSecuritySettings(provider)

// When
let secureAccessOnly = appTransportSecurity.secureAccessOnly(for: exampleURL)

// Then
XCTAssertTrue(secureAccessOnly)
}

func testReturnsTrueIfNothingIsDefined() throws {
// Given
let provider = FakeInfoDictionaryObjectProvider(appTransportSecurity: [String: Any]())
let appTransportSecurity = AppTransportSecuritySettings(provider)

// When
let secureAccessOnly = appTransportSecurity.secureAccessOnly(for: exampleURL)

// Then
XCTAssertTrue(secureAccessOnly)
}

func testReturnsFalseIfAllowsInsecureHTTPLoadsIsTrue() throws {
// Given
let provider = FakeInfoDictionaryObjectProvider(appTransportSecurity: [
"NSExceptionDomains": [
"shiki.me": [
"NSExceptionAllowsInsecureHTTPLoads": true
]
]
])
let appTransportSecurity = AppTransportSecuritySettings(provider)
let url = try XCTUnwrap(URL(string: "http://shiki.me"))

// When
let secureAccessOnly = appTransportSecurity.secureAccessOnly(for: url)

// Then
XCTAssertFalse(secureAccessOnly)
}

func testReturnsTrueIfAllowsInsecureHTTPLoadsIsNotProvided() throws {
// Given
let provider = FakeInfoDictionaryObjectProvider(appTransportSecurity: [
"NSExceptionDomains": [
"shiki.me": [String: Any]()
],
// This value will be ignored because there is an exception for shiki.me
"NSAllowsArbitraryLoads": true
])
let appTransportSecurity = AppTransportSecuritySettings(provider)
let url = try XCTUnwrap(URL(string: "http://shiki.me"))

// When
let secureAccessOnly = appTransportSecurity.secureAccessOnly(for: url)

// Then
XCTAssertTrue(secureAccessOnly)
}
}
25 changes: 25 additions & 0 deletions Tests/WordPressKitTests/CoreAPITests/Bundle+SPMSupport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

extension Bundle {
/// Returns the `Bundle` for the target.
///
/// If installed via CocoaPods, this will be `<target_name>.bundle`, otherwise it will be the framework bundle.
@objc public class var coreAPITestsBundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
let defaultBundle = Bundle(for: BundleFinder.self)

guard let bundleURL = defaultBundle.resourceURL,
let resourceBundle = Bundle(url: bundleURL.appendingPathComponent("CoreAPITests.bundle")) else {
return defaultBundle
}

return resourceBundle
#endif
}
}

#if !SWIFT_PACKAGE
private class BundleFinder: NSObject {}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#if SWIFT_PACKAGE
@testable import CoreAPI
#else
@testable import WordPressKit
#endif

class FakeInfoDictionaryObjectProvider: InfoDictionaryObjectProvider {
private let appTransportSecurity: [String: Any]?

init(appTransportSecurity: [String: Any]?) {
self.appTransportSecurity = appTransportSecurity
}

func object(forInfoDictionaryKey key: String) -> Any? {
if key == "NSAppTransportSecurity" {
return appTransportSecurity
}

return nil
}
}
Loading