Skip to content

Commit

Permalink
Fix NULL handling for both arguments of sec_check_authz()
Browse files Browse the repository at this point in the history
  • Loading branch information
larsw committed Jan 16, 2024
1 parent 647fff2 commit 53eacad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pg_test = []

[dependencies]
#accumulo-access = { path = "../accumulo-access-rs/accumulo-access", features = ["caching"] } # for local dev
accumulo-access = "0.1.3"
accumulo-access = "0.1"
pgrx = "=0.11.2"
serde = { version = "1.0.194", features = ["derive"] }
serde = { version = "1.0.195", features = ["derive"] }

[dev-dependencies]
pgrx-tests = "=0.11.2"
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ use serde::{Deserialize, Serialize};
pg_module_magic!();

#[pg_extern]
fn sec_authz_check(expression: String, tokens: String) -> bool {
fn sec_authz_check(expression: Option<String>, tokens: Option<String>) -> bool {
if expression.is_none() || tokens.is_none() {
return false;
}
let expression = expression.unwrap();
let tokens = tokens.unwrap();

if expression.is_empty() {
return false;
}
if tokens.is_empty() {
return false;
}
match check_authorization_csv(expression, tokens) {
Ok(result) => result,
Err(e) => {
Expand Down Expand Up @@ -56,7 +68,7 @@ mod tests {
fn test_accumulo_check_authorization() {
let expression = String::from("label1 & label5 & (label2 | \"label 🕺\")");
let tokens = String::from("label1,label5,label 🕺");
assert_eq!(true, crate::sec_authz_check(expression, tokens));
assert_eq!(true, crate::sec_authz_check(Some(expression), Some(tokens)));
}
}

Expand Down

0 comments on commit 53eacad

Please sign in to comment.