github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/com/sap/piper/BashUtilsTest.groovy (about) 1 package com.sap.piper 2 3 import org.junit.Assert 4 import org.junit.Test 5 6 class BashUtilsTest { 7 @Test 8 void escapeFilePath() { 9 // Given: A Windows-style file path C:\some\path 10 def input = 'C:\\some\\path' 11 12 // When we escape the string 13 def result = BashUtils.quoteAndEscape(input) 14 15 // Then the string is surrounded by single quotes 'C:\some\path' 16 def expected = "'C:\\some\\path'" 17 Assert.assertEquals(expected, result) 18 } 19 20 @Test 21 void escapeUri() { 22 // Given: An URI with single quotes values http://www.sap.com?$filter='234' 23 def input = "http://www.sap.com?\$filter='234'" 24 25 // When we escape the string 26 def result = BashUtils.quoteAndEscape(input) 27 28 // Then the input string is surrounded by single quotes and each original ' is replaced by '"'"' 29 // 'http://www.sap.com?$filter='"'"'234'"'"'' 30 def expected = "'http://www.sap.com?\$filter='\"'\"'234'\"'\"''" 31 Assert.assertEquals(expected, result) 32 } 33 34 @Test 35 void escapePassword() { 36 // Given: A random generated password VQ5r\%*h"49'Ch>Jj? 37 def input = "VQ5r\\%*h\"49'Ch>Jj?" 38 39 // When we escape the string 40 def result = BashUtils.quoteAndEscape(input) 41 42 // Then the input string is surrounded by single quotes and each original ' is replaced by '"'"' 43 // 'VQ5r\%*h"49'"'"'Ch>Jj?' 44 def expected = "'VQ5r\\%*h\"49'\"'\"'Ch>Jj?'" 45 Assert.assertEquals(expected, result) 46 } 47 }