@@ -213,112 +213,4 @@ class BlockingActionHelperSpecification extends DDSpecification {
213213 HTML | ' template.html' | ' <body>Custom template with security_response_id: [security_response_id]</body>' | ' Custom template with security_response_id: [id]'
214214 JSON | ' template.json' | ' {"error":"blocked","id":"[security_response_id]"}' | ' "error":"blocked","id":"[id]"'
215215 }
216-
217-
218- void ' getTemplate with security_response_id replaces placeholder in HTML template' () {
219- given :
220- def securityResponseId = ' 12345678-1234-1234-1234-123456789abc'
221-
222- when :
223- def template = BlockingActionHelper . getTemplate(HTML , securityResponseId)
224- def templateStr = new String (template, StandardCharsets . UTF_8 )
225-
226- then :
227- templateStr. contains(" Security Response ID: ${ securityResponseId} " )
228- ! templateStr. contains(' [security_response_id]' )
229- }
230-
231- void ' getTemplate with security_response_id replaces placeholder in JSON template' () {
232- given :
233- def securityResponseId = ' 12345678-1234-1234-1234-123456789abc'
234-
235- when :
236- def template = BlockingActionHelper . getTemplate(JSON , securityResponseId)
237- def templateStr = new String (template, StandardCharsets . UTF_8 )
238-
239- then :
240- templateStr. contains(" \" security_response_id\" :\" ${ securityResponseId} \" " )
241- ! templateStr. contains(' [security_response_id]' )
242- }
243-
244- void ' getTemplate without security_response_id uses empty string in HTML template' () {
245- when :
246- def template = BlockingActionHelper . getTemplate(HTML , null )
247- def templateStr = new String (template, StandardCharsets . UTF_8 )
248-
249- then :
250- ! templateStr. contains(' [security_response_id]' )
251- templateStr. contains(' Security Response ID:' )
252- // The placeholder is replaced with empty string
253- }
254-
255- void ' getTemplate without security_response_id uses empty string in JSON template' () {
256- when :
257- def template = BlockingActionHelper . getTemplate(JSON , null )
258- def templateStr = new String (template, StandardCharsets . UTF_8 )
259-
260- then :
261- ! templateStr. contains(' [security_response_id]' )
262- templateStr. contains(' "security_response_id"' )
263- templateStr. contains(' ""' ) // Empty string value
264- }
265-
266- void ' getTemplate with empty security_response_id uses empty string' () {
267- when :
268- def htmlTemplate = BlockingActionHelper . getTemplate(HTML , ' ' )
269- def jsonTemplate = BlockingActionHelper . getTemplate(JSON , ' ' )
270-
271- then :
272- ! new String (htmlTemplate, StandardCharsets . UTF_8 ). contains(' [security_response_id]' )
273- ! new String (jsonTemplate, StandardCharsets . UTF_8 ). contains(' [security_response_id]' )
274- // Both templates have placeholders replaced with empty string
275- }
276-
277- void ' getTemplate with security_response_id works with custom HTML template' () {
278- setup :
279- File tempDir = File . createTempDir(' testTempDir-' , ' ' )
280- Config config = Mock (Config )
281- File tempFile = new File (tempDir, ' template.html' )
282- tempFile << ' <body>Custom template with security_response_id: [security_response_id]</body>'
283- def securityResponseId = ' test-block-id-123'
284-
285- when :
286- BlockingActionHelper . reset(config)
287- def template = BlockingActionHelper . getTemplate(HTML , securityResponseId)
288- def templateStr = new String (template, StandardCharsets . UTF_8 )
289-
290- then :
291- 1 * config. getAppSecHttpBlockedTemplateHtml() >> tempFile. toString()
292- 1 * config. getAppSecHttpBlockedTemplateJson() >> null
293- templateStr. contains(" Custom template with security_response_id: ${ securityResponseId} " )
294- ! templateStr. contains(' [security_response_id]' )
295-
296- cleanup :
297- BlockingActionHelper . reset(Config . get())
298- tempDir. deleteDir()
299- }
300-
301- void ' getTemplate with security_response_id works with custom JSON template' () {
302- setup :
303- File tempDir = File . createTempDir(' testTempDir-' , ' ' )
304- Config config = Mock (Config )
305- File tempFile = new File (tempDir, ' template.json' )
306- tempFile << ' {"error":"blocked","id":"[security_response_id]"}'
307- def securityResponseId = ' test-block-id-456'
308-
309- when :
310- BlockingActionHelper . reset(config)
311- def template = BlockingActionHelper . getTemplate(JSON , securityResponseId)
312- def templateStr = new String (template, StandardCharsets . UTF_8 )
313-
314- then :
315- 1 * config. getAppSecHttpBlockedTemplateHtml() >> null
316- 1 * config. getAppSecHttpBlockedTemplateJson() >> tempFile. toString()
317- templateStr. contains(" \" error\" :\" blocked\" ,\" id\" :\" ${ securityResponseId} \" " )
318- ! templateStr. contains(' [security_response_id]' )
319-
320- cleanup :
321- BlockingActionHelper . reset(Config . get())
322- tempDir. deleteDir()
323- }
324216}
0 commit comments