mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/19797 - Use the FXA email only if the account is authenticated
An account may exist but it may need to be re-authenticated. In this case also the email should not be exposed to the app.
This commit is contained in:
parent
60725fc1f9
commit
c2b11553f1
@ -18,8 +18,15 @@ open class FenixAccountManager(context: Context) {
|
|||||||
val authenticatedAccount
|
val authenticatedAccount
|
||||||
get() = accountManager.authenticatedAccount() != null
|
get() = accountManager.authenticatedAccount() != null
|
||||||
|
|
||||||
val accountProfileEmail
|
/**
|
||||||
get() = accountManager.accountProfile()?.email
|
* Returns the Firefox Account email if authenticated in the app, `null` otherwise.
|
||||||
|
*/
|
||||||
|
val accountProfileEmail: String?
|
||||||
|
get() = if (accountState == AccountState.AUTHENTICATED) {
|
||||||
|
accountManager.accountProfile()?.email
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current state of the Firefox Account. See [AccountState].
|
* The current state of the Firefox Account. See [AccountState].
|
||||||
|
@ -332,16 +332,8 @@ open class DefaultToolbarMenu(
|
|||||||
onItemTapped.invoke(ToolbarMenu.Item.Quit)
|
onItemTapped.invoke(ToolbarMenu.Item.Quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSyncItemTitle(): String {
|
private fun getSyncItemTitle() =
|
||||||
val authenticatedAccount = accountManager.authenticatedAccount
|
accountManager.accountProfileEmail ?: context.getString(R.string.sync_menu_sign_in)
|
||||||
val email = accountManager.accountProfileEmail
|
|
||||||
|
|
||||||
return if (authenticatedAccount && !email.isNullOrEmpty()) {
|
|
||||||
email
|
|
||||||
} else {
|
|
||||||
context.getString(R.string.sync_menu_sign_in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val syncMenuItem = BrowserMenuImageText(
|
val syncMenuItem = BrowserMenuImageText(
|
||||||
getSyncItemTitle(),
|
getSyncItemTitle(),
|
||||||
|
@ -91,16 +91,8 @@ class HomeMenu(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSyncItemTitle(): String {
|
private fun getSyncItemTitle(): String =
|
||||||
val authenticatedAccount = accountManager.authenticatedAccount
|
accountManager.accountProfileEmail ?: context.getString(R.string.sync_menu_sign_in)
|
||||||
val email = accountManager.accountProfileEmail
|
|
||||||
|
|
||||||
return if (authenticatedAccount && !email.isNullOrEmpty()) {
|
|
||||||
email
|
|
||||||
} else {
|
|
||||||
context.getString(R.string.sync_menu_sign_in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val syncSignInMenuItem = BrowserMenuImageText(
|
private val syncSignInMenuItem = BrowserMenuImageText(
|
||||||
getSyncItemTitle(),
|
getSyncItemTitle(),
|
||||||
|
@ -14,11 +14,8 @@ import org.junit.Assert.assertEquals
|
|||||||
import org.junit.Assert.assertSame
|
import org.junit.Assert.assertSame
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
|
||||||
|
|
||||||
@RunWith(FenixRobolectricTestRunner::class)
|
|
||||||
class FenixAccountManagerTest {
|
class FenixAccountManagerTest {
|
||||||
|
|
||||||
private lateinit var fenixFxaManager: FenixAccountManager
|
private lateinit var fenixFxaManager: FenixAccountManager
|
||||||
@ -36,32 +33,46 @@ class FenixAccountManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `GIVEN an account exists THEN fetch the associated email address`() {
|
fun `GIVEN an account does not exist WHEN accountProfileEmail is called THEN it returns null`() {
|
||||||
every { accountManagerComponent.authenticatedAccount() } returns account
|
|
||||||
every { accountManagerComponent.accountProfile() } returns profile
|
|
||||||
every { context.components.backgroundServices.accountManager } returns accountManagerComponent
|
|
||||||
|
|
||||||
fenixFxaManager = FenixAccountManager(context)
|
|
||||||
|
|
||||||
val emailAddress = "firefoxIsFun@test.com"
|
|
||||||
every { accountManagerComponent.accountProfile()?.email } returns emailAddress
|
|
||||||
|
|
||||||
val result = fenixFxaManager.accountProfileEmail
|
|
||||||
assertEquals(emailAddress, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `GIVEN an account does not exist THEN return null when fetching the associated email address`() {
|
|
||||||
every { accountManagerComponent.authenticatedAccount() } returns null
|
every { accountManagerComponent.authenticatedAccount() } returns null
|
||||||
every { accountManagerComponent.accountProfile() } returns null
|
every { accountManagerComponent.accountProfile() } returns null
|
||||||
every { context.components.backgroundServices.accountManager } returns accountManagerComponent
|
every { context.components.backgroundServices.accountManager } returns accountManagerComponent
|
||||||
|
|
||||||
fenixFxaManager = FenixAccountManager(context)
|
fenixFxaManager = FenixAccountManager(context)
|
||||||
|
|
||||||
val result = fenixFxaManager.accountProfileEmail
|
val result = fenixFxaManager.accountProfileEmail
|
||||||
|
|
||||||
assertEquals(null, result)
|
assertEquals(null, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `GIVEN an account exists but needs to be re-authenticated WHEN accountProfileEmail is called THEN it returns null`() {
|
||||||
|
every { accountManagerComponent.authenticatedAccount() } returns account
|
||||||
|
every { accountManagerComponent.accountProfile() } returns profile
|
||||||
|
every { accountManagerComponent.accountProfile()?.email } returns "firefoxIsFun@test.com"
|
||||||
|
every { accountManagerComponent.accountNeedsReauth() } returns true
|
||||||
|
every { context.components.backgroundServices.accountManager } returns accountManagerComponent
|
||||||
|
fenixFxaManager = FenixAccountManager(context)
|
||||||
|
|
||||||
|
val result = fenixFxaManager.accountProfileEmail
|
||||||
|
|
||||||
|
assertEquals(null, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `GIVEN an account exists and doesn't need to be re-authenticated WHEN accountProfileEmail is called THEN it returns the associated email address`() {
|
||||||
|
every { accountManagerComponent.authenticatedAccount() } returns account
|
||||||
|
every { accountManagerComponent.accountProfile() } returns profile
|
||||||
|
val accountEmail = "firefoxIsFun@test.com"
|
||||||
|
every { accountManagerComponent.accountProfile()?.email } returns accountEmail
|
||||||
|
every { accountManagerComponent.accountNeedsReauth() } returns false
|
||||||
|
every { context.components.backgroundServices.accountManager } returns accountManagerComponent
|
||||||
|
fenixFxaManager = FenixAccountManager(context)
|
||||||
|
|
||||||
|
val result = fenixFxaManager.accountProfileEmail
|
||||||
|
|
||||||
|
assertEquals(accountEmail, result)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `GIVEN no account exists WHEN accountState is called THEN it returns AccountState#NO_ACCOUNT`() {
|
fun `GIVEN no account exists WHEN accountState is called THEN it returns AccountState#NO_ACCOUNT`() {
|
||||||
every { context.components.backgroundServices.accountManager } returns accountManagerComponent
|
every { context.components.backgroundServices.accountManager } returns accountManagerComponent
|
||||||
|
Loading…
Reference in New Issue
Block a user