Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.duckduckgo.app.httpsupgrade

import android.net.Uri
import com.duckduckgo.app.httpsupgrade.store.HttpsFalsePositivesDao
import com.duckduckgo.app.pixels.AppPixelName
import com.duckduckgo.app.privacy.db.UserWhitelistDao
import com.duckduckgo.app.statistics.pixels.Pixel
import com.nhaarman.mockitokotlin2.mock
Expand Down Expand Up @@ -52,35 +51,30 @@ class HttpsUpgraderTest {
fun whenHttpUriIsInBloomThenShouldUpgrade() {
bloomFilter.add("www.local.url")
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.local.url")))
mockPixel.fire(AppPixelName.HTTPS_LOCAL_UPGRADE)
}

@Test
fun whenHttpUriIsNotInBloomThenShouldNotUpgrade() {
bloomFilter.add("www.local.url")
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.differentlocal.url")))
mockPixel.fire(AppPixelName.HTTPS_NO_UPGRADE)
}

@Test
fun whenHttpsUriThenShouldNotUpgrade() {
bloomFilter.add("www.local.url")
assertFalse(testee.shouldUpgrade(Uri.parse("https://www.local.url")))
mockPixel.fire(AppPixelName.HTTPS_NO_UPGRADE)
}

@Test
fun whenHttpUriHasOnlyPartDomainInLocalListThenShouldNotUpgrade() {
bloomFilter.add("local.url")
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.local.url")))
mockPixel.fire(AppPixelName.HTTPS_NO_LOOKUP)
}

@Test
fun whenHttpDomainIsUserWhitelistedThenShouldNotUpgrade() {
bloomFilter.add("www.local.url")
whenever(mockUserAllowlistDao.contains("www.local.url")).thenReturn(true)
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.local.url")))
mockPixel.fire(AppPixelName.HTTPS_NO_LOOKUP)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,23 @@ class HttpsUpgraderImpl(
override fun shouldUpgrade(uri: Uri): Boolean {

if (uri.isHttps) {
pixel.fire(HTTPS_NO_LOOKUP)
return false
}

val host = uri.host
if (host == null) {
pixel.fire(HTTPS_NO_LOOKUP)
return false
}
val host = uri.host ?: return false

if (userAllowListDao.contains(host)) {
pixel.fire(HTTPS_NO_LOOKUP)
Timber.d("$host is in user allowlist and so not upgradable")
return false
}

if (bloomFalsePositiveDao.contains(host)) {
pixel.fire(HTTPS_NO_LOOKUP)
Timber.d("$host is in https whitelist and so not upgradable")
return false
}

val isUpgradable = isInUpgradeList(host)
Timber.d("$host ${if (isUpgradable) "is" else "is not"} upgradable")
pixel.fire(if (isUpgradable) HTTPS_LOCAL_UPGRADE else HTTPS_NO_UPGRADE)
return isUpgradable
}

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ enum class AppPixelName(override val pixelName: String) : Pixel.PixelName {
BROWSER_MENU_WHITELIST_ADD("mb_wla"),
BROWSER_MENU_WHITELIST_REMOVE("mb_wlr"),

HTTPS_NO_LOOKUP("m_https_nl"),
HTTPS_LOCAL_UPGRADE("m_https_lu"),
HTTPS_NO_UPGRADE("m_https_nu"),

DEFAULT_BROWSER_SET("m_db_s"),
DEFAULT_BROWSER_NOT_SET("m_db_ns"),
DEFAULT_BROWSER_UNSET("m_db_u"),
Expand Down