-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
samples verify block by block #88
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
45a163c
match sample.json model
KannarFr 2b7aa44
add datalog parser for block
KannarFr 0eae499
add symbol table constructor from symbols
KannarFr 80cecfa
add pk
KannarFr 76fa45e
block enable to add symbol
KannarFr 903ebea
use long
KannarFr 4ceee3a
wip: add block comparison between sample definition and its serializa…
KannarFr ee11ee6
Update src/main/java/org/biscuitsec/biscuit/datalog/SymbolTable.java
Geal 2cf6c01
Update src/main/java/org/biscuitsec/biscuit/datalog/SymbolTable.java
Geal ba50c18
Merge branch 'master' into verifyBlocks
Geal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,47 @@ Stream<DynamicTest> jsonTest() { | |
return sample.testcases.stream().map(t -> process_testcase(t, publicKey, keyPair)); | ||
} | ||
|
||
void compareBlocks(List<Block> sampleBlocks, List<org.biscuitsec.biscuit.token.Block> blocks) { | ||
assertEquals(sampleBlocks.size(), blocks.size()); | ||
List<Tuple2<Block, org.biscuitsec.biscuit.token.Block>> comparisonList = IntStream.range(0, sampleBlocks.size()) | ||
.mapToObj(i -> new Tuple2<>(sampleBlocks.get(i), blocks.get(i))) | ||
.collect(Collectors.toList()); | ||
|
||
// for each token we start from the base symbol table | ||
SymbolTable baseSymbols = new SymbolTable(); | ||
|
||
io.vavr.collection.Stream.ofAll(comparisonList).zipWithIndex().forEach(indexedItem -> { | ||
compareBlock(baseSymbols, indexedItem._2, indexedItem._1._1, indexedItem._1._2); | ||
}); | ||
} | ||
|
||
void compareBlock(SymbolTable baseSymbols, long sampleBlockIndex, Block sampleBlock, org.biscuitsec.biscuit.token.Block block) { | ||
Option<PublicKey> sampleExternalKey = sampleBlock.getExternalKey(); | ||
List<PublicKey> samplePublicKeys = sampleBlock.getPublicKeys(); | ||
String sampleDatalog = sampleBlock.getCode().replace("\"","\\\""); | ||
SymbolTable sampleSymbols = new SymbolTable(sampleBlock.symbols); | ||
|
||
Either<Map<Integer, List<org.biscuitsec.biscuit.token.builder.parser.Error>>, org.biscuitsec.biscuit.token.builder.Block> outputSample = Parser.datalog(sampleBlockIndex, baseSymbols, sampleDatalog); | ||
assertTrue(outputSample.isRight()); | ||
|
||
if (!block.publicKeys.isEmpty()) { | ||
outputSample.get().addPublicKeys(samplePublicKeys); | ||
} | ||
|
||
if (!block.externalKey.isDefined()) { | ||
sampleSymbols.symbols.forEach(baseSymbols::add); | ||
} else { | ||
SymbolTable freshSymbols = new SymbolTable(); | ||
sampleSymbols.symbols.forEach(freshSymbols::add); | ||
outputSample.get().setExternalKey(sampleExternalKey); | ||
} | ||
|
||
System.out.println(outputSample.get().build().print(sampleSymbols)); | ||
System.out.println(block.symbols.symbols); | ||
System.out.println(block.print(sampleSymbols)); | ||
assertArrayEquals(outputSample.get().build().to_bytes().get(), block.to_bytes().get()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, this should show the expected and actual arrays, because the errors don't help https://github.com/biscuit-auth/biscuit-java/actions/runs/8622173639/job/23632740026?pr=88#step:5:6259 |
||
} | ||
|
||
DynamicTest process_testcase(final TestCase testCase, final PublicKey publicKey, final KeyPair privateKey) { | ||
return DynamicTest.dynamicTest(testCase.title + ": "+testCase.filename, () -> { | ||
System.out.println("Testcase name: \""+testCase.title+"\""); | ||
|
@@ -63,6 +104,12 @@ DynamicTest process_testcase(final TestCase testCase, final PublicKey publicKey, | |
Biscuit token = Biscuit.from_bytes(data, publicKey); | ||
assertArrayEquals(token.serialize(), data); | ||
|
||
List<org.biscuitsec.biscuit.token.Block> allBlocks = new ArrayList<>(); | ||
allBlocks.add(token.authority); | ||
allBlocks.addAll(token.blocks); | ||
|
||
compareBlocks(testCase.token, allBlocks); | ||
|
||
List<RevocationIdentifier> revocationIds = token.revocation_identifiers(); | ||
JsonArray validationRevocationIds = validation.getAsJsonArray("revocation_ids"); | ||
assertEquals(revocationIds.size(), validationRevocationIds.size()); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should show the input that was parsed and the error we got, otherwise we don't have any context to fix it