Fix: Correctly implement none for Capabilities (#4218)

This commit is contained in:
Gerard Guillemas Martos 2024-06-18 20:49:12 +02:00 committed by GitHub
parent befb185f1d
commit 24c8b06c93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View file

@ -278,6 +278,19 @@ impl Capabilities {
}
}
pub fn none() -> Self {
Self {
scripting: false,
guest_access: false,
live_query_notifications: false,
allow_funcs: Arc::new(Targets::None),
deny_funcs: Arc::new(Targets::None),
allow_net: Arc::new(Targets::None),
deny_net: Arc::new(Targets::None),
}
}
pub fn with_scripting(mut self, scripting: bool) -> Self {
self.scripting = scripting;
self

View file

@ -131,7 +131,7 @@ impl Capabilities {
/// Create a builder with all capabilities disabled.
pub fn none() -> Self {
Capabilities {
cap: CoreCapabilities::default(),
cap: CoreCapabilities::none(),
allow_funcs: Targets::None,
deny_funcs: Targets::None,
allow_net: Targets::None,

View file

@ -809,7 +809,6 @@ mod cli_integration {
}
#[test(tokio::test)]
#[ignore]
async fn test_capabilities() {
// Default capabilities only allow functions
info!("* When default capabilities");
@ -893,11 +892,11 @@ mod cli_integration {
let query = format!("RETURN http::get('http://{}/version');\n\n", addr);
let output = common::run(&cmd).input(&query).output().unwrap();
assert!(output.starts_with("['surrealdb"), "unexpected output: {output:?}");
assert!(output.contains("['surrealdb-"), "unexpected output: {output:?}");
let query = "RETURN function() { return '1' };";
let output = common::run(&cmd).input(query).output().unwrap();
assert!(output.starts_with("['1']"), "unexpected output: {output:?}");
assert!(output.contains("['1']"), "unexpected output: {output:?}");
server.finish().unwrap();
}
@ -969,7 +968,7 @@ mod cli_integration {
let query = format!("RETURN http::get('http://{}/version');\n\n", addr);
let output = common::run(&cmd).input(&query).output().unwrap();
assert!(output.starts_with("['surrealdb"), "unexpected output: {output:?}");
assert!(output.contains("['surrealdb-"), "unexpected output: {output:?}");
server.finish().unwrap();
}