Skip to content

Trusted entitlements: Add internal mechanism to force signing errors for tests#1070

Merged
tonidero merged 4 commits into
mainfrom
toniricodiez/sdk-3182-add-forceverificationerrors-dangerous-setting-for
Jun 19, 2023
Merged

Trusted entitlements: Add internal mechanism to force signing errors for tests#1070
tonidero merged 4 commits into
mainfrom
toniricodiez/sdk-3182-add-forceverificationerrors-dangerous-setting-for

Conversation

@tonidero

Copy link
Copy Markdown
Contributor

Description

SDK-3182

This allows to force signing errors during tests so we can better test the trusted entitlements feature automatically.

@tonidero tonidero added the test label Jun 15, 2023
@tonidero tonidero marked this pull request as ready for review June 15, 2023 09:03
@tonidero tonidero requested a review from a team June 15, 2023 09:03
protected fun simulateSdkRestart(context: Context, forceServerErrors: Boolean = false) {
protected fun simulateSdkRestart(
context: Context,
entitlementVerificationMode: EntitlementVerificationMode? = null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

EntitlementVerificationMode already has DISABLED, so does this need to be null?
Oh I guess it's to be able to determine if it's been explicitly set? It might be useful to have a comment explaining that.
Update: oh just realized this is in tests, so makes sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's pretty much a way to make sure it's explicitly set 👍

@tonidero tonidero requested a review from NachoSoto June 16, 2023 07:11
@tonidero

Copy link
Copy Markdown
Contributor Author

@NachoSoto Applied the suggested changes in #1071 here, since they seemed more related to this PR (I forgot to base the other PR off this branch)

val dangerousSettings: DangerousSettings = DangerousSettings(autoSyncPurchases = true),
// Should only be used for tests
var forceServerErrors: Boolean = false,
private val runningTests: Boolean = false,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was trying to calculate this within AppConfig itself but was getting problems trying to mock these when running unit tests (which don't run in the integrationTest flavor).

@codecov

codecov Bot commented Jun 16, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1070 (f65ee9f) into main (d669a99) will increase coverage by 0.00%.
The diff coverage is 88.88%.

@@           Coverage Diff           @@
##             main    #1070   +/-   ##
=======================================
  Coverage   85.64%   85.64%           
=======================================
  Files         176      176           
  Lines        6247     6263   +16     
  Branches      859      863    +4     
=======================================
+ Hits         5350     5364   +14     
  Misses        563      563           
- Partials      334      336    +2     
Impacted Files Coverage Δ
.../java/com/revenuecat/purchases/common/AppConfig.kt 81.48% <77.77%> (-1.13%) ⬇️
...at/purchases/common/verification/SigningManager.kt 100.00% <100.00%> (ø)
...otlin/com/revenuecat/purchases/PurchasesFactory.kt 84.44% <100.00%> (+0.47%) ⬆️

Comment on lines +22 to +26
// Should only be used for tests
var forceServerErrors: Boolean = forceServerErrors
get() = runningTests && field
var forceSigningErrors: Boolean = forceSigningErrors
get() = runningTests && field

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice

@tonidero tonidero merged commit 6a4d2d1 into main Jun 19, 2023
@tonidero tonidero deleted the toniricodiez/sdk-3182-add-forceverificationerrors-dangerous-setting-for branch June 19, 2023 06:39
tonidero pushed a commit that referenced this pull request Jun 23, 2023
**This is an automatic release.**

### Bugfixes
* Default customer info schema version to latest known by SDK (#1080)
via Toni Rico (@tonidero)
* Handle other diagnostics-related exceptions (#1076) via Toni Rico
(@tonidero)
* Return error in queryPurchases if error connecting to billing client
(#1072) via Toni Rico (@tonidero)
### Other Changes
* Fix offline entitlements integration tests (#1085) via Toni Rico
(@tonidero)
* Add defaultsRelease variant tests run configuration (#1074) via Toni
Rico (@tonidero)
* Compose sample app: move to gradle catalog (#1081) via Toni Rico
(@tonidero)
* Compose sample app: automate builds (#1082) via Toni Rico (@tonidero)
* Compose sample app (#1056) via Toni Rico (@tonidero)
* Migrate to Gradle version catalog (#1059) via Cesar de la Vega
(@vegaro)
* Trusted entitlements: Add logs with verification mode (#1067) via Toni
Rico (@tonidero)
* Sync pending purchases before getting customer info (#1073) via Toni
Rico (@tonidero)
* Refactor syncing pending transactions logic out of `Purchases` (#1058)
via Toni Rico (@tonidero)
* Refactor CustomerInfo listener and cache logic into
CustomerInfoUpdater (#1052) via Toni Rico (@tonidero)
* Trusted entitlements: Add integration tests (#1071) via Toni Rico
(@tonidero)
* Trusted entitlements: Add internal mechanism to force signing errors
for tests (#1070) via Toni Rico (@tonidero)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants