Commit 51b77601 authored by brizental's avatar brizental Committed by brizental
Browse files

fixup! [android] Disable features and functionality

Bug 45134: Return deterministic NIL value for ClientUUID
parent 584d0657
Loading
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ package org.mozilla.fenix.components

import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit
import mozilla.components.lib.llm.mlpa.UserIdProvider
import mozilla.components.lib.llm.mlpa.service.UserId
import mozilla.components.support.ktx.kotlin.toHexString
@@ -67,12 +66,9 @@ internal class PrefsBackedClientUUID(
    private val generateUUID: () -> String = { UUID.randomUUID().toString() },
    private val hasher: Hasher = Hasher.sha256,
) : ClientUUID {
    // tor-browser#45134: never expose a unique, trackable per-install identifier.
    private val uuid: String by lazy {
        getPrefs().let { prefs ->
            prefs.getString(KEY, null) ?: generateUUID().also {
                prefs.edit { putString(KEY, it) }
            }
        }
        NIL_UUID
    }

    override fun getUserId() = UserId(uuid)
@@ -81,5 +77,6 @@ internal class PrefsBackedClientUUID(

    companion object {
        private const val KEY = "uuid"
        private const val NIL_UUID = "00000000-0000-0000-0000-000000000000"
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -7,9 +7,25 @@ package org.mozilla.fenix.components
import mozilla.components.lib.llm.mlpa.service.UserId
import mozilla.components.support.test.fakes.android.FakeSharedPreferences
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Test

class ClientUUIDTest {
    @Test
    fun `that the client uuid is always the nil uuid, regardless of generateUUID`() {
        val prefs = FakeSharedPreferences()
        val nilUuid = UserId("00000000-0000-0000-0000-000000000000")

        val first = PrefsBackedClientUUID({ prefs }, generateUUID = { "my-generated-uuid" })
        assertEquals(nilUuid, first.getUserId())
        // idempotency check
        assertEquals(nilUuid, first.getUserId())

        val second = PrefsBackedClientUUID({ prefs }, generateUUID = { "another-generated-uuid" })
        assertEquals(nilUuid, second.getUserId())
    }

    @Ignore("tor-browser#45134: PrefsBackedClientUUID always returns the nil uuid, see the test above")
    @Test
    fun `that a client uuid will only be generated the first time`() {
        val prefs = FakeSharedPreferences()
@@ -25,6 +41,7 @@ class ClientUUIDTest {
        assertEquals(UserId("my-generated-uuid"), second.getUserId())
    }

    @Ignore("tor-browser#45134: PrefsBackedClientUUID always returns the nil uuid, so the hash is no longer derived from generateUUID's output")
    @Test
    fun `that generateHash uses the provided hasher`() {
        val prefs = FakeSharedPreferences()