Workaround too early loggin in

This commit is contained in:
Mikołaj Pich 2018-12-30 22:03:43 +01:00
parent 6505da304a
commit 864c4e9942
No known key found for this signature in database
GPG key ID: F62B26E36D4C4BAA
3 changed files with 37 additions and 3 deletions

View file

@ -4,14 +4,17 @@ import pl.droidsonroids.jspoon.annotation.Selector
class CertificateResponse {
@Selector("title")
var title: String = ""
@Selector("form[name=hiddenform]", attr = "abs:action")
lateinit var action: String
var action: String = ""
@Selector("input[name=wa]", attr = "value")
lateinit var wa: String
var wa: String = ""
@Selector("input[name=wresult]", attr = "value")
lateinit var wresult: String
var wresult: String = ""
@Selector("input[name=wctx]", attr = "value", defValue = "")
var wctx: String = ""

View file

@ -2,6 +2,7 @@ package io.github.wulkanowy.api.repository
import io.github.wulkanowy.api.Api
import io.github.wulkanowy.api.ApiException
import io.github.wulkanowy.api.interceptor.VulcanException
import io.github.wulkanowy.api.login.CertificateResponse
import io.github.wulkanowy.api.register.HomepageResponse
import io.github.wulkanowy.api.service.LoginService
@ -43,6 +44,11 @@ class LoginRepository(
@Synchronized
fun login(email: String, password: String): Single<HomepageResponse> {
return sendCredentials(email, password).flatMap {
when {
it.title.startsWith("Witryna ucznia i rodzica") -> return@flatMap Single.just(HomepageResponse())
it.action.isBlank() -> throw VulcanException("Invalid certificate page: '${it.title}'. Try again")
}
sendCertificate(it)
}
}

View file

@ -2,6 +2,8 @@ package io.github.wulkanowy.api.login
import io.github.wulkanowy.api.Api
import io.github.wulkanowy.api.BaseLocalTest
import io.github.wulkanowy.api.homework.HomeworkTest
import io.github.wulkanowy.api.interceptor.VulcanException
import io.github.wulkanowy.api.register.HomepageResponse
import io.github.wulkanowy.api.repository.LoginRepository
import io.github.wulkanowy.api.service.LoginService
@ -111,4 +113,27 @@ class LoginTest : BaseLocalTest() {
observer.assertTerminated()
observer.assertError(AccountPermissionException::class.java)
}
@Test
fun alreadyLoggedIn() {
server.enqueue(MockResponse().setBody(HomeworkTest::class.java.getResource("ZadaniaDomowe.html").readText()))
server.start(3000)
val res = normal.login("jan@fakelog.cf", "jan123")
val observer = TestObserver<HomepageResponse>()
res.subscribe(observer)
observer.assertComplete()
}
@Test
fun invalidCertificatePage() {
server.enqueue(MockResponse().setBody(LoginTest::class.java.getResource("Offline.html").readText()))
server.start(3000)
val res = normal.login("jan@fakelog.cf", "jan123")
val observer = TestObserver<HomepageResponse>()
res.subscribe(observer)
observer.assertTerminated()
observer.assertError(VulcanException::class.java)
}
}