Skip to content

Commit ea58fa1

Browse files
Fix protobuf parsing for unrecognized extension functions (#517)
Signed-off-by: John Kastner <[email protected]>
1 parent d8f5cdb commit ea58fa1

28 files changed

+168
-163
lines changed

cedar-drt/fuzz/src/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub fn run_pe_test(
8484
TestResult::Failure(err) => {
8585
// TODO(#175): Ignore cases where the definitional code returned an error due to
8686
// an unknown extension function.
87-
if err.contains("jsonToExtFun: unknown extension function") {
87+
if err.contains("unknown extension function") {
8888
return;
8989
}
9090
// No other errors are expected
@@ -139,7 +139,7 @@ pub fn run_eval_test(
139139
TestResult::Failure(err) => {
140140
// TODO(#175): Ignore cases where the definitional code returned an error due to
141141
// an unknown extension function.
142-
if err.contains("jsonToExtFun: unknown extension function") {
142+
if err.contains("unknown extension function") {
143143
return;
144144
}
145145
// No other errors are expected
@@ -176,7 +176,7 @@ pub fn run_auth_test(
176176
TestResult::Failure(err) => {
177177
// TODO(#175): For now, ignore cases where the Lean code returned an error due to
178178
// an unknown extension function.
179-
if err.contains("jsonToExtFun: unknown extension function") {
179+
if err.contains("unknown extension function") {
180180
rust_res
181181
} else {
182182
panic!(
@@ -249,7 +249,9 @@ pub fn run_val_test(
249249
TestResult::Failure(err) => {
250250
// TODO(#175): For now, ignore cases where the Lean code returned an error due to
251251
// an unknown extension function.
252-
if !err.contains("jsonToExtFun: unknown extension function") {
252+
if !err.contains("unknown extension function")
253+
&& !err.contains("unknown extension type")
254+
{
253255
panic!(
254256
"Unexpected error\nPolicies:\n{}\nSchema:\n{:?}\nError: {err}",
255257
&policies, schema

cedar-drt/src/lean_impl.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use lean_sys::{
3838
lean_alloc_sarray, lean_dec, lean_dec_ref, lean_finalize_thread,
3939
lean_initialize_runtime_module_locked, lean_initialize_thread, lean_io_mark_end_initialization,
4040
lean_io_mk_world, lean_io_result_is_ok, lean_io_result_show_error, lean_sarray_object,
41-
lean_string_cstr,
41+
lean_set_exit_on_panic, lean_string_cstr,
4242
};
4343
use log::info;
4444
use miette::miette;
@@ -167,6 +167,8 @@ impl LeanDefinitionalEngine {
167167
panic!("Failed to initialize Lean");
168168
}
169169
lean_io_mark_end_initialization();
170+
// If we don't explicitly set this, Lean does not abort after hitting a panic
171+
lean_set_exit_on_panic(true);
170172
};
171173
});
172174
unsafe { lean_initialize_thread() };

cedar-lean/CedarProto/ActionConstraint.lean

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn ActionScope.In) := do
7373
match t.fieldNum with
7474
| 1 =>
7575
let x : Repeated EntityUID ← Field.guardedParse t
76-
pure (mergeEuids · x)
76+
pure (pure $ mergeEuids · x)
7777
| _ =>
7878
t.wireType.skip
7979
pure ignore
@@ -105,7 +105,7 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn ActionScope.Eq) := do
105105
match t.fieldNum with
106106
| 1 =>
107107
let x : EntityUID ← Field.guardedParse t
108-
pure (mergeEuid · x)
108+
pure (pure $ mergeEuid · x)
109109
| _ =>
110110
t.wireType.skip
111111
pure ignore
@@ -157,13 +157,13 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn ActionScope) := do
157157
match t.fieldNum with
158158
| 1 =>
159159
let x : Proto.ActionScope.Ty ← Field.guardedParse t
160-
pure (mergeTy · x)
160+
pure (pure $ mergeTy · x)
161161
| 2 =>
162162
let x : Proto.ActionScope.In ← Field.guardedParse t
163-
pure (mergeIn · x)
163+
pure (pure $ mergeIn · x)
164164
| 3 =>
165165
let x : Proto.ActionScope.Eq ← Field.guardedParse t
166-
pure (mergeEq · x)
166+
pure (pure $ mergeEq · x)
167167
| _ =>
168168
t.wireType.skip
169169
pure ignore

cedar-lean/CedarProto/AuthorizationRequest.lean

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn AuthorizationRequest) := do
6262
match t.fieldNum with
6363
| 1 =>
6464
let x : Request ← Field.guardedParse t
65-
pure (mergeRequest · x)
65+
pure (pure $ mergeRequest · x)
6666
| 2 =>
6767
let x : Policies ← Field.guardedParse t
68-
pure (mergePolicies · x)
68+
pure (pure $ mergePolicies · x)
6969
| 3 =>
7070
let x : Entities ← Field.guardedParse t
71-
pure (mergeEntities · x)
71+
pure (pure $ mergeEntities · x)
7272
| _ =>
7373
t.wireType.skip
7474
pure ignore

cedar-lean/CedarProto/Context.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn Context) := do
4848
match t.fieldNum with
4949
| 1 =>
5050
let x : Value ← Field.guardedParse t
51-
pure (mergeValue · x)
51+
pure (pure $ mergeValue · x)
5252
| _ =>
5353
t.wireType.skip
5454
pure ignore

cedar-lean/CedarProto/Entities.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn EntitiesProto) := do
5151
match t.fieldNum with
5252
| 1 =>
5353
let x : Repeated EntityProto ← Field.guardedParse t
54-
pure (mergeEntities · x)
54+
pure (pure $ mergeEntities · x)
5555
-- Ignoring 3 | mode
5656
| _ =>
5757
t.wireType.skip

cedar-lean/CedarProto/Entity.lean

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn EntityProto) := do
7979
match t.fieldNum with
8080
| 1 =>
8181
let x : EntityUID ← Field.guardedParse t
82-
pure (mergeUid · x)
82+
pure (pure $ mergeUid · x)
8383
| 2 =>
8484
let x : Proto.Map String Value ← Field.guardedParse t
85-
pure (mergeAttrs · x)
85+
pure (pure $ mergeAttrs · x)
8686
| 3 =>
8787
let x : Repeated EntityUID ← Field.guardedParse t
88-
pure (mergeAncestors · x)
88+
pure (pure $ mergeAncestors · x)
8989
| 4 =>
9090
let x : Proto.Map String Value ← Field.guardedParse t
91-
pure (mergeTags · x)
91+
pure (pure $ mergeTags · x)
9292
| _ =>
9393
t.wireType.skip
9494
pure ignore

cedar-lean/CedarProto/EntityReference.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn EntityUIDOrSlot) := do
7474
match t.fieldNum with
7575
| 1 =>
7676
let x : Proto.EntityReferenceType ← Field.guardedParse t
77-
pure (mergeTy · x)
77+
pure (pure $ mergeTy · x)
7878
| 2 =>
7979
let x : EntityUID ← Field.guardedParse t
80-
pure (mergeEuid · x)
80+
pure (pure $ mergeEuid · x)
8181
| _ =>
8282
t.wireType.skip
8383
pure ignore

cedar-lean/CedarProto/EntityType.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn EntityTypeProto) := do
4747
match t.fieldNum with
4848
| 1 =>
4949
let x : Name ← Field.guardedParse t
50-
pure (mergeName · x)
50+
pure (pure $ mergeName · x)
5151
| _ =>
5252
t.wireType.skip
5353
pure ignore

cedar-lean/CedarProto/EntityUID.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn EntityUID) := do
5555
match t.fieldNum with
5656
| 1 =>
5757
let x : EntityTypeProto ← Field.guardedParse t
58-
pure (mergeTy · x)
58+
pure (pure $ mergeTy · x)
5959
| 2 =>
6060
let x : String ← Field.guardedParse t
61-
pure (mergeEid · x)
61+
pure (pure $ mergeEid · x)
6262
| _ =>
6363
t.wireType.skip
6464
pure ignore

cedar-lean/CedarProto/EntityUIDEntry.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def parseField (t : Proto.Tag) : BParsec (MergeFn EntityUIDEntry) := do
4242
match t.fieldNum with
4343
| 1 =>
4444
let x : EntityUID ← Field.guardedParse t
45-
pure (mergeEuid · x)
45+
pure (pure $ mergeEuid · x)
4646
| _ =>
4747
t.wireType.skip
4848
pure ignore

0 commit comments

Comments
 (0)