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

Purchases.configure: log warning if attempting to use a static appUserID #2385

Merged
merged 6 commits into from
Mar 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/Purchasing/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,18 @@ import Foundation
*
* - Important: Set this property if you have your own user identifiers that you manage.
*/
@_disfavoredOverload
@objc public func with(appUserID: String?) -> Builder {
self.appUserID = appUserID
return self
}

// swiftlint:disable:next missing_docs
public func with(appUserID: StaticString) -> Configuration.Builder {
Logger.warn(Strings.identity.logging_in_with_static_string)
return self.with(appUserID: "\(appUserID)")
}

/**
* Set `observerMode`.
* - Parameter observerMode: Set this to `true` if you have your own IAP implementation and want to use only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ class PurchasesConfiguringTests: BasePurchasesTests {
expect(purchases.appUserID) == Self.appUserID
}

func testStaticUserIdSringLogsMessage() {
let logger = TestLogHandler()

_ = Purchases.configure(
with: .init(withAPIKey: "")
.with(appUserID: "Static string")
)

logger.verifyMessageWasLogged(Strings.identity.logging_in_with_static_string)
}

func testUserIdSringDoesNotLogMessage() {
let appUserID = "user ID"
let logger = TestLogHandler()

_ = Purchases.configure(
with: .init(withAPIKey: "")
.with(appUserID: appUserID)
)

logger.verifyMessageWasNotLogged(Strings.identity.logging_in_with_static_string)
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
func testEntitlementVerificationModeDisabledDoesNotSetPublicKey() throws {
try AvailabilityChecks.iOS13APIAvailableOrSkipTest()
Expand Down