1::@echo off 2:: 3:: "$Id: bonjour-tests.bat 12142 2014-08-30 02:35:43Z msweet $" 4:: 5:: IPP Everywhere Printer Self-Certification Manual 1.0: Section 5: Bonjour Tests. 6:: 7:: Copyright 2014 by The Printer Working Group. 8:: 9:: This program may be copied and furnished to others, and derivative works 10:: that comment on, or otherwise explain it or assist in its implementation may 11:: be prepared, copied, published and distributed, in whole or in part, without 12:: restriction of any kind, provided that the above copyright notice and this 13:: paragraph are included on all such copies and derivative works. 14:: 15:: The IEEE-ISTO and the Printer Working Group DISCLAIM ANY AND ALL WARRANTIES, 16:: WHETHER EXPRESS OR IMPLIED INCLUDING (WITHOUT LIMITATION) ANY IMPLIED 17:: WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 18:: 19:: Usage: 20:: 21:: bonjour-tests.bat 'Printer Name' 22:: 23 24set PLIST="%1 Bonjour Results.plist" 25 26:: Special case second argument: "_keys" and "_values" to show bad/missing TXT keys 27if not "%2" == "" ( 28 echo "FAIL" 29 echo "<key>Errors</key><array>" >>"%PLIST%" 30 if not defined IPPFIND_TXT_ADMINURL ( 31 echo " adminurl is not set." 32 echo "<string>adminurl is not set.</string>" >>"%PLIST%" 33 ) else ( 34 if "%2" == "_values" ( 35 set result=FAIL 36 set scheme="%IPPFIND_TXT_ADMINURL:~0,7%" 37 if "%scheme%" == "http://" set result=PASS 38 set scheme="%IPPFIND_TXT_ADMINURL:~0,8%" 39 if "%scheme%" == "https://" set result=PASS 40 if "%result%" == "FAIL" ( 41 echo " adminurl has bad value '%IPPFIND_TXT_ADMINURL%'." 42 echo "<string>adminurl has bad value '%IPPFIND_TXT_ADMINURL%'.</string>" >>"%PLIST%" 43 ) 44 ) 45 ) 46 47 if not defined IPPFIND_TXT_PDL ( 48 echo " pdl is not set." 49 echo "<string>pdl is not set.</string>" >>"%PLIST%" 50 ) else ( 51 if "%2" == "_values" ( 52 set temp="%IPPFIND_TXT_PDL:image/jpeg=%" 53 if "%temp%" == "%IPPFIND_TXT_PDL%" ( 54 echo " pdl is missing image/jpeg: '%IPPFIND_TXT_PDL%'" 55 echo "<string>pdl is missing image/jpeg: '%IPPFIND_TXT_PDL%'.</string>" >>"%PLIST%" 56 ) 57 58 set temp="%IPPFIND_TXT_PDL:image/pwg-raster=%" 59 if "%temp%" == "%IPPFIND_TXT_PDL%" ( 60 echo " pdl is missing image/pwg-raster: '%IPPFIND_TXT_PDL%'" 61 echo "<string>pdl is missing image/pwg-raster: '%IPPFIND_TXT_PDL%'.</string>" >>"%PLIST%" 62 ) 63 ) 64 ) 65 66 if not defined IPPFIND_TXT_RP ( 67 echo " rp is not set." 68 echo "<string>rp is not set.</string>" >>"%PLIST%" 69 ) else ( 70 if "%2" == "_values" ( 71 if not "%IPPFIND_TXT_RP%" == "ipp/print" ( 72 if not "%IPPFIND_TXT_RP:~0,10%" == "ipp/print/" ( 73 echo " rp has bad value '%IPPFIND_TXT_RP%'" 74 echo "<string>rp has bad value '%IPPFIND_TXT_RP%'.</string>" >>"%PLIST%" 75 ) 76 ) 77 ) 78 ) 79 80 if not defined IPPFIND_TXT_UUID ( 81 echo " UUID is not set." 82 echo "<string>UUID is not set.</string>" >>"%PLIST%" 83 ) else ( 84 if "%2" == "_values" ( 85 :: This isn't as effective as the test in bonjour-tests.sh but still 86 :: catches the most common error... 87 set scheme="%IPPFIND_TXT_UUID:~0,9%" 88 if "%scheme%" == "urn:uuid:" ( 89 echo " UUID has bad value '%IPPFIND_TXT_UUID%'" 90 echo "<string>UUID has bad value '%IPPFIND_TXT_UUID%'.</string>" >>"%PLIST%" 91 ) 92 ) 93 ) 94 95 if "%2" == "_values" ( 96 ipptool -t -d "ADMINURL=%IPPFIND_TXT_ADMINURL%" -d "UUID=%IPPFIND_TXT_UUID%" %IPPFIND_SERVICE_URI% bonjour-value-tests.test 97 echo "<string>" >>"%PLIST%" 98 $IPPTOOL -t -d "ADMINURL=$IPPFIND_TXT_ADMINURL" -d "UUID=$IPPFIND_TXT_UUID" $IPPFIND_SERVICE_URI bonjour-value-tests.test | findstr /r "[TD]:" >>"%PLIST%" 99 echo "</string>" >>"%PLIST%" 100 ) 101 102 echo "</array>" >>"%PLIST%" 103 echo "<key>Successful</key><false />" >>"%PLIST%" 104 echo "</dict>" >>"%PLIST%" 105 106 goto :eof 107) 108 109 110:: Write the standard XML plist header... 111echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" >"%PLIST%" 112echo "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" >>"%PLIST%" 113echo "<plist version=\"1.0\">" >>"%PLIST%" 114echo "<dict>" >>"%PLIST%" 115echo "<key>Tests</key><array>" >>"%PLIST%" 116 117set total=0 118set pass=0 119set fail=0 120set skip=0 121 122:: B-1. IPP Browse test: Printers appear in a search for "_ipp._tcp,_print" services? 123call :start_test "B-1. IPP Browse test" 124set result=FAIL 125ippfind _ipp._tcp,_print.local. --name "%1" --quiet && set result=PASS 126if "%result%" == "PASS" ( 127 set /a pass+=1 128 call :end_test PASS 129) else ( 130 set /a fail+=1 131 call :end_test FAIL 132) 133 134:: B-2. IPP TXT keys test: The IPP TXT record contains all required keys. 135call :start_test "B-2. IPP TXT keys test" 136set result=FAIL 137ippfind "%1._ipp._tcp.local." --txt adminurl --txt pdl --txt rp --txt UUID --quiet && set result=PASS 138if "%result%" == "PASS" ( 139 set /a pass+=1 140 call :end_test PASS 141) else ( 142 set /a fail+=1 143 ippfind "%1._ipp._tcp.local." -x bonjour-tests.bat "{service_name}" _keys ";" 144) 145 146:: B-3. IPP Resolve test: Printer responds to an IPP Get-Printer-Attributes request using the resolved hostname, port, and resource path. 147call :start_test "B-3. IPP Resolve test" 148set result=FAIL 149(ippfind "%1._ipp._tcp.local." --ls && set result=PASS) >nul: 150if "%result%" == "PASS" ( 151 set /a pass+=1 152 call :end_test PASS 153) else ( 154 set /a fail+=1 155 echo "<key>Errors</key><array><string>" >>"%PLIST%" 156 ippfind "%1._ipp._tcp.local." --ls >>"%PLIST%" 157 echo "</string></array>" >>"%PLIST%" 158 call :end_test FAIL 159) 160 161:: B-4. IPP TXT values test: The IPP TXT record values match the reported IPP attribute values. 162call :start_test "B-4. IPP TXT values test" 163set result=FAIL 164ippfind "%1._ipp._tcp.local." --txt-adminurl "^(http:|https:)//" --txt-pdl image/pwg-raster --txt-pdl image/jpeg --txt-rp "^ipp/(print|print/[^/]+)$" --txt-UUID "^[0-9a-fA-F]{8,8}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{12,12}$" -x $IPPTOOL -q -d "ADMINURL={txt_adminurl}" -d "UUID={txt_uuid}" "{}" bonjour-value-tests.test ";" && set result=PASS 165if "%result%" == "PASS" ( 166 set /a pass+=1 167 call :end_test PASS 168) else ( 169 set /a fail+=1 170 ippfind "%1._ipp._tcp.local." -x bonjour-tests.bat "{service_name}" _values ";" 171) 172 173:: B-5. TLS tests: Performed only if TLS is supported 174call :start_test "B-5. TLS tests" 175set result=FAIL 176find "%1._ipp._tcp.local." --txt tls --quiet && set result=PASS 177if "%result%" == "PASS" ( 178 set /a pass+=1 179 set HAVE_TLS=1 180 call :end_test PASS 181) else ( 182 set /a skip+=1 183 set HAVE_TLS=0 184 call :end_test SKIP 185) 186 187:: B-5.1 HTTP Upgrade test: Printer responds to an IPP Get-Printer-Attributes request after doing an HTTP Upgrade to TLS. 188call :start_test "B-5.1 HTTP Upgrade test" 189if "%HAVE_TLS%" == "1" ( 190 set result=FAIL 191 ippfind "%1._ipp._tcp.local." -x ipptool -E -q "{}" bonjour-access-tests.test ";" && set result=PASS 192 if "%result%" == "PASS" ( 193 set /a pass+=1 194 call :end_test PASS 195 ) else ( 196 set /a fail+=1 197 echo "<key>Errors</key><array><string>" >>"%PLIST" 198 ippfind "%1._ipp._tcp.local." -x ipptool -E -q "{}" bonjour-access-tests.test ";" >>"%PLIST%" 199 echo "</string></array>" >>"%PLIST%" 200 call :end_test FAIL 201 ) 202) else ( 203 set /a skip+=1 204 call :end_test SKIP 205) 206 207:: B-5.2 IPPS Browse test: Printer appears in a search for "_ipps._tcp,_print" services. 208call :start_test "B-5.2 IPPS Browse test" 209if "%HAVE_TLS%" == "1" ( 210 set result=FAIL 211 ippfind _ipps._tcp,_print.local. --name "%1" --quiet && set result=PASS 212 if "%result%" == "PASS" ( 213 set /a pass+=1 214 call :end_test PASS 215 ) else ( 216 set /a fail+=1 217 call :end_test FAIL 218 ) 219) else ( 220 set /a skip+=1 221 call :end_test SKIP 222) 223 224:: B-5.3 IPPS TXT keys test: The TXT record for IPPS contains all required keys 225call :start_test "B-5.3 IPPS TXT keys test" 226if "%HAVE_TLS%" == "1" ( 227 set result=FAIL 228 ippfind "%1._ipps._tcp.local." --txt adminurl --txt pdl --txt rp --txt TLS --txt UUID --quiet && set result=PASS 229 if "%result%" == "PASS" ( 230 set /a pass+=1 231 call :end_test PASS 232 ) else ( 233 set /a fail+=1 234 ippfind "%1._ipps._tcp.local." -x bonjour-tests.bat "{service_name}" _keys ";" 235 ) 236) else ( 237 set /a skip+=1 238 call :end_test SKIP 239) 240 241:: B-5.4 IPPS Resolve test: Printer responds to an IPPS Get-Printer-Attributes request using the resolved hostname, port, and resource path. 242call :start_test "B-5.4 IPPS Resolve test" 243if "%HAVE_TLS%" == "1" ( 244 set result=FAIL 245 (ippfind "%1._ipps._tcp.local." --ls && set result=PASS) >nul: 246 if "%result%" == "PASS" ( 247 set /a pass+=1 248 call :end_test PASS 249 ) else ( 250 set /a fail+=1 251 echo "<key>Errors</key><array><string>" >>"%PLIST%" 252 ippfind "%1._ipps._tcp.local." --ls >>"%PLIST%" 253 echo "</string></array>" >>"%PLIST%" 254 call :end_test FAIL 255 ) 256) else ( 257 set /a skip+=1 258 call :end_test SKIP 259) 260 261:: B-5.5 IPPS TXT values test: The TXT record values for IPPS match the reported IPPS attribute values. 262call :start_test "B-5.5 IPPS TXT values test" 263if "%HAVE_TLS%" == "1" ( 264 set result=FAIL 265 ippfind "%1._ipps._tcp.local." --txt-adminurl "^(http:|https:)//" --txt-pdl image/pwg-raster --txt-pdl image/jpeg --txt-rp "^ipp/(print|print/[^/]+)$" --txt-UUID "^[0-9a-fA-F]{8,8}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{12,12}$" -x ipptool -q -d "ADMINURL={txt_adminurl}" -d "UUID={txt_uuid}" "{}" bonjour-value-tests.test ";" && set result=PASS 266 if "%result%" == "PASS" ( 267 set /a pass+=1 268 call :end_test PASS 269 ) else ( 270 set /a fail+=1 271 ippfind "%1._ipps._tcp.local." -x bonjour-tests.bat "{service_name}" _values ";" 272 ) 273) else ( 274 set /a skip+=1 275 call :end_test SKIP 276) 277 278:: Finish up... 279echo "</array>" >>"%PLIST%" 280echo "<key>Successful</key>" >>"%PLIST%" 281if %fail% gtr 0 ( 282 echo "<false />" >>"%PLIST%" 283) else ( 284 echo "<true />" >>"%PLIST%" 285) 286echo "</dict>" >>"%PLIST%" 287echo "</plist>" >>"%PLIST%" 288 289set /a score=%pass% + %skip% 290set /a score=100 * %score% / %total% 291echo "Summary: %total% tests, %pass% passed, %fail% failed, %skip% skipped" 292echo "Score: %score%^%" 293 294exit 295 296:: call :start_test "name" 297:start_test 298 set /a total+=1 299 setlocal 300 set name=%1 301 set name=%name:~1,-1% 302 set <NUL /p="%name%: " 303 echo "<dict><key>Name</key><string>%name%</string>" >>"%PLIST%" 304 echo "<key>FileId</key><string>org.pwg.ipp-everywhere.20140826.bonjour</string>" >>"%PLIST%" 305 endlocal 306 goto :eof 307 308:: call :end_test PASS/FAIL/SKIP 309:end_test 310 setlocal 311 echo %1 312 if "%1" == "FAIL" ( 313 echo "<key>Successful</key><false />" >>"%PLIST%" 314 ) else ( 315 if "%1" == "SKIP" ( 316 echo "<key>Successful</key><true />" >>"%PLIST%" 317 echo "<key>Skipped</key><true />" >>"%PLIST%" 318 ) else ( 319 echo "<key>Successful</key><true />" >>"%PLIST%" 320 ) 321 ) 322 echo "</dict>" >>"%PLIST%" 323 endlocal 324 goto :eof 325 326:: 327:: End of "$Id: bonjour-tests.bat 12142 2014-08-30 02:35:43Z msweet $". 328:: 329