You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Querying Facts returns types that are missing public accessors #69
When querying facts on an authorizer, the returned types are com.clevercloud.biscuit.token.builder.Term - this class hierarchy does not have public accessors, so it is difficult to get the data out. (Except for Term.Str, which does have a getValue() )
minor: The toStrings look a little bit odd too, e.g. ""+value rather than String.valueOf(x)
sorry my test case is kotlin.
importcom.clevercloud.biscuit.crypto.KeyPairimportcom.clevercloud.biscuit.token.Biscuitimportcom.clevercloud.biscuit.token.builder.Termimportorg.junit.jupiter.api.Testimportstrikt.api.expectThatimportstrikt.assertions.isEqualToclassBiscuitTest {
val keypair =KeyPair()
@Test
fun`can put a fact in a biscuit and get it back out again`() {
val token =Biscuit.builder(keypair)
.add_authority_fact("""email("bob@example.com")""")
.add_authority_fact("""id(123)""")
.build()
val tokenString = token.serialize_b64url().replace("=", "")
val authorizer =Biscuit.from_b64url(tokenString, keypair.public_key())
.verify(keypair.public_key())
.authorizer()
val email = authorizer.query("emailfact(\$name) <- email(\$name)")
.first { it.name() =="emailfact" }
.terms()
.first()
.stringValue()
expectThat(email).isEqualTo("bob@example.com")
val id = authorizer.query("idfact(\$name) <- id(\$name)")
.first { it.name() =="idfact" }
.terms()
.first()
.intValue()
expectThat(id).isEqualTo(123) // might not work is a Term.Integer an int or a long?
}
}
fun Term.stringValue(): String {
returnwhen (this) {
isTerm.Str->this.value
else->throwIllegalArgumentException("Can only call on Term.Str")
}
}
fun Term.intValue(): Int {
returnwhen (this) {
isTerm.Integer->this.value // does not compile:- package-private, also, is a long?else->throwIllegalArgumentException("Can only call on Term.Integer")
}
}
Activity