55 lines
1.7 KiB
Kotlin
55 lines
1.7 KiB
Kotlin
package studio.daybreak.mail
|
|
|
|
import org.junit.Assert.assertEquals
|
|
import org.junit.Assert.assertThrows
|
|
import org.junit.Test
|
|
|
|
class DavUrlPolicyTest {
|
|
@Test
|
|
fun acceptsHttpsServerUrl() {
|
|
assertEquals("https://dav.example.test/calendar", DavUrlPolicy.parseServerUrl(
|
|
"https://dav.example.test/calendar"
|
|
).toString())
|
|
}
|
|
|
|
@Test
|
|
fun rejectsCleartextAndNonWebSchemes() {
|
|
assertThrows(IllegalArgumentException::class.java) {
|
|
DavUrlPolicy.parseServerUrl("http://localhost:8080/dav")
|
|
}
|
|
assertThrows(IllegalArgumentException::class.java) {
|
|
DavUrlPolicy.parseServerUrl("ftp://dav.example.test/dav")
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun rejectsEmbeddedCredentialsAndFragments() {
|
|
assertThrows(IllegalArgumentException::class.java) {
|
|
DavUrlPolicy.parseServerUrl("https://user:pass@dav.example.test/dav")
|
|
}
|
|
assertThrows(IllegalArgumentException::class.java) {
|
|
DavUrlPolicy.parseServerUrl("https://dav.example.test/dav#fragment")
|
|
}
|
|
}
|
|
|
|
@Test
|
|
fun allowsSameOriginAndRejectsCrossOriginTargets() {
|
|
DavUrlPolicy.requireSameOrigin(
|
|
"https://dav.example.test/root",
|
|
"https://dav.example.test/calendar/"
|
|
)
|
|
assertThrows(IllegalArgumentException::class.java) {
|
|
DavUrlPolicy.requireSameOrigin(
|
|
"https://dav.example.test/root",
|
|
"https://attacker.example.test/calendar/"
|
|
)
|
|
}
|
|
assertThrows(IllegalArgumentException::class.java) {
|
|
DavUrlPolicy.requireSameOrigin(
|
|
"https://dav.example.test/root",
|
|
"http://dav.example.test/calendar/"
|
|
)
|
|
}
|
|
}
|
|
}
|