diff options
author | Allan Wang <me@allanwang.ca> | 2017-12-21 20:55:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-21 20:55:51 -0500 |
commit | f1e1aec8487fd148eb8e75fe016a8438958989ad (patch) | |
tree | c4d614e6a3e7d6ef9fa7c04452c357d06bc50279 /app/src/test/kotlin/com | |
parent | d683cae6ffe644a9f63eea6cf3b7e59d2bde617b (diff) | |
download | frost-f1e1aec8487fd148eb8e75fe016a8438958989ad.tar.gz frost-f1e1aec8487fd148eb8e75fe016a8438958989ad.tar.bz2 frost-f1e1aec8487fd148eb8e75fe016a8438958989ad.zip |
misc (#566)
* Fix click validator
* Update tests
* Feature/fb requests (#567)
* Add initial requesting interface
* Update unit tests and dependencies
* Resolve lint
* Fix lint 2
* Fix toolbar location, closes #439
* Add prev version code, closes #551
* Clear test val
* Update changelog
Diffstat (limited to 'app/src/test/kotlin/com')
3 files changed, 96 insertions, 0 deletions
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt new file mode 100644 index 00000000..a521ceda --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt @@ -0,0 +1,62 @@ +package com.pitchedapps.frost.facebook + +import com.pitchedapps.frost.internal.COOKIE +import com.pitchedapps.frost.internal.FB_DTSG +import com.pitchedapps.frost.internal.USER_ID +import org.junit.Assume +import org.junit.BeforeClass +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotNull + +/** + * Created by Allan Wang on 21/12/17. + */ +class FbRequestTest { + + companion object { + @BeforeClass + @JvmStatic + fun before() { + Assume.assumeTrue(COOKIE.isNotEmpty()) + } + + val AUTH: RequestAuth by lazy { RequestAuth(USER_ID, COOKIE, FB_DTSG) } + } + + @Test + fun userIdRegex() { + val id = 12349876L + val cookie = "wd=1366x615; c_user=$id; act=1234%2F12; m_pixel_ratio=1; presence=hello; x-referer=asdfasdf" + assertEquals(id, FB_USER_MATCHER.find(cookie)?.groupValues?.get(1)?.toLong()) + } + + @Test + fun fbDtsgRegex() { + val fb_dtsg = "readme" + val input = "data-sigil=\"mbasic_inline_feed_composer\">\u003Cinput type=\"hidden\" name=\"fb_dtsg\" value=\"$fb_dtsg\" autocomplete=\"off\" \\/>\u003Cinput type=\"hidden\" name=\"privacyx\" value=\"12345\"" + assertEquals(fb_dtsg, FB_DTSG_MATCHER.find(input)?.groupValues?.get(1)) + } + + @Test + fun auth() { + val auth = (USER_ID to COOKIE).getAuth() + assertNotNull(auth) + assertEquals(USER_ID, auth!!.userId) + assertEquals(COOKIE, auth.cookie) + println("Test auth: priv $FB_DTSG, test ${auth.fb_dtsg}") + } + + @Test + fun markNotification() { + val notifId = 1513544657695779 + + val out = AUTH.markNotificationRead(notifId) + .execute().body()?.string() ?: "" + println(out) + + assertFalse(out.contains("error")) + } + +}
\ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt new file mode 100644 index 00000000..91eb968d --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt @@ -0,0 +1,28 @@ +package com.pitchedapps.frost.internal + +import com.pitchedapps.frost.facebook.FB_USER_MATCHER +import java.io.File +import java.io.FileInputStream +import java.util.* + +/** + * Created by Allan Wang on 21/12/17. + */ + +private const val FILE = "priv.properties" + +val PROPS: Properties by lazy { + val props = Properties() + val file = File(FILE) + if (!file.exists()) { + println("$FILE not found") + return@lazy props + } + println("Found properties at ${file.absolutePath}") + FileInputStream(file).use { props.load(it) } + props +} + +val COOKIE: String by lazy { PROPS.getProperty("COOKIE") ?: "" } +val FB_DTSG: String by lazy { PROPS.getProperty("FB_DTSG") ?: "" } +val USER_ID: Long by lazy { FB_USER_MATCHER.find(COOKIE)?.groupValues?.get(1)?.toLong() ?: -1 } diff --git a/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt b/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt index 4062cf98..5dbcad65 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/UrlTests.kt @@ -17,6 +17,12 @@ class UrlTests { assertTrue(GOOGLE.isIndependent, "google") assertTrue(FACEBOOK_COM.isIndependent, "facebook") assertFalse("#!/photos/viewer/?photoset_token=pcb.1234".isIndependent, "photo") + assertFalse("#test-id".isIndependent, "id") + assertFalse("#".isIndependent, "#") + assertFalse("#!".isIndependent, "#!") + assertFalse("#!/".isIndependent, "#!/") + assertTrue("/this/is/valid".isIndependent, "url segments") + assertTrue("#!/facebook/segment".isIndependent, "facebook segments") } @Test |