From ee35a9768f19d03983f54be20fcc40a708131c86 Mon Sep 17 00:00:00 2001 From: mike castleman Date: Sat, 1 Jun 2019 14:47:14 -0400 Subject: [PATCH 1/3] rick roll instead of logging in on selected domains --- .../com/keylesspalace/tusky/LoginActivity.kt | 6 ++++++ .../com/keylesspalace/tusky/util/RickRoll.kt | 20 +++++++++++++++++++ app/src/main/res/values/donottranslate.xml | 5 +++++ 3 files changed, 31 insertions(+) create mode 100644 app/src/main/java/com/keylesspalace/tusky/util/RickRoll.kt diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt index 659e76548..7359dee41 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt @@ -33,6 +33,7 @@ import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.entity.AccessToken import com.keylesspalace.tusky.entity.AppCredentials import com.keylesspalace.tusky.network.MastodonApi +import com.keylesspalace.tusky.util.RickRoll import com.keylesspalace.tusky.util.ThemeUtils import kotlinx.android.synthetic.main.activity_login.* import okhttp3.HttpUrl @@ -138,6 +139,11 @@ class LoginActivity : BaseActivity(), Injectable { return } + if (RickRoll.shouldRickRoll(this, domain)) { + RickRoll.rickRoll(this) + return + } + val callback = object : Callback { override fun onResponse(call: Call, response: Response) { diff --git a/app/src/main/java/com/keylesspalace/tusky/util/RickRoll.kt b/app/src/main/java/com/keylesspalace/tusky/util/RickRoll.kt new file mode 100644 index 000000000..3adfd6b92 --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/util/RickRoll.kt @@ -0,0 +1,20 @@ +package com.keylesspalace.tusky.util + +import android.content.Context +import android.content.Intent +import android.net.Uri +import com.keylesspalace.tusky.R + +object RickRoll { + fun shouldRickRoll(context: Context, domain: String) = + context.resources.getStringArray(R.array.rick_roll_domains).contains(domain) + + fun rickRoll(context: Context) { + val uri = Uri.parse(context.getString(R.string.rick_roll_url)) + val intent = Intent(Intent.ACTION_VIEW, uri).apply { + addCategory(Intent.CATEGORY_BROWSABLE) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + context.startActivity(intent) + } +} diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 2aa4f90f4..45a19323b 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -105,4 +105,9 @@ %1$s; %2$s; %3$s, %13$s %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s + + gab.com + + + https://www.youtube.com/watch?v=dQw4w9WgXcQ From b15a5c76140b2fe3433bd4440043b8f2c2ca23a5 Mon Sep 17 00:00:00 2001 From: mike castleman Date: Sat, 1 Jun 2019 15:29:15 -0400 Subject: [PATCH 2/3] enhance bad-domain detection --- .../com/keylesspalace/tusky/LoginActivity.kt | 7 ++++--- .../com/keylesspalace/tusky/util/RickRoll.kt | 20 +++++++++---------- app/src/main/res/values/donottranslate.xml | 1 + 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt index 7359dee41..02e3d54ee 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.kt @@ -33,8 +33,9 @@ import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.entity.AccessToken import com.keylesspalace.tusky.entity.AppCredentials import com.keylesspalace.tusky.network.MastodonApi -import com.keylesspalace.tusky.util.RickRoll import com.keylesspalace.tusky.util.ThemeUtils +import com.keylesspalace.tusky.util.rickRoll +import com.keylesspalace.tusky.util.shouldRickRoll import kotlinx.android.synthetic.main.activity_login.* import okhttp3.HttpUrl import retrofit2.Call @@ -139,8 +140,8 @@ class LoginActivity : BaseActivity(), Injectable { return } - if (RickRoll.shouldRickRoll(this, domain)) { - RickRoll.rickRoll(this) + if (shouldRickRoll(this, domain)) { + rickRoll(this) return } diff --git a/app/src/main/java/com/keylesspalace/tusky/util/RickRoll.kt b/app/src/main/java/com/keylesspalace/tusky/util/RickRoll.kt index 3adfd6b92..03c3339fb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/RickRoll.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/RickRoll.kt @@ -5,16 +5,16 @@ import android.content.Intent import android.net.Uri import com.keylesspalace.tusky.R -object RickRoll { - fun shouldRickRoll(context: Context, domain: String) = - context.resources.getStringArray(R.array.rick_roll_domains).contains(domain) - - fun rickRoll(context: Context) { - val uri = Uri.parse(context.getString(R.string.rick_roll_url)) - val intent = Intent(Intent.ACTION_VIEW, uri).apply { - addCategory(Intent.CATEGORY_BROWSABLE) - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) +fun shouldRickRoll(context: Context, domain: String) = + context.resources.getStringArray(R.array.rick_roll_domains).any { candidate -> + domain.equals(candidate, true) || domain.endsWith(".$candidate", true) } - context.startActivity(intent) + +fun rickRoll(context: Context) { + val uri = Uri.parse(context.getString(R.string.rick_roll_url)) + val intent = Intent(Intent.ACTION_VIEW, uri).apply { + addCategory(Intent.CATEGORY_BROWSABLE) + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } + context.startActivity(intent) } diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 45a19323b..7084bcd27 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -107,6 +107,7 @@ gab.com + gab.ai https://www.youtube.com/watch?v=dQw4w9WgXcQ From 728e4f4858d34335ee00a5d9b6e9131cd53f5091 Mon Sep 17 00:00:00 2001 From: mike castleman Date: Sat, 1 Jun 2019 15:29:33 -0400 Subject: [PATCH 3/3] add tests --- .../keylesspalace/tusky/util/RickRollTest.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/src/test/java/com/keylesspalace/tusky/util/RickRollTest.kt diff --git a/app/src/test/java/com/keylesspalace/tusky/util/RickRollTest.kt b/app/src/test/java/com/keylesspalace/tusky/util/RickRollTest.kt new file mode 100644 index 000000000..6a6a5d53a --- /dev/null +++ b/app/src/test/java/com/keylesspalace/tusky/util/RickRollTest.kt @@ -0,0 +1,34 @@ +package com.keylesspalace.tusky.util + +import android.app.Activity +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.keylesspalace.tusky.FakeTuskyApplication +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.Robolectric +import org.robolectric.annotation.Config + +@Config(application = FakeTuskyApplication::class) +@RunWith(AndroidJUnit4::class) +class RickRollTest { + private lateinit var activity: Activity + @Before + fun setupActivity() { + val controller = Robolectric.buildActivity(Activity::class.java) + activity = controller.get() + } + + @Test + fun testShouldRickRoll() { + listOf("gab.Com", "social.gab.ai", "whatever.GAB.com").forEach { + rollableDomain -> assertTrue(shouldRickRoll(activity, rollableDomain)) + } + + listOf("chaos.social", "notgab.com").forEach { + notRollableDomain -> assertFalse(shouldRickRoll(activity, notRollableDomain)) + } + } +}