Skip to content

Commit

Permalink
Use trimmed API key (#1768)
Browse files Browse the repository at this point in the history
### Description
I noticed that trusted entitlements may fail if passing an API key with
extra whitespaces. This is because it's part of the data we are
verifying and the backend uses the trimmed version so there is a
mismatch. This trims the API key we use in the SDK, so it matches what
the backend uses in those cases. Any real API key shouldn't contain any
whitespaces so I think it should be fine but lmk what you think
  • Loading branch information
tonidero authored Jul 3, 2024
1 parent 80781e4 commit f1445f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open class PurchasesConfiguration(builder: Builder) {

init {
this.context = builder.context
this.apiKey = builder.apiKey
this.apiKey = builder.apiKey.trim()
this.appUserID = builder.appUserID
this.purchasesAreCompletedBy = builder.purchasesAreCompletedBy
this.service = builder.service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@ class PurchasesConfigurationTest {
val purchasesConfiguration = builder.dangerousSettings(dangerousSettings).build()
assertThat(purchasesConfiguration.dangerousSettings).isEqualTo(dangerousSettings)
}

@Test
fun `PurchasesConfiguration trims api key`() {
val purchasesConfiguration = PurchasesConfiguration.Builder(context, " test-api-key ").build()
assertThat(purchasesConfiguration.apiKey).isEqualTo("test-api-key")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ class PurchasesFactoryTest {
}

private fun createConfiguration(testApiKey: String = "fakeApiKey"): PurchasesConfiguration {
return mockk<PurchasesConfiguration>().apply {
every { context } returns contextMock
every { apiKey } returns testApiKey
every { appUserID } returns "appUserID"
every { store } returns Store.PLAY_STORE
}
return PurchasesConfiguration.Builder(contextMock, testApiKey)
.appUserID("appUserID")
.store(Store.PLAY_STORE)
.build()
}
}

0 comments on commit f1445f2

Please sign in to comment.