2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2016-11-11 15:57:25 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class NotificationFactoryRendererTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
# RSpec incoming!
|
|
|
|
def described_class
|
|
|
|
NotificationFactory::Renderer
|
|
|
|
end
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
group = Group.new(name: 'Users')
|
2017-03-31 06:54:05 +00:00
|
|
|
owner = User.new(firstname: 'Owner<b>xxx</b>', lastname: 'Agent1<b>yyy</b>')
|
2016-11-13 18:33:12 +00:00
|
|
|
current_user = User.new(firstname: 'CurrentUser<b>xxx</b>', lastname: 'Agent2<b>yyy</b>')
|
|
|
|
state = Ticket::State.new(name: 'new')
|
|
|
|
ticket = Ticket.new(
|
2018-12-19 17:31:51 +00:00
|
|
|
id: 1,
|
|
|
|
title: '<b>Welcome to Zammad!</b>',
|
|
|
|
group: group,
|
|
|
|
owner: owner,
|
|
|
|
state: state,
|
2017-03-31 06:54:05 +00:00
|
|
|
created_by: current_user,
|
|
|
|
updated_by: current_user,
|
2016-11-13 18:33:12 +00:00
|
|
|
created_at: Time.zone.parse('2016-11-12 12:00:00 UTC'),
|
|
|
|
updated_at: Time.zone.parse('2016-11-12 14:00:00 UTC'),
|
|
|
|
)
|
|
|
|
article_html1 = Ticket::Article.new(
|
2018-12-19 17:31:51 +00:00
|
|
|
body: 'test <b>hello</b><br>some new line',
|
2016-11-13 18:33:12 +00:00
|
|
|
content_type: 'text/html',
|
|
|
|
)
|
|
|
|
article_plain1 = Ticket::Article.new(
|
2018-12-19 17:31:51 +00:00
|
|
|
body: "test <b>hello</b>\nsome new line",
|
2016-11-13 18:33:12 +00:00
|
|
|
content_type: 'text/plain',
|
|
|
|
)
|
|
|
|
article_plain2 = Ticket::Article.new(
|
|
|
|
body: "test <b>hello</b>\nsome new line",
|
|
|
|
)
|
2016-11-11 15:57:25 +00:00
|
|
|
|
|
|
|
test 'replace object attribute' do
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.title}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML(ticket.title), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.created_at}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
2019-02-10 11:01:38 +00:00
|
|
|
assert_equal('11/12/2016 13:00 (Europe/Berlin)', result)
|
2016-11-13 18:33:12 +00:00
|
|
|
|
2017-03-31 06:54:05 +00:00
|
|
|
template = "\#{ticket.created_by.firstname}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2017-03-31 06:54:05 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2017-03-31 06:54:05 +00:00
|
|
|
).render
|
|
|
|
assert_equal('CurrentUser<b>xxx</b>', result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.updated_at}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
2019-02-10 11:01:38 +00:00
|
|
|
assert_equal('11/12/2016 15:00 (Europe/Berlin)', result)
|
2016-11-13 18:33:12 +00:00
|
|
|
|
2017-03-31 06:54:05 +00:00
|
|
|
template = "\#{ticket.updated_by.firstname}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2017-03-31 06:54:05 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2017-03-31 06:54:05 +00:00
|
|
|
).render
|
|
|
|
assert_equal('CurrentUser<b>xxx</b>', result)
|
|
|
|
|
|
|
|
template = "\#{ticket.owner.firstname}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2017-03-31 06:54:05 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2017-03-31 06:54:05 +00:00
|
|
|
).render
|
|
|
|
assert_equal('Owner<b>xxx</b>', result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket. title}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML(ticket.title), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.\n title}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML(ticket.title), result)
|
2016-11-11 15:57:25 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.\t title}"
|
2016-11-11 15:57:25 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-11 15:57:25 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-11 15:57:25 +00:00
|
|
|
).render
|
2016-11-12 10:19:15 +00:00
|
|
|
assert_equal(CGI.escapeHTML(ticket.title), result)
|
2016-11-11 15:57:25 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.\t\n title\t}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
2016-11-11 15:57:25 +00:00
|
|
|
assert_equal(CGI.escapeHTML(ticket.title), result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.\" title\t}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML(ticket.title), result)
|
|
|
|
|
2017-07-24 13:25:37 +00:00
|
|
|
template = "\#{<a href=\"/test123\">ticket.\" title</a>}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2017-07-24 13:25:37 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2017-07-24 13:25:37 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML(ticket.title), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "some test<br>\#{article.body}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
article: article_html1,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
|
|
|
assert_equal('some test<br>> test hello<br>> some new line<br>', result)
|
|
|
|
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
article: article_plain1,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
|
|
|
assert_equal('some test<br>> test <b>hello</b><br>> some new line<br>', result)
|
|
|
|
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
article: article_plain2,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
|
|
|
assert_equal('some test<br>> test <b>hello</b><br>> some new line<br>', result)
|
|
|
|
|
2016-11-11 15:57:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'config' do
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
setting = 'fqdn'
|
|
|
|
template = "\#{config.#{setting}}"
|
2016-11-11 15:57:25 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-11 15:57:25 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-11 15:57:25 +00:00
|
|
|
).render
|
|
|
|
assert_equal(Setting.get(setting), result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
|
|
|
setting1 = 'fqdn'
|
|
|
|
setting2 = 'product_name'
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "some \#{config.#{setting1}} and \#{config.#{setting2}}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
2016-11-13 18:33:12 +00:00
|
|
|
assert_equal("some #{Setting.get(setting1)} and #{Setting.get(setting2)}", result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
setting1 = 'fqdn'
|
|
|
|
setting2 = 'product_name'
|
|
|
|
template = "some \#{ config.#{setting1}} and \#{\tconfig.#{setting2}}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
2016-11-12 10:19:15 +00:00
|
|
|
assert_equal("some #{Setting.get(setting1)} and #{Setting.get(setting2)}", result)
|
2016-11-11 15:57:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'translation' do
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
#template = "<%= t 'new' %>"
|
|
|
|
template = "\#{t('new')}"
|
2016-11-11 15:57:25 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-11 15:57:25 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'de-de',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-11 15:57:25 +00:00
|
|
|
).render
|
|
|
|
assert_equal('neu', result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "some text \#{t('new')} and \#{t('open')}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'de-de',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
|
|
|
assert_equal('some text neu and offen', result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "some text \#{t('new') } and \#{ t('open')}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'de-de',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
2016-11-13 18:33:12 +00:00
|
|
|
assert_equal('some text neu and offen', result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "some text \#{\nt('new') } and \#{ t('open')\t}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'de-de',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
2016-11-12 10:19:15 +00:00
|
|
|
assert_equal('some text neu and offen', result)
|
|
|
|
|
2016-11-11 15:57:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'chained function calls' do
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{t(ticket.state.name)}"
|
2016-11-11 15:57:25 +00:00
|
|
|
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-11 15:57:25 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'de-de',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-11 15:57:25 +00:00
|
|
|
).render
|
|
|
|
|
|
|
|
assert_equal('neu', result)
|
|
|
|
end
|
2016-11-12 10:19:15 +00:00
|
|
|
|
|
|
|
test 'not existing object and attribute' do
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{no such object}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{notexsiting.notexsiting}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{notexsiting / no such object}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.notexsiting}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.notexsiting / no such method}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket. / no such method}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.title.notexsiting}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.title.notexsiting / no such method}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.notexsiting.notexsiting}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.notexsiting / no such method}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{notexsiting}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{notexsiting / no such object}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{notexsiting.}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{notexsiting / no such object}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{string}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
string: 'some string',
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('some string'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{fixum}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
fixum: 123,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('123'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{float}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
float: 123.99,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('123.99'), result)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'data key validation' do
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.title `echo 1`}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
2016-11-13 18:33:12 +00:00
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.title`echo1` / not allowed}'), result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.destroy}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.destroy / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.save}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.save / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.update}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.update / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.create}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-13 18:33:12 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-13 18:33:12 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.create / not allowed}'), result)
|
|
|
|
|
|
|
|
template = "\#{ticket.delete}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.delete / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.remove}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.remove / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.drop}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.drop / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.create}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.create / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.new}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.new / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.update_att}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.update_att / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.all}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.all / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.find}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.find / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.where}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.where / not allowed}'), result)
|
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket. destroy}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
2016-11-13 18:33:12 +00:00
|
|
|
assert_equal(CGI.escapeHTML('#{ticket.destroy / not allowed}'), result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.\n destroy}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
2016-11-13 18:33:12 +00:00
|
|
|
assert_equal(CGI.escapeHTML("\#{ticket.destroy / not allowed}"), result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.\t destroy}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
2016-11-13 18:33:12 +00:00
|
|
|
assert_equal(CGI.escapeHTML("\#{ticket.destroy / not allowed}"), result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
2016-11-13 18:33:12 +00:00
|
|
|
template = "\#{ticket.\r destroy}"
|
2016-11-12 10:19:15 +00:00
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2016-11-12 10:19:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2016-11-12 10:19:15 +00:00
|
|
|
).render
|
2016-11-13 18:33:12 +00:00
|
|
|
assert_equal(CGI.escapeHTML("\#{ticket.destroy / not allowed}"), result)
|
2016-11-12 10:19:15 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2018-10-16 08:45:15 +00:00
|
|
|
test 'methods with single Integer parameter' do
|
|
|
|
|
|
|
|
template = "\#{ticket.title.first(3)}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2018-10-16 08:45:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2018-10-16 08:45:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('<b>'), result)
|
|
|
|
|
|
|
|
template = "\#{ticket.title.last(4)}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2018-10-16 08:45:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2018-10-16 08:45:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML('</b>'), result)
|
|
|
|
|
|
|
|
template = "\#{ticket.title.slice(3, 4)}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2018-10-16 08:45:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2018-10-16 08:45:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal(CGI.escapeHTML("\#{ticket.title.slice(3,4) / invalid parameter: 3,4}"), result)
|
|
|
|
|
|
|
|
template = "\#{ticket.title.first('some invalid parameter')}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2018-10-16 08:45:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2018-10-16 08:45:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal("\#{ticket.title.first(someinvalidparameter) / invalid parameter: someinvalidparameter}", result)
|
|
|
|
|
|
|
|
template = "\#{ticket.title.chomp(`cat /etc/passwd`)}"
|
|
|
|
result = described_class.new(
|
2019-02-10 11:01:38 +00:00
|
|
|
objects: {
|
2018-10-16 08:45:15 +00:00
|
|
|
ticket: ticket,
|
|
|
|
},
|
2019-02-10 11:01:38 +00:00
|
|
|
locale: 'en-us',
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
template: template,
|
2018-10-16 08:45:15 +00:00
|
|
|
).render
|
|
|
|
assert_equal("\#{ticket.title.chomp(`cat/etc/passwd`) / not allowed}", result)
|
|
|
|
end
|
2016-11-11 15:57:25 +00:00
|
|
|
end
|