Skip to content

Commit

Permalink
fix the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Jun 16, 2024
1 parent dbf40c6 commit ecd235c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import biscuit.format.schema.Schema;
import io.vavr.control.Either;
import io.vavr.control.Option;
import net.i2p.crypto.eddsa.EdDSAEngine;
import org.biscuitsec.biscuit.crypto.KeyPair;
import org.biscuitsec.biscuit.crypto.PublicKey;
Expand Down Expand Up @@ -30,7 +31,7 @@ public Either<Error.FormatError, ThirdPartyBlock> createBlock(KeyPair keyPair, B
symbols.insert(pk);
}

org.biscuitsec.biscuit.token.Block block = blockBuilder.build(symbols);
org.biscuitsec.biscuit.token.Block block = blockBuilder.build(symbols, Option.some(keyPair.public_key()));
block.version = SerializedBiscuit.MAX_SCHEMA_VERSION;

Either<Error.FormatError, byte[]> res = block.to_bytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static Either<Error, org.biscuitsec.biscuit.crypto.PublicKey> verifyBlockSignatu
algo_buf2.putInt(Integer.valueOf(publicKey.algorithm.getNumber()));
algo_buf2.flip();

Signature sgr2 = new EdDSAEngine(MessageDigest.getInstance(org.biscuitsec.biscuit.crypto.KeyPair.ed25519.getHashAlgorithm()));
Signature sgr2 = new EdDSAEngine(MessageDigest.getInstance(KeyPair.ed25519.getHashAlgorithm()));
sgr2.initVerify(signedBlock.externalSignature.get().key.key);
sgr2.update(block);
sgr2.update(algo_buf2);
Expand Down
20 changes: 5 additions & 15 deletions src/test/java/org/biscuitsec/biscuit/token/ThirdPartyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class ThirdPartyTest {
@Test
public void testBasic() throws NoSuchAlgorithmException, SignatureException, InvalidKeyException, CloneNotSupportedException, Error {
public void testRoundTrip() throws NoSuchAlgorithmException, SignatureException, InvalidKeyException, CloneNotSupportedException, Error {
byte[] seed = {0, 0, 0, 0};
SecureRandom rng = new SecureRandom(seed);

Expand All @@ -35,10 +35,9 @@ public void testBasic() throws NoSuchAlgorithmException, SignatureException, Inv
KeyPair external = new KeyPair(rng);
System.out.println("external: ed25519/"+external.public_key().toHex());


org.biscuitsec.biscuit.token.builder.Block authority_builder = new Block();
authority_builder.add_fact("right(\"read\")");
authority_builder.add_check("check if group(\"admin\") trusting ed25519/D75712CB4091E53D850E032DFBCD8D003CA9BD1B60BAFF4D92DC98145448BCC5");
authority_builder.add_check("check if group(\"admin\") trusting ed25519/"+external.public_key().toHex());

Biscuit b1 = Biscuit.make(rng, root, authority_builder.build());
ThirdPartyRequest request = b1.thirdPartyRequest();
Expand All @@ -63,26 +62,17 @@ public void testBasic() throws NoSuchAlgorithmException, SignatureException, Inv
Authorizer authorizer2 = deser.authorizer();
authorizer2.add_fact("resource(\"file2\")");
authorizer2.add_policy("allow if true");
authorizer2.authorize(new RunLimits(500, 100, Duration.ofMillis(500)));

/*try {
try {
authorizer2.authorize(new RunLimits(500, 100, Duration.ofMillis(500)));
} catch (Error e) {
System.out.println(e);
assertEquals(
new Error.FailedLogic(new LogicError.Unauthorized(new LogicError.MatchedPolicy.Allow(0), Arrays.asList(
new FailedCheck.FailedBlock(1, 0, "check if resource($resource), operation(\"read\"), right($resource, \"read\")"),
new FailedCheck.FailedBlock(2, 0, "check if resource(\"file1\")")
new FailedCheck.FailedBlock(1, 0, "check if resource(\"file1\")")
))),
e);
}
assertThrows(InvalidKeyException.class, () -> {
Biscuit deser = Biscuit.from_bytes(data, new KeyDelegate() {
@Override
public Option<PublicKey> root_key(Option<Integer> key_id) {
return Option.none();
}
});
});*/

}
}

0 comments on commit ecd235c

Please sign in to comment.