|
6 | 6 |
|
7 | 7 | using namespace icinga; |
8 | 8 |
|
9 | | -BOOST_AUTO_TEST_SUITE(config_ops) |
| 9 | +BOOST_AUTO_TEST_SUITE(config_ops, |
| 10 | + *boost::unit_test::label("config")) |
10 | 11 |
|
11 | 12 | BOOST_AUTO_TEST_CASE(simple) |
12 | 13 | { |
@@ -243,4 +244,44 @@ BOOST_AUTO_TEST_CASE(advanced) |
243 | 244 | BOOST_CHECK(func->Invoke() == 3); |
244 | 245 | } |
245 | 246 |
|
| 247 | +BOOST_AUTO_TEST_CASE(sandboxed_ticket_salt) |
| 248 | +{ |
| 249 | + ScriptFrame frame(true, new Namespace); |
| 250 | + std::unique_ptr<Expression> expr; |
| 251 | + |
| 252 | + auto ns = ScriptGlobal::GetGlobals(); |
| 253 | + ns->Set("TicketSalt", "testvalue"); |
| 254 | + |
| 255 | + expr = ConfigCompiler::CompileText("<test>", "TicketSalt"); |
| 256 | + BOOST_CHECK_EQUAL(expr->Evaluate(frame).GetValue(), "testvalue"); |
| 257 | + |
| 258 | + expr = ConfigCompiler::CompileText("<test>", "globals.TicketSalt"); |
| 259 | + BOOST_CHECK_EQUAL(expr->Evaluate(frame).GetValue(), "testvalue"); |
| 260 | + |
| 261 | + expr = ConfigCompiler::CompileText("<test>", "*&TicketSalt"); |
| 262 | + BOOST_CHECK_EQUAL(expr->Evaluate(frame).GetValue(), "testvalue"); |
| 263 | + |
| 264 | + expr = ConfigCompiler::CompileText("<test>", "globals.TicketSalt = {{{other}}}"); |
| 265 | + BOOST_CHECK_NO_THROW(expr->Evaluate(frame)); |
| 266 | + |
| 267 | + frame.Sandboxed = true; |
| 268 | + ns->Set("TicketSalt", "testvalue", false); |
| 269 | + |
| 270 | + // Accessing TicketSalt in a sandboxed context is like trying to access a variable that doesn't exist. |
| 271 | + // In case of direct access, it will throw a ScriptError. |
| 272 | + expr = ConfigCompiler::CompileText("<test>", "TicketSalt"); |
| 273 | + BOOST_CHECK_THROW(expr->Evaluate(frame).GetValue(), ScriptError); |
| 274 | + |
| 275 | + // In case of other ways of accessing it, like through the global scope, it evaluates to Empty |
| 276 | + expr = ConfigCompiler::CompileText("<test>", "globals.TicketSalt"); |
| 277 | + BOOST_CHECK_EQUAL(expr->Evaluate(frame).GetValue(), ""); |
| 278 | + |
| 279 | + // Same for (the different ways of) trying to access it via a reference. |
| 280 | + expr = ConfigCompiler::CompileText("<test>", "*&TicketSalt"); |
| 281 | + BOOST_CHECK_EQUAL(expr->Evaluate(frame).GetValue(), ""); |
| 282 | + |
| 283 | + expr = ConfigCompiler::CompileText("<test>", "globals.TicketSalt = {{{other}}}"); |
| 284 | + BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError); |
| 285 | +} |
| 286 | + |
246 | 287 | BOOST_AUTO_TEST_SUITE_END() |
0 commit comments