Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash cache & UIPasteBoard tests updates #686

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nodes with values to reuse in the pipeline.
common_params:
plugins: &common_plugins
- automattic/bash-cache#2.8.0
- automattic/bash-cache#2.9.0
env: &common_env
IMAGE_ID: xcode-14

Expand Down
46 changes: 28 additions & 18 deletions WordPressAuthenticatorTests/Authenticator/PasteboardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,62 @@ class PasteboardTests: XCTestCase {
}

func testNominalAuthCode() throws {
if #available(iOS 16.0, *) {
throw XCTSkip("UIPasteboard doesn't work in iOS 16.0.") // Check https://github.com/wordpress-mobile/WordPressAuthenticator-iOS/issues/696
}

guard #available(iOS 14.0, *) else {
throw XCTSkip("Unsupported iOS version")
}

// FIXME: We'll need to find a way to make the test work the new pasteboard rules
//
// See:
// - https://developer.apple.com/forums/thread/713770
// - https://sarunw.com/posts/uipasteboard-privacy-change-ios16/
// - https://github.com/wordpress-mobile/WordPressAuthenticator-iOS/issues/696
XCTExpectFailure("Paste board access has changed in iOS 16 and this test is now failing")

Comment on lines +17 to +24
Copy link
Contributor

@AliSoftware AliSoftware Nov 7, 2022

Choose a reason for hiding this comment

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

What if we happen to run the Unit Tests using an iPhone Simulator that runs iOS 15.4 or older? Shouldn't we guard this against the iOS runtime version?

Probably with something like this:

Suggested change
// FIXME: We'll need to find a way to make the test work the new pasteboard rules
//
// See:
// - https://developer.apple.com/forums/thread/713770
// - https://sarunw.com/posts/uipasteboard-privacy-change-ios16/
// - https://github.com/wordpress-mobile/WordPressAuthenticator-iOS/issues/696
XCTExpectFailure("Paste board access has changed in iOS 16 and this test is now failing")
// FIXME: We'll need to find a way to make the test work the new pasteboard rules
//
// See:
// - https://developer.apple.com/forums/thread/713770
// - https://sarunw.com/posts/uipasteboard-privacy-change-ios16/
// - https://github.com/wordpress-mobile/WordPressAuthenticator-iOS/issues/696
if ProcessInfo.processInfo.isOperatingSystemAtLeast(.init(majorVersion: 16, minorVersion: 0, patchVersion: 0)) {
XCTExpectFailure("Pasteboard access has changed in iOS 16 and this test is now failing")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Confirmed this is needed, by testing on an iOS 15.4 simulator 😉
image

Copy link
Contributor Author

@mokagio mokagio Nov 8, 2022

Choose a reason for hiding this comment

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

Neat technique.

But do we really need it? Yes, the tests will fail on iOS < 16, but how much of a concern is that for us? What are the chances we'll need to run the tests in iOS < 16?

Thinking about it, it might be beneficial if the UIPasteboard changes are such that we'll need different code between iOS < 16 and >= 16. 🤔 I haven't looked at that yet, this might be a good time to do so.

let expect = expectation(description: "Could read nominal auth code from pasteboard")
let pasteboard = UIPasteboard.general
pasteboard.string = "123456"

UIPasteboard.general.detectAuthenticatorCode { result in
switch result {
case .success(let authenticationCode):
XCTAssertEqual(authenticationCode, "123456")
case .failure:
XCTAssert(false)
case .success(let authenticationCode):
XCTAssertEqual(authenticationCode, "123456")
expect.fulfill()
case .failure:
// Do nothing, by not fulfilling the expectation, the test will fail.
return
}
expect.fulfill()
}

waitForExpectations(timeout: timeout, handler: nil)
}

func testLeadingZeroInAuthCodePreserved() throws {
if #available(iOS 16.0, *) {
throw XCTSkip("UIPasteboard doesn't work in iOS 16.0.") // Check https://github.com/wordpress-mobile/WordPressAuthenticator-iOS/issues/696
}

guard #available(iOS 14.0, *) else {
throw XCTSkip("Unsupported iOS version")
}

// FIXME: We'll need to find a way to make the test work the new pasteboard rules
//
// See:
// - https://developer.apple.com/forums/thread/713770
// - https://sarunw.com/posts/uipasteboard-privacy-change-ios16/
// - https://github.com/wordpress-mobile/WordPressAuthenticator-iOS/issues/696
XCTExpectFailure("Paste board access has changed in iOS 16 and this test is now failing")

let expect = expectation(description: "Could read leading zero auth code from pasteboard")
let pasteboard = UIPasteboard.general
pasteboard.string = "012345"

UIPasteboard.general.detectAuthenticatorCode { result in
switch result {
case .success(let authenticationCode):
XCTAssertEqual(authenticationCode, "012345")
case .failure:
XCTAssert(false)
case .success(let authenticationCode):
XCTAssertEqual(authenticationCode, "012345")
expect.fulfill()
case .failure:
// Do nothing, by not fulfilling the expectation, the test will fail.
return
}
expect.fulfill()
}

waitForExpectations(timeout: timeout, handler: nil)
Expand Down