Skip to content

Commit 896d5fb

Browse files
Merge pull request #226 from Tcode-Motion/add-http-capability-denied-test-8240489410032386587
🧪 [testing improvement: Add tests for std.http capability denied error path]
2 parents 40a5530 + e5251ae commit 896d5fb

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

‎stdlib/tests/stdlib_tests.rs‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::cell::RefCell;
22
use std::collections::HashSet;
33
use std::rc::Rc;
4-
use techscript_runtime::{context::Capability, value::RuntimeValue, RuntimeConfig, RuntimeContext};
4+
use techscript_runtime::{
5+
context::Capability, error::RuntimeErrorKind, value::RuntimeValue, RuntimeConfig,
6+
RuntimeContext,
7+
};
58
use techscript_stdlib::StdlibRegistry;
69

710
#[test]
@@ -472,6 +475,33 @@ fn test_web_module() {
472475
let _ = stop.call(&mut ctx, vec![]).unwrap();
473476
}
474477

478+
#[test]
479+
fn test_http_module_capability_denied() {
480+
let registry = StdlibRegistry::new();
481+
let http = registry.get_module("std.http").unwrap();
482+
483+
let mut config_unprivileged = RuntimeConfig::default();
484+
config_unprivileged
485+
.capabilities
486+
.remove(&Capability::Network);
487+
let mut ctx_unprivileged = RuntimeContext::new(config_unprivileged);
488+
489+
let get = http.exports.get("get").unwrap();
490+
let res = get.call(
491+
&mut ctx_unprivileged,
492+
vec![RuntimeValue::Str("http://example.com".to_string())],
493+
);
494+
495+
assert!(res.is_err());
496+
let err = res.unwrap_err();
497+
match err.kind {
498+
RuntimeErrorKind::InvalidOperation(msg) => {
499+
assert!(msg.contains("Security policy violation: Network capability is denied"));
500+
}
501+
_ => panic!("Expected InvalidOperation error"),
502+
}
503+
}
504+
475505
#[test]
476506
fn test_http_module() {
477507
use std::io::{Read, Write};

0 commit comments

Comments
 (0)