diff options
Diffstat (limited to 'test/models/page_test.rb')
| -rw-r--r-- | test/models/page_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/models/page_test.rb b/test/models/page_test.rb index edb7c378..58794d54 100644 --- a/test/models/page_test.rb +++ b/test/models/page_test.rb | |||
| @@ -370,4 +370,36 @@ class PageTest < ActiveSupport::TestCase | |||
| 370 | assert en_entry[:changed] | 370 | assert en_entry[:changed] |
| 371 | refute en_entry[:exists_there] | 371 | refute en_entry[:exists_there] |
| 372 | end | 372 | end |
| 373 | |||
| 374 | test "aggregate ignores order_by values outside the allowlist" do | ||
| 375 | sql = Page.aggregate(:order_by => "pages.id; DROP TABLE pages--").to_sql | ||
| 376 | |||
| 377 | assert_not_includes sql, "DROP" | ||
| 378 | assert_includes sql, "pages.id ASC" | ||
| 379 | end | ||
| 380 | |||
| 381 | test "aggregate accepts allowlisted order columns, bare or prefixed" do | ||
| 382 | assert_includes Page.aggregate(:order_by => "published_at").to_sql, | ||
| 383 | "pages.published_at ASC" | ||
| 384 | assert_includes Page.aggregate(:order_by => "pages.published_at").to_sql, | ||
| 385 | "pages.published_at ASC" | ||
| 386 | end | ||
| 387 | |||
| 388 | test "template_name rejects values not present in the template directory" do | ||
| 389 | page = Page.create!(:title => "Template guard") | ||
| 390 | |||
| 391 | page.template_name = "../../partials/_article" | ||
| 392 | assert_not page.valid? | ||
| 393 | |||
| 394 | page.template_name = "standard_template" | ||
| 395 | assert page.valid? | ||
| 396 | end | ||
| 397 | |||
| 398 | test "a stale legacy template_name does not block unrelated saves" do | ||
| 399 | page = Page.create!(:title => "Stale template") | ||
| 400 | page.update_column(:template_name, "long_deleted_template") | ||
| 401 | |||
| 402 | page.reload | ||
| 403 | assert page.update(:abstract => "still saveable") | ||
| 404 | end | ||
| 373 | end | 405 | end |
