mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-05 03:55:58 +01:00
more DSL
This commit is contained in:
parent
dc5d6fca51
commit
7a1df02920
4 changed files with 43 additions and 41 deletions
|
@ -40,6 +40,9 @@ interface NetworkDSL {
|
||||||
fun Certification(issuer: CertSynopsis, target: CertSynopsis, userId: String): Certification =
|
fun Certification(issuer: CertSynopsis, target: CertSynopsis, userId: String): Certification =
|
||||||
Certification(issuer, target, userId, Date())
|
Certification(issuer, target, userId, Date())
|
||||||
|
|
||||||
|
fun Certification(issuer: CertSynopsis, target: CertSynopsis, amount: Int, depth: Depth): Certification =
|
||||||
|
Certification(issuer, target, null, Date(), null, true, amount, depth, RegexSet.wildcard())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a single [CertSynopsis] built from a [String] fingerprint to the builder.
|
* Add a single [CertSynopsis] built from a [String] fingerprint to the builder.
|
||||||
*/
|
*/
|
||||||
|
@ -150,6 +153,30 @@ interface NetworkDSL {
|
||||||
return getEdgeFor(Fingerprint(issuer), Fingerprint(target), userId)
|
return getEdgeFor(Fingerprint(issuer), Fingerprint(target), userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Date.plusMillis(millis: Long): Date {
|
||||||
|
return Date(time + millis)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Date.plusSeconds(seconds: Long): Date {
|
||||||
|
return plusMillis(1000L * seconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Date.plusMinutes(minutes: Long): Date {
|
||||||
|
return plusSeconds(60 * minutes)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Date.plusHours(hours: Long): Date {
|
||||||
|
return plusMinutes(60 * hours)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Date.plusDays(days: Long): Date {
|
||||||
|
return plusHours(24 * days)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun domainRegex(domain: String): RegexSet {
|
||||||
|
return RegexSet.fromExpression("<[^>]+[@.]" + domain.replace(".", "\\.") + ">$")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lambda with Receiver.
|
* Lambda with Receiver.
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,23 +7,11 @@ import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class PathTest {
|
class PathTest: NetworkDSL {
|
||||||
|
|
||||||
private val root = CertSynopsis(
|
private val root = CertSynopsis("aabbccddeeAABBCCDDEEaabbccddeeAABBCCDDEE")
|
||||||
Fingerprint("aabbccddeeAABBCCDDEEaabbccddeeAABBCCDDEE"),
|
private val alice = CertSynopsis("0000000000000000000000000000000000000000")
|
||||||
null,
|
private val bob = CertSynopsis("1111111111111111111111111111111111111111")
|
||||||
RevocationState.notRevoked(),
|
|
||||||
mapOf())
|
|
||||||
private val alice = CertSynopsis(
|
|
||||||
Fingerprint("0000000000000000000000000000000000000000"),
|
|
||||||
null,
|
|
||||||
RevocationState.notRevoked(),
|
|
||||||
mapOf())
|
|
||||||
private val bob = CertSynopsis(
|
|
||||||
Fingerprint("1111111111111111111111111111111111111111"),
|
|
||||||
null,
|
|
||||||
RevocationState.notRevoked(),
|
|
||||||
mapOf())
|
|
||||||
|
|
||||||
// Root -(255, 255)-> Alice
|
// Root -(255, 255)-> Alice
|
||||||
private val root_alice__fully_trusted = Certification(root, alice, 255, Depth.unconstrained())
|
private val root_alice__fully_trusted = Certification(root, alice, 255, Depth.unconstrained())
|
||||||
|
@ -32,7 +20,7 @@ class PathTest {
|
||||||
// Alice -(255,255)-> Root
|
// Alice -(255,255)-> Root
|
||||||
private val alice_root = Certification(alice, root, 255, Depth.unconstrained())
|
private val alice_root = Certification(alice, root, 255, Depth.unconstrained())
|
||||||
// Alice -(120, 1)-> Bob
|
// Alice -(120, 1)-> Bob
|
||||||
private val alice_bob = Certification(alice, bob, null, Date())
|
private val alice_bob = Certification(alice, bob)
|
||||||
// Root -> Root
|
// Root -> Root
|
||||||
private val root_root = Certification(root, root, 120, Depth.limited(1))
|
private val root_root = Certification(root, root, 120, Depth.limited(1))
|
||||||
|
|
||||||
|
@ -102,10 +90,4 @@ class PathTest {
|
||||||
val path = Path(root)
|
val path = Path(root)
|
||||||
assertThrows<IllegalArgumentException> { path.append(root_root) }
|
assertThrows<IllegalArgumentException> { path.append(root_root) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method for legible initialization of [Certification] objects for test purposes.
|
|
||||||
*/
|
|
||||||
fun Certification(issuer: CertSynopsis, target: CertSynopsis, amount: Int, depth: Depth): Certification =
|
|
||||||
Certification(issuer, target, null, Date(), null, true, amount, depth, RegexSet.wildcard())
|
|
||||||
}
|
}
|
|
@ -6,18 +6,10 @@ import org.pgpainless.wot.dijkstra.sq.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class PathsTest {
|
class PathsTest: NetworkDSL {
|
||||||
|
|
||||||
private val alice = CertSynopsis(
|
private val alice = CertSynopsis("0000000000000000000000000000000000000000")
|
||||||
Fingerprint("0000000000000000000000000000000000000000"),
|
private val bob = CertSynopsis("1111111111111111111111111111111111111111")
|
||||||
null,
|
|
||||||
RevocationState.notRevoked(),
|
|
||||||
mapOf())
|
|
||||||
private val bob = CertSynopsis(
|
|
||||||
Fingerprint("1111111111111111111111111111111111111111"),
|
|
||||||
null,
|
|
||||||
RevocationState.notRevoked(),
|
|
||||||
mapOf())
|
|
||||||
|
|
||||||
private val alice_bob_1 = Certification(alice, bob, 140, Depth.unconstrained())
|
private val alice_bob_1 = Certification(alice, bob, 140, Depth.unconstrained())
|
||||||
private val alice_bob_2 = Certification(alice, bob, 160, Depth.limited(1))
|
private val alice_bob_2 = Certification(alice, bob, 160, Depth.limited(1))
|
||||||
|
@ -56,10 +48,4 @@ class PathsTest {
|
||||||
paths.add(path, 250)
|
paths.add(path, 250)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory method to create a [Certification] more easily for test purposes.
|
|
||||||
*/
|
|
||||||
private fun Certification(issuer: CertSynopsis, target: CertSynopsis, amount: Int, depth: Depth): Certification =
|
|
||||||
Certification(issuer, target, null, Date(), null, true, amount, depth, RegexSet.wildcard())
|
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@ import org.pgpainless.wot.dijkstra.sq.RegexSet
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class RegexSetTest {
|
class RegexSetTest: NetworkDSL {
|
||||||
|
|
||||||
private val exampleComRegex = "<[^>]+[@.]example\\.com>\$"
|
private val exampleComRegex = "<[^>]+[@.]example\\.com>\$"
|
||||||
private val pgpainlessOrgRegex = "<[^>]+[@.]pgpainless\\.org>\$"
|
private val pgpainlessOrgRegex = "<[^>]+[@.]pgpainless\\.org>\$"
|
||||||
|
@ -39,4 +39,11 @@ class RegexSetTest {
|
||||||
assertFalse { multi.matches("Alice") }
|
assertFalse { multi.matches("Alice") }
|
||||||
assertFalse { multi.matches("<info@examp1e.com>") }
|
assertFalse { multi.matches("<info@examp1e.com>") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `verify that a domain regex built with DLS properly works`() {
|
||||||
|
val regex = domainRegex("pgpainless.org")
|
||||||
|
assertTrue { regex.matches("Alice <alice@pgpainless.org>") }
|
||||||
|
assertFalse { regex.matches("<alice@pgpainless\\.org>") }
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue