Skip to content

Conversation

@xavimolloy
Copy link
Collaborator

Description

Link the JIRA issue.

Please provide a clear definition of the problem and explain your solution.

@xavimolloy xavimolloy force-pushed the ANDROAPP-7393 branch 2 times, most recently from 08c505a to fe6cc60 Compare November 24, 2025 11:59
Base automatically changed from ANDROAPP-7393 to release/3.3.0-RC November 24, 2025 12:36
@sonarqubecloud
Copy link

@xavimolloy xavimolloy changed the base branch from release/3.3.0-RC to develop December 2, 2025 09:06
Copilot AI review requested due to automatic review settings December 2, 2025 09:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive test coverage for the OpenIdLogin use case, implementing 15 test cases that verify various scenarios of OpenID authentication including success cases, failure cases, edge cases with different parameter values, and the critical biometric credentials deletion logic based on account count.

Key Changes:

  • New test file with 15 test cases covering OpenIdLogin functionality
  • Tests verify biometric credential deletion logic based on number of existing accounts
  • Tests cover edge cases including offline mode, custom redirect URIs, different server URL formats, and special characters in usernames

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines +294 to +338
@Test
fun `GIVEN network is offline WHEN user logs in with OpenID THEN login is attempted with offline flag`() =
runTest {
// GIVEN - Network is unavailable
val isOffline = false
whenever(
repository.loginWithOpenId(
serverUrl = serverUrl,
isNetworkAvailable = isOffline,
clientId = clientId,
redirectUri = redirectUri,
discoveryUri = discoveryUri,
authorizationUri = authorizationUri,
tokenUrl = tokenUrl,
),
) doReturn Result.success(Unit)
whenever(repository.getUsername()) doReturn username
whenever(repository.numberOfAccounts()) doReturn 0
whenever(repository.displayTrackingMessage()) doReturn false
whenever(repository.initialSyncDone(serverUrl, username)) doReturn true

// WHEN - User attempts to log in offline
val result =
openIdLogin(
serverUrl = serverUrl,
isNetworkAvailable = isOffline,
clientId = clientId,
redirectUri = redirectUri,
discoveryUri = discoveryUri,
authorizationUri = authorizationUri,
tokenUrl = tokenUrl,
)

// THEN - Login is successful with offline flag
assertIs<LoginResult.Success>(result)
verify(repository).loginWithOpenId(
serverUrl = serverUrl,
isNetworkAvailable = isOffline,
clientId = clientId,
redirectUri = redirectUri,
discoveryUri = discoveryUri,
authorizationUri = authorizationUri,
tokenUrl = tokenUrl,
)
}
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

The test description states "GIVEN network is offline" but the variable isOffline is set to false (line 298), which means the network is online. This contradicts the test's intent. Either:

  1. Change isOffline to true to actually test offline behavior, or
  2. Rename the variable to isOnline and update the test description to match

The current implementation doesn't actually test offline login behavior as the test name suggests.

Copilot uses AI. Check for mistakes.
fun `GIVEN network is offline WHEN user logs in with OpenID THEN login is attempted with offline flag`() =
runTest {
// GIVEN - Network is unavailable
val isOffline = false
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

The variable name isOffline is misleading and contradictory:

  • Line 297 comment states "GIVEN - Network is unavailable"
  • Line 298 defines isOffline = false (meaning network IS available)
  • Line 302 uses isNetworkAvailable = isOffline (passing false, meaning available)
  • Line 327 comment says "THEN - Login is successful with offline flag"

This creates confusion. The variable should be named isNetworkAvailable to match the parameter name and be set to false for offline testing, or true if testing online behavior. The test description and comments should then be updated accordingly.

Copilot uses AI. Check for mistakes.
verify(repository).updateAvailableUsers(username)
verify(repository).updateServerUrls(serverUrl)
verify(repository).numberOfAccounts()
// Biometric credentials should NOT be deleted when numberOfAccounts < 1
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

The comment states "Biometric credentials should NOT be deleted when numberOfAccounts < 1", but the actual implementation condition in BaseLogin.kt:35 is numberOfAccounts() >= 2.

The comment should be corrected to:

// Biometric credentials should NOT be deleted when numberOfAccounts < 2

This accurately reflects that deletion only occurs when there are 2 or more accounts.

Suggested change
// Biometric credentials should NOT be deleted when numberOfAccounts < 1
// Biometric credentials should NOT be deleted when numberOfAccounts < 2

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +116
@Test
fun `GIVEN successful OpenID login with one existing account WHEN user logs in to second account THEN biometric creds are deleted`() =
runTest {
// GIVEN - User has one existing account (numberOfAccounts = 1)
whenever(
repository.loginWithOpenId(
serverUrl = serverUrl,
isNetworkAvailable = isNetworkAvailable,
clientId = clientId,
redirectUri = redirectUri,
discoveryUri = discoveryUri,
authorizationUri = authorizationUri,
tokenUrl = tokenUrl,
),
) doReturn Result.success(Unit)
whenever(repository.getUsername()) doReturn username
whenever(repository.numberOfAccounts()) doReturn 1
whenever(repository.displayTrackingMessage()) doReturn false
whenever(repository.initialSyncDone(serverUrl, username)) doReturn true

// WHEN - User logs in successfully with OpenID to a second account
val result =
openIdLogin(
serverUrl = serverUrl,
isNetworkAvailable = isNetworkAvailable,
clientId = clientId,
redirectUri = redirectUri,
discoveryUri = discoveryUri,
authorizationUri = authorizationUri,
tokenUrl = tokenUrl,
)

// THEN - Login is successful and biometric credentials are deleted
assertIs<LoginResult.Success>(result)
verify(repository).unlockSession()
verify(repository).updateAvailableUsers(username)
verify(repository).updateServerUrls(serverUrl)
verify(repository).numberOfAccounts()
verify(repository).deleteBiometricCredentials()
}
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

This test incorrectly expects biometric credentials to be deleted when numberOfAccounts() = 1. According to the implementation in BaseLogin.kt:35, biometric credentials are only deleted when numberOfAccounts() >= 2.

With only 1 existing account, the condition >= 2 is not met, so deleteBiometricCredentials() should NOT be called. The assertion at line 115 should be changed to:

verify(repository, never()).deleteBiometricCredentials()

Alternatively, if the test intent is to verify deletion when logging into a second account, numberOfAccounts() should return 2, not 1.

Copilot uses AI. Check for mistakes.
@xavimolloy xavimolloy force-pushed the ANDROAPP-7393-openid-login-test branch from 85387c4 to fdad183 Compare December 3, 2025 12:04
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.

4 participants