Skip to content

Commit

Permalink
compare rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Jan 8, 2024
1 parent cbfa5a8 commit 0870f92
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public String print_scope(final Scope scope) {
case PublicKey:
Option<PublicKey> pk = this.get_pk((int) scope.publicKey);
if(pk.isDefined()) {
return pk.toString();
return pk.get().toString();
}
}
return "?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public String print(Deque<String> stack, SymbolTable symbols) {
String _s = "";
switch (this.op) {
case Negate:
_s = "! " + prec;
_s = "!" + prec;
stack.push(_s);
break;
case Parens:
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/biscuitsec/biscuit/token/Authorizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -631,15 +631,11 @@ public String print_world() {
}

public FactSet facts() {
return this.world.facts();/*.stream()
.map((f) -> org.biscuitsec.biscuit.token.builder.Fact.convert_from(f, this.symbols))
.collect(Collectors.toList());*/
return this.world.facts();
}

public RuleSet rules() {
return this.world.rules();/*.stream()
.map((r) -> org.biscuitsec.biscuit.token.builder.Rule.convert_from(r, this.symbols))
.collect(Collectors.toList());*/
return this.world.rules();
}

public List<Tuple2<Long, List<Check>>> checks() {
Expand Down
50 changes: 43 additions & 7 deletions src/test/java/org/biscuitsec/biscuit/token/SamplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,18 @@ DynamicTest process_testcase(final TestCase testCase, final PublicKey publicKey,
world.fixOrigin();
System.out.println("fixed origin");


World authorizerWorld = new World(authorizer);


System.out.println("validation world"+world);
System.out.println("authorizer world"+authorizerWorld);

assertEquals(world.factMap(), authorizerWorld.factMap());

/*assertEquals(world.rules.size(), authorizerWorld.rules.size());
assertEquals(world.rules.size(), authorizerWorld.rules.size());
for (int i = 0; i < world.rules.size(); i++) {
assertEquals(world.rules.get(i), authorizerWorld.rules.get(i));
}
assertEquals(world.checks.size(), authorizerWorld.checks.size());
/*assertEquals(world.checks.size(), authorizerWorld.checks.size());
for (int i = 0; i < world.checks.size(); i++) {
assertEquals(world.checks.get(i), authorizerWorld.checks.get(i));
}
Expand All @@ -129,12 +127,15 @@ DynamicTest process_testcase(final TestCase testCase, final PublicKey publicKey,
System.out.println(world.facts);
System.out.println(authorizerWorld.facts);
assertEquals(world.factMap(), authorizerWorld.factMap());

/*assertEquals(world.rules.size(), authorizerWorld.rules.size());

System.out.println(world.rules);
System.out.println(authorizerWorld.rules);

assertEquals(world.rules.size(), authorizerWorld.rules.size());
for (int i = 0; i < world.rules.size(); i++) {
assertEquals(world.rules.get(i), authorizerWorld.rules.get(i));
}
assertEquals(world.checks.size(), authorizerWorld.checks.size());
/*assertEquals(world.checks.size(), authorizerWorld.checks.size());
for (int i = 0; i < world.checks.size(); i++) {
assertEquals(world.checks.get(i), authorizerWorld.checks.get(i));
}
Expand Down Expand Up @@ -381,6 +382,7 @@ public void fixOrigin() {
this.origin.set(i, Long.MAX_VALUE);
}
}
Collections.sort(this.origin);

System.out.println("->: "+this.origin);

Expand Down Expand Up @@ -434,6 +436,32 @@ public int compareTo(RuleSet ruleSet) {
return this.origin.compareTo(ruleSet.origin);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

RuleSet ruleSet = (RuleSet) o;

if (!Objects.equals(origin, ruleSet.origin)) return false;
return Objects.equals(rules, ruleSet.rules);
}

@Override
public int hashCode() {
int result = origin != null ? origin.hashCode() : 0;
result = 31 * result + (rules != null ? rules.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "RuleSet{" +
"origin=" + origin +
", rules=" + rules +
'}';
}
}

class CheckSet implements Comparable<RuleSet> {
Expand Down Expand Up @@ -462,6 +490,14 @@ public int compareTo(RuleSet ruleSet) {
return this.origin.compareTo(ruleSet.origin);
}
}

@Override
public String toString() {
return "CheckSet{" +
"origin=" + origin +
", checks=" + checks +
'}';
}
}

}

0 comments on commit 0870f92

Please sign in to comment.