diff --git a/src/main/java/org/biscuitsec/biscuit/datalog/Combinator.java b/src/main/java/org/biscuitsec/biscuit/datalog/Combinator.java index 7dc8f8e4..3fd25191 100644 --- a/src/main/java/org/biscuitsec/biscuit/datalog/Combinator.java +++ b/src/main/java/org/biscuitsec/biscuit/datalog/Combinator.java @@ -119,7 +119,10 @@ public Option>> getNext() { // no need to copy all the expressions at all levels this.currentIt = new Combinator( - vars, predicates.subList(1, predicates.size()), this.allFacts, this.symbolTable); + vars, + predicates.subList(1, predicates.size()), + this.allFacts, + this.symbolTable); } break; diff --git a/src/main/java/org/biscuitsec/biscuit/datalog/MatchedVariables.java b/src/main/java/org/biscuitsec/biscuit/datalog/MatchedVariables.java index 6f55d192..770cb952 100644 --- a/src/main/java/org/biscuitsec/biscuit/datalog/MatchedVariables.java +++ b/src/main/java/org/biscuitsec/biscuit/datalog/MatchedVariables.java @@ -64,8 +64,8 @@ public MatchedVariables(final Set ids) { } } - public Option> checkExpressions(List expressions, SymbolTable symbolTable) - throws Error { + public Option> checkExpressions( + List expressions, SymbolTable symbolTable) throws Error { final Option> vars = this.complete(); if (vars.isDefined()) { Map variables = vars.get(); diff --git a/src/main/java/org/biscuitsec/biscuit/datalog/Rule.java b/src/main/java/org/biscuitsec/biscuit/datalog/Rule.java index 6ae5e4ea..4d2b4536 100644 --- a/src/main/java/org/biscuitsec/biscuit/datalog/Rule.java +++ b/src/main/java/org/biscuitsec/biscuit/datalog/Rule.java @@ -127,7 +127,8 @@ private MatchedVariables variablesSet() { // do not produce new facts, only find one matching set of facts public boolean findMatch( - final FactSet facts, Long origin, TrustedOrigins scope, SymbolTable symbolTable) throws Error { + final FactSet facts, Long origin, TrustedOrigins scope, SymbolTable symbolTable) + throws Error { MatchedVariables variables = variablesSet(); if (this.body.isEmpty()) { @@ -135,7 +136,8 @@ public boolean findMatch( } Supplier>> factsSupplier = () -> facts.stream(scope); - Stream>> stream = this.apply(factsSupplier, origin, symbolTable); + Stream>> stream = + this.apply(factsSupplier, origin, symbolTable); Iterator>> it = stream.iterator(); diff --git a/src/main/java/org/biscuitsec/biscuit/datalog/World.java b/src/main/java/org/biscuitsec/biscuit/datalog/World.java index 2ebdbe9f..a7a89108 100644 --- a/src/main/java/org/biscuitsec/biscuit/datalog/World.java +++ b/src/main/java/org/biscuitsec/biscuit/datalog/World.java @@ -90,13 +90,14 @@ public RuleSet getRules() { return this.rules; } - public FactSet queryRule(final Rule rule, Long origin, TrustedOrigins scope, SymbolTable symbolTable) - throws Error { + public FactSet queryRule( + final Rule rule, Long origin, TrustedOrigins scope, SymbolTable symbolTable) throws Error { final FactSet newFacts = new FactSet(); Supplier>> factsSupplier = () -> this.facts.stream(scope); - Stream>> stream = rule.apply(factsSupplier, origin, symbolTable); + Stream>> stream = + rule.apply(factsSupplier, origin, symbolTable); for (Iterator>> it = stream.iterator(); it.hasNext(); ) { Either> res = it.next(); @@ -111,8 +112,8 @@ public FactSet queryRule(final Rule rule, Long origin, TrustedOrigins scope, Sym return newFacts; } - public boolean queryMatch(final Rule rule, Long origin, TrustedOrigins scope, SymbolTable symbolTable) - throws Error { + public boolean queryMatch( + final Rule rule, Long origin, TrustedOrigins scope, SymbolTable symbolTable) throws Error { return rule.findMatch(this.facts, origin, scope, symbolTable); } diff --git a/src/main/java/org/biscuitsec/biscuit/datalog/expressions/Op.java b/src/main/java/org/biscuitsec/biscuit/datalog/expressions/Op.java index 8353381e..a1af1e4e 100644 --- a/src/main/java/org/biscuitsec/biscuit/datalog/expressions/Op.java +++ b/src/main/java/org/biscuitsec/biscuit/datalog/expressions/Op.java @@ -52,7 +52,8 @@ public Term getValue() { } @Override - public void evaluate(Deque stack, Map variables, TemporarySymbolTable temporarySymbolTable) + public void evaluate( + Deque stack, Map variables, TemporarySymbolTable temporarySymbolTable) throws Error.Execution { if (value instanceof Term.Variable) { Term.Variable var = (Term.Variable) value; @@ -126,7 +127,8 @@ public UnaryOp getOp() { } @Override - public void evaluate(Deque stack, Map variables, TemporarySymbolTable temporarySymbolTable) + public void evaluate( + Deque stack, Map variables, TemporarySymbolTable temporarySymbolTable) throws Error.Execution { Term value = stack.pop(); switch (this.op) { @@ -287,7 +289,8 @@ public BinaryOp getOp() { } @Override - public void evaluate(Deque stack, Map variables, TemporarySymbolTable temporarySymbolTable) + public void evaluate( + Deque stack, Map variables, TemporarySymbolTable temporarySymbolTable) throws Error.Execution { Term right = stack.pop(); Term left = stack.pop(); @@ -398,7 +401,8 @@ public void evaluate(Deque stack, Map variables, TemporarySymb } if (left instanceof Term.Str && right instanceof Term.Str) { Option leftS = temporarySymbolTable.getSymbol((int) ((Term.Str) left).value()); - Option rightS = temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); + Option rightS = + temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); if (leftS.isEmpty()) { throw new Error.Execution( @@ -415,7 +419,8 @@ public void evaluate(Deque stack, Map variables, TemporarySymb case Prefix: if (right instanceof Term.Str && left instanceof Term.Str) { Option leftS = temporarySymbolTable.getSymbol((int) ((Term.Str) left).value()); - Option rightS = temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); + Option rightS = + temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); if (leftS.isEmpty()) { throw new Error.Execution( "cannot find string in symbols for index " + ((Term.Str) left).value()); @@ -431,7 +436,8 @@ public void evaluate(Deque stack, Map variables, TemporarySymb case Suffix: if (right instanceof Term.Str && left instanceof Term.Str) { Option leftS = temporarySymbolTable.getSymbol((int) ((Term.Str) left).value()); - Option rightS = temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); + Option rightS = + temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); if (leftS.isEmpty()) { throw new Error.Execution( "cannot find string in symbols for index " + ((Term.Str) left).value()); @@ -446,7 +452,8 @@ public void evaluate(Deque stack, Map variables, TemporarySymb case Regex: if (right instanceof Term.Str && left instanceof Term.Str) { Option leftS = temporarySymbolTable.getSymbol((int) ((Term.Str) left).value()); - Option rightS = temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); + Option rightS = + temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); if (leftS.isEmpty()) { throw new Error.Execution( "cannot find string in symbols for index " + ((Term.Str) left).value()); @@ -474,7 +481,8 @@ public void evaluate(Deque stack, Map variables, TemporarySymb } if (right instanceof Term.Str && left instanceof Term.Str) { Option leftS = temporarySymbolTable.getSymbol((int) ((Term.Str) left).value()); - Option rightS = temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); + Option rightS = + temporarySymbolTable.getSymbol((int) ((Term.Str) right).value()); if (leftS.isEmpty()) { throw new Error.Execution( diff --git a/src/main/java/org/biscuitsec/biscuit/token/Authorizer.java b/src/main/java/org/biscuitsec/biscuit/token/Authorizer.java index d9892702..22fed3b5 100644 --- a/src/main/java/org/biscuitsec/biscuit/token/Authorizer.java +++ b/src/main/java/org/biscuitsec/biscuit/token/Authorizer.java @@ -4,6 +4,7 @@ import static io.vavr.API.Right; import io.vavr.Tuple2; +import io.vavr.Tuple5; import io.vavr.control.Either; import io.vavr.control.Option; import java.time.Instant; @@ -203,6 +204,53 @@ public Authorizer addToken(Biscuit token) throws Error.FailedLogic { return this; } + public Either>, Authorizer> addDatalog(String s) { + Either< + Map>, + Tuple5< + List, + List, + List, + List, + List>> + result = Parser.datalogComponents(s); + + if (result.isLeft()) { + Map> errors = + result.getLeft(); + Map> errorMap = new HashMap<>(); + for (Map.Entry> entry : + errors.entrySet()) { + List errorsList = new ArrayList<>(); + for (org.biscuitsec.biscuit.token.builder.parser.Error error : entry.getValue()) { + errorsList.add(new Error.Parser(error)); + } + errorMap.put(entry.getKey(), errorsList); + } + return Either.left(errorMap); + } + + Tuple5< + List, + List, + List, + List, + List> + components = result.get(); + components._1.forEach(this::addFact); + components._2.forEach(this::addRule); + components._3.forEach(this::addCheck); + components._4.forEach(this::addScope); + components._5.forEach(this::addPolicy); + + return Either.right(this); + } + + public Authorizer addScope(org.biscuitsec.biscuit.token.builder.Scope s) { + this.scopes.add(s.convert(symbolTable)); + return this; + } + public Authorizer addFact(org.biscuitsec.biscuit.token.builder.Fact fact) { world.addFact(Origin.authorizer(), fact.convert(symbolTable)); return this; @@ -274,7 +322,8 @@ public Authorizer addCheck(String s) throws Error.Parser { public Authorizer setTime() throws Error.Language { world.addFact( - Origin.authorizer(), Utils.fact("time", List.of(Utils.date(new Date()))).convert(symbolTable)); + Origin.authorizer(), + Utils.fact("time", List.of(Utils.date(new Date()))).convert(symbolTable)); return this; } @@ -649,7 +698,12 @@ public String formatWorld() { for (int j = 0; j < b.getChecks().size(); j++) { checks.add( - "Block[" + (i + 1) + "][" + j + "]: " + blockSymbolTable.formatCheck(b.getChecks().get(j))); + "Block[" + + (i + 1) + + "][" + + j + + "]: " + + blockSymbolTable.formatCheck(b.getChecks().get(j))); } } } @@ -691,7 +745,8 @@ public List>> getChecks() { List blockChecks = new ArrayList<>(); if (block.getExternalKey().isDefined()) { - SymbolTable blockSymbolTable = new SymbolTable(block.getSymbolTable(), block.getPublicKeys()); + SymbolTable blockSymbolTable = + new SymbolTable(block.getSymbolTable(), block.getPublicKeys()); for (org.biscuitsec.biscuit.datalog.Check check : block.getChecks()) { blockChecks.add(Check.convertFrom(check, blockSymbolTable)); } diff --git a/src/main/java/org/biscuitsec/biscuit/token/Biscuit.java b/src/main/java/org/biscuitsec/biscuit/token/Biscuit.java index f78110ac..dff6e9ba 100644 --- a/src/main/java/org/biscuitsec/biscuit/token/Biscuit.java +++ b/src/main/java/org/biscuitsec/biscuit/token/Biscuit.java @@ -241,7 +241,8 @@ public static Biscuit fromBytesWithSymbols(byte[] data, PublicKey root, SymbolTa * @param data * @return */ - public static Biscuit fromBytesWithSymbols(byte[] data, KeyDelegate delegate, SymbolTable symbolTable) + public static Biscuit fromBytesWithSymbols( + byte[] data, KeyDelegate delegate, SymbolTable symbolTable) throws NoSuchAlgorithmException, SignatureException, InvalidKeyException, Error { // System.out.println("will deserialize and verify token"); SerializedBiscuit ser = SerializedBiscuit.fromBytes(data, delegate); @@ -255,7 +256,8 @@ public static Biscuit fromBytesWithSymbols(byte[] data, KeyDelegate delegate, Sy * * @return */ - static Biscuit fromSerializedBiscuit(SerializedBiscuit ser, SymbolTable symbolTable) throws Error { + static Biscuit fromSerializedBiscuit(SerializedBiscuit ser, SymbolTable symbolTable) + throws Error { Tuple2> t = ser.extractBlocks(symbolTable); Block authority = t._1; ArrayList blocks = t._2; diff --git a/src/main/java/org/biscuitsec/biscuit/token/Block.java b/src/main/java/org/biscuitsec/biscuit/token/Block.java index c87ba63d..ae7b8451 100644 --- a/src/main/java/org/biscuitsec/biscuit/token/Block.java +++ b/src/main/java/org/biscuitsec/biscuit/token/Block.java @@ -485,7 +485,6 @@ public List getChecks() { return Collections.unmodifiableList(checks); } - public List getPublicKeys() { return Collections.unmodifiableList(this.publicKeys); } diff --git a/src/main/java/org/biscuitsec/biscuit/token/UnverifiedBiscuit.java b/src/main/java/org/biscuitsec/biscuit/token/UnverifiedBiscuit.java index dc49be95..fcc87701 100644 --- a/src/main/java/org/biscuitsec/biscuit/token/UnverifiedBiscuit.java +++ b/src/main/java/org/biscuitsec/biscuit/token/UnverifiedBiscuit.java @@ -87,8 +87,8 @@ public static UnverifiedBiscuit fromBytesWithSymbols(byte[] data, SymbolTable sy * * @return UnverifiedBiscuit */ - private static UnverifiedBiscuit fromSerializedBiscuit(SerializedBiscuit ser, SymbolTable symbolTable) - throws Error { + private static UnverifiedBiscuit fromSerializedBiscuit( + SerializedBiscuit ser, SymbolTable symbolTable) throws Error { Tuple2> t = ser.extractBlocks(symbolTable); Block authority = t._1; ArrayList blocks = t._2; diff --git a/src/main/java/org/biscuitsec/biscuit/token/builder/Expression.java b/src/main/java/org/biscuitsec/biscuit/token/builder/Expression.java index e2e99fef..e1d3473a 100644 --- a/src/main/java/org/biscuitsec/biscuit/token/builder/Expression.java +++ b/src/main/java/org/biscuitsec/biscuit/token/builder/Expression.java @@ -9,7 +9,8 @@ public abstract class Expression { - public final org.biscuitsec.biscuit.datalog.expressions.Expression convert(SymbolTable symbolTable) { + public final org.biscuitsec.biscuit.datalog.expressions.Expression convert( + SymbolTable symbolTable) { ArrayList ops = new ArrayList<>(); this.toOpcodes(symbolTable, ops); @@ -162,8 +163,9 @@ public Value(Term value) { } public void toOpcodes( - SymbolTable symbolTable, List ops) { - ops.add(new org.biscuitsec.biscuit.datalog.expressions.Op.Value(this.value.convert(symbolTable))); + SymbolTable symbolTable, List ops) { + ops.add( + new org.biscuitsec.biscuit.datalog.expressions.Op.Value(this.value.convert(symbolTable))); } public void gatherVariables(Set variables) { @@ -207,7 +209,7 @@ public Unary(Op op, Expression arg1) { } public void toOpcodes( - SymbolTable symbolTable, List ops) { + SymbolTable symbolTable, List ops) { this.arg1.toOpcodes(symbolTable, ops); switch (this.op) { @@ -286,7 +288,7 @@ public Binary(Op op, Expression arg1, Expression arg2) { } public void toOpcodes( - SymbolTable symbolTable, List ops) { + SymbolTable symbolTable, List ops) { this.arg1.toOpcodes(symbolTable, ops); this.arg2.toOpcodes(symbolTable, ops); diff --git a/src/main/java/org/biscuitsec/biscuit/token/builder/Scope.java b/src/main/java/org/biscuitsec/biscuit/token/builder/Scope.java index 4c0436e2..3c4047a6 100644 --- a/src/main/java/org/biscuitsec/biscuit/token/builder/Scope.java +++ b/src/main/java/org/biscuitsec/biscuit/token/builder/Scope.java @@ -67,7 +67,8 @@ public org.biscuitsec.biscuit.datalog.Scope convert(SymbolTable symbolTable) { } } - public static Scope convertFrom(org.biscuitsec.biscuit.datalog.Scope scope, SymbolTable symbolTable) { + public static Scope convertFrom( + org.biscuitsec.biscuit.datalog.Scope scope, SymbolTable symbolTable) { switch (scope.kind()) { case Authority: return new Scope(Kind.Authority); @@ -75,7 +76,8 @@ public static Scope convertFrom(org.biscuitsec.biscuit.datalog.Scope scope, Symb return new Scope(Kind.Previous); case PublicKey: // FIXME error management should bubble up here - return new Scope(Kind.PublicKey, symbolTable.getPublicKey((int) scope.getPublicKey()).get()); + return new Scope( + Kind.PublicKey, symbolTable.getPublicKey((int) scope.getPublicKey()).get()); default: return null; } diff --git a/src/main/java/org/biscuitsec/biscuit/token/builder/parser/Parser.java b/src/main/java/org/biscuitsec/biscuit/token/builder/parser/Parser.java index d5b3dfa9..0212743f 100644 --- a/src/main/java/org/biscuitsec/biscuit/token/builder/parser/Parser.java +++ b/src/main/java/org/biscuitsec/biscuit/token/builder/parser/Parser.java @@ -3,6 +3,7 @@ import biscuit.format.schema.Schema; import io.vavr.Tuple2; import io.vavr.Tuple4; +import io.vavr.Tuple5; import io.vavr.collection.Stream; import io.vavr.control.Either; import java.time.OffsetDateTime; @@ -34,16 +35,22 @@ private Parser() {} * *

If one succeeds it returns Right(Block) else it returns a Map[lineNumber, List[Error]] * - * @param index block index * @param s datalog string to parse - * @return Either>, Block> + * @return Either>, Tuple5, List, + * List, List, List>> */ - public static Either>, Block> datalog(long index, String s) { - Block blockBuilder = new Block(); + public static Either< + Map>, + Tuple5, List, List, List, List>> + datalogComponents(String s) { + List facts = new ArrayList<>(); + List rules = new ArrayList<>(); + List checks = new ArrayList<>(); + List scopes = new ArrayList<>(); + List policies = new ArrayList<>(); - // empty block code if (s.isEmpty()) { - return Either.right(blockBuilder); + return Either.right(new Tuple5<>(facts, rules, checks, scopes, policies)); } Map> errors = new HashMap<>(); @@ -69,7 +76,7 @@ public static Either>, Block> datalog(long index, Strin return false; }, r -> { - blockBuilder.addRule(r._2); + rules.add(r._2); return true; }); @@ -82,7 +89,7 @@ public static Either>, Block> datalog(long index, Strin return false; }, r -> { - blockBuilder.addFact(r._2); + facts.add(r._2); return true; }); } @@ -96,7 +103,7 @@ public static Either>, Block> datalog(long index, Strin return false; }, r -> { - blockBuilder.addCheck(r._2); + checks.add(r._2); return true; }); } @@ -110,7 +117,21 @@ public static Either>, Block> datalog(long index, Strin return false; }, r -> { - blockBuilder.addScope(r._2); + scopes.add(r._2); + return true; + }); + } + + if (!parsed) { + parsed = + policy(code) + .fold( + e -> { + lineErrors.add(e); + return false; + }, + r -> { + policies.add(r._2); return true; }); } @@ -127,6 +148,52 @@ public static Either>, Block> datalog(long index, Strin return Either.left(errors); } + return Either.right(new Tuple5<>(facts, rules, checks, scopes, policies)); + } + + /** + * Takes a datalog string with \n as datalog line separator. It + * tries to parse each + * line using fact, rule, check and scope sequentially. + * + *

+ * If one succeeds it returns Right(Block) else it returns a Map[lineNumber, + * List[Error]] + * + * @param index block index + * @param s datalog string to parse + * @return Either>, Block> + */ + public static Either>, Block> datalog(long index, String s) { + Block blockBuilder = new Block(); + + Either< + Map>, + Tuple5, List, List, List, List>> + result = datalogComponents(s); + + if (result.isLeft()) { + return Either.left(result.getLeft()); + } + + Tuple5, List, List, List, List> components = + result.get(); + + if (!components._5.isEmpty()) { + return Either.left( + Map.of( + -1, // we don't have a line number for policies + List.of( + new Error( + s, + "Policies must be empty but found " + components._5.size() + " policies")))); + } + + components._1.forEach(blockBuilder::addFact); + components._2.forEach(blockBuilder::addRule); + components._3.forEach(blockBuilder::addCheck); + components._4.forEach(blockBuilder::addScope); + return Either.right(blockBuilder); } diff --git a/src/test/java/org/biscuitsec/biscuit/builder/parser/ParserTest.java b/src/test/java/org/biscuitsec/biscuit/builder/parser/ParserTest.java index 99d1fd38..e3205715 100644 --- a/src/test/java/org/biscuitsec/biscuit/builder/parser/ParserTest.java +++ b/src/test/java/org/biscuitsec/biscuit/builder/parser/ParserTest.java @@ -275,7 +275,7 @@ void testCheck() { new Tuple2<>( "", new Check( - ONE, + ONE, Arrays.asList( Utils.rule( "query", diff --git a/src/test/java/org/biscuitsec/biscuit/token/AuthorizerTest.java b/src/test/java/org/biscuitsec/biscuit/token/AuthorizerTest.java index 5f57a096..0e0f2c56 100644 --- a/src/test/java/org/biscuitsec/biscuit/token/AuthorizerTest.java +++ b/src/test/java/org/biscuitsec/biscuit/token/AuthorizerTest.java @@ -1,6 +1,7 @@ package org.biscuitsec.biscuit.token; import static org.biscuitsec.biscuit.token.builder.Utils.constrainedRule; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import biscuit.format.schema.Schema; @@ -73,6 +74,35 @@ public void testPuttingSomeFactsInBiscuitAndGettingThemBackOutAgain() throws Exc ((Term.Set) permsTerm).getValue()); } + @Test + public void testDatalogAuthorizer() throws Exception { + KeyPair keypair = KeyPair.generate(Schema.PublicKey.Algorithm.Ed25519, new SecureRandom()); + + Biscuit token = + Biscuit.builder(keypair) + .addAuthorityFact("email(\"bob@example.com\")") + .addAuthorityFact("id(123)") + .addAuthorityFact("enabled(true)") + .addAuthorityFact("perms([1,2,3])") + .build(); + + Authorizer authorizer = + Biscuit.fromBase64Url(token.serializeBase64Url(), keypair.getPublicKey()) + .verify(keypair.getPublicKey()) + .authorizer(); + + String l0 = "right($email) <- email($email)"; + String l1 = "check if right(\"bob@example.com\")"; + String l2 = "allow if true"; + String datalog = String.join(";", Arrays.asList(l0, l1, l2)); + authorizer.addDatalog(datalog); + + assertDoesNotThrow(() -> authorizer.authorize()); + + Term emailTerm = queryFirstResult(authorizer, "right($address) <- email($address)"); + assertEquals("bob@example.com", ((Term.Str) emailTerm).getValue()); + } + private static Term queryFirstResult(Authorizer authorizer, String query) throws Error { return authorizer.query(query).iterator().next().terms().get(0); } diff --git a/src/test/java/org/biscuitsec/biscuit/token/BiscuitTest.java b/src/test/java/org/biscuitsec/biscuit/token/BiscuitTest.java index 84e73077..17d42807 100644 --- a/src/test/java/org/biscuitsec/biscuit/token/BiscuitTest.java +++ b/src/test/java/org/biscuitsec/biscuit/token/BiscuitTest.java @@ -25,12 +25,10 @@ import java.util.Arrays; import java.util.Date; import java.util.List; - import org.biscuitsec.biscuit.crypto.KeyDelegate; import org.biscuitsec.biscuit.crypto.KeyPair; import org.biscuitsec.biscuit.crypto.PublicKey; import org.biscuitsec.biscuit.datalog.RunLimits; -import org.biscuitsec.biscuit.datalog.SymbolTable; import org.biscuitsec.biscuit.error.Error; import org.biscuitsec.biscuit.error.FailedCheck; import org.biscuitsec.biscuit.error.LogicError; @@ -82,7 +80,7 @@ public void testBasic() check( rule( "caveat1", - List.of(var("resource")), + List.of(var("resource")), Arrays.asList( pred("resource", List.of(var("resource"))), pred("operation", List.of(str("read"))), @@ -115,8 +113,8 @@ public void testBasic() check( rule( "caveat2", - List.of(str("file1")), - List.of(pred("resource", List.of(str("file1"))))))); + List.of(str("file1")), + List.of(pred("resource", List.of(str("file1"))))))); Biscuit b3 = deser2.attenuate(rng, keypair3, builder3); @@ -441,7 +439,7 @@ public void testBasicWithNamespaces() check( rule( "caveat1", - List.of(var("resource")), + List.of(var("resource")), Arrays.asList( pred("resource", List.of(var("resource"))), pred("operation", List.of(str("read"))), @@ -474,8 +472,8 @@ public void testBasicWithNamespaces() check( rule( "caveat2", - List.of(str("file1")), - List.of(pred("resource", List.of(str("file1"))))))); + List.of(str("file1")), + List.of(pred("resource", List.of(str("file1"))))))); Biscuit b3 = deser2.attenuate(rng, keypair3, builder3); @@ -571,7 +569,7 @@ public void testBasicWithNamespacesWithAddAuthorityFact() check( rule( "caveat1", - List.of(var("resource")), + List.of(var("resource")), Arrays.asList( pred("resource", List.of(var("resource"))), pred("operation", List.of(str("read"))), @@ -604,8 +602,8 @@ public void testBasicWithNamespacesWithAddAuthorityFact() check( rule( "caveat2", - List.of(str("file1")), - List.of(pred("resource", List.of(str("file1"))))))); + List.of(str("file1")), + List.of(pred("resource", List.of(str("file1"))))))); Biscuit b3 = deser2.attenuate(rng, keypair3, builder3); @@ -762,12 +760,12 @@ public void testCheckAll() new Error.FailedLogic( new LogicError.Unauthorized( new LogicError.MatchedPolicy.Allow(0), - List.of( - new FailedCheck.FailedBlock( - 0, - 0, - "check all operation($op), allowed_operations($allowed)," - + " $allowed.contains($op)")))), + List.of( + new FailedCheck.FailedBlock( + 0, + 0, + "check all operation($op), allowed_operations($allowed)," + + " $allowed.contains($op)")))), e); } diff --git a/src/test/java/org/biscuitsec/biscuit/token/ExampleTest.java b/src/test/java/org/biscuitsec/biscuit/token/ExampleTest.java index 70faef91..f8fbb275 100644 --- a/src/test/java/org/biscuitsec/biscuit/token/ExampleTest.java +++ b/src/test/java/org/biscuitsec/biscuit/token/ExampleTest.java @@ -39,5 +39,4 @@ public Biscuit attenuate(KeyPair root, byte[] serializedToken) Block block = token.createBlock().addCheck("check if operation(\"read\")"); return token.attenuate(block, root.getPublicKey().getAlgorithm()); } - } diff --git a/src/test/java/org/biscuitsec/biscuit/token/SamplesTest.java b/src/test/java/org/biscuitsec/biscuit/token/SamplesTest.java index addfcd77..0022d47e 100644 --- a/src/test/java/org/biscuitsec/biscuit/token/SamplesTest.java +++ b/src/test/java/org/biscuitsec/biscuit/token/SamplesTest.java @@ -173,8 +173,7 @@ DynamicTest processTestcase( System.out.println( Arrays.toString(token.serializedBiscuit.getAuthority().getBlock())); org.biscuitsec.biscuit.token.Block deserBlockAuthority = - fromBytes(serBlockAuthority, token.authority.getExternalKey()) - .get(); + fromBytes(serBlockAuthority, token.authority.getExternalKey()).get(); assertEquals( token.authority.print(token.symbolTable), deserBlockAuthority.print(token.symbolTable)); @@ -189,7 +188,8 @@ DynamicTest processTestcase( org.biscuitsec.biscuit.token.Block deserBlock = fromBytes(serBlock, block.getExternalKey()).get(); assertEquals( - block.print(token.symbolTable), deserBlock.print(token.symbolTable)); + block.print(token.symbolTable), + deserBlock.print(token.symbolTable)); assert (Arrays.equals(serBlock, signedBlock.getBlock())); } @@ -300,8 +300,10 @@ DynamicTest processTestcase( class Block { List symbols; String code; + @SuppressWarnings("checkstyle:MemberName") List public_keys; + @SuppressWarnings("checkstyle:MemberName") String external_key; @@ -414,6 +416,7 @@ public void setRoot_public_key(String root_public_key) { @SuppressWarnings("checkstyle:MemberName") String root_public_key; + List testcases; @SuppressWarnings("checkstyle:MethodName")