Skip to content

Commit

Permalink
Use trimmed API key
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero committed Jul 1, 2024
1 parent b5bc297 commit 3b1609a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ open class PurchasesConfiguration(builder: Builder) {
val apiKey: String
val appUserID: String?

internal val trimmedApiKey: String
get() = apiKey.trim()

@Deprecated(
"observerMode is being deprecated in favor of purchasesAreCompletedBy.",
ReplaceWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ internal class PurchasesFactory(
val signatureVerificationMode = SignatureVerificationMode.fromEntitlementVerificationMode(
verificationMode,
)
val signingManager = SigningManager(signatureVerificationMode, appConfig, apiKey)
val signingManager = SigningManager(signatureVerificationMode, appConfig, trimmedApiKey)

val cache = DeviceCache(prefs, apiKey)
val cache = DeviceCache(prefs, trimmedApiKey)

val httpClient = HTTPClient(appConfig, eTagManager, diagnosticsTracker, signingManager, cache)
val backendHelper = BackendHelper(apiKey, backendDispatcher, appConfig, httpClient)
val backendHelper = BackendHelper(trimmedApiKey, backendDispatcher, appConfig, httpClient)
val backend = Backend(
appConfig,
backendDispatcher,
Expand Down Expand Up @@ -324,11 +324,11 @@ internal class PurchasesFactory(
"Purchases requires INTERNET permission."
}

require(apiKey.isNotBlank()) { "API key must be set. Get this from the RevenueCat web app" }
require(trimmedApiKey.isNotBlank()) { "API key must be set. Get this from the RevenueCat web app" }

require(context.applicationContext is Application) { "Needs an application context." }

apiKeyValidator.validateAndLog(apiKey, store)
apiKeyValidator.validateAndLog(trimmedApiKey, store)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,11 @@ class PurchasesConfigurationTest {
val purchasesConfiguration = builder.dangerousSettings(dangerousSettings).build()
assertThat(purchasesConfiguration.dangerousSettings).isEqualTo(dangerousSettings)
}

@Test
fun `PurchasesConfiguration trimmedApiKey has correct value`() {
val purchasesConfiguration = PurchasesConfiguration.Builder(context, " test-api-key ").build()
assertThat(purchasesConfiguration.apiKey).isEqualTo(" test-api-key ")
assertThat(purchasesConfiguration.trimmedApiKey).isEqualTo("test-api-key")
}
}

0 comments on commit 3b1609a

Please sign in to comment.