From 3643ca7e045a72ff893e631366936aff30ebd4e7 Mon Sep 17 00:00:00 2001 From: Zdenek Dohnal Date: Tue, 23 Jul 2024 16:23:12 +0200 Subject: [PATCH] Add sanity test for Web UI --- Sanity/web-ui-sanity/main.fmf | 19 +++ Sanity/web-ui-sanity/test.sh | 217 ++++++++++++++++++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 Sanity/web-ui-sanity/main.fmf create mode 100755 Sanity/web-ui-sanity/test.sh diff --git a/Sanity/web-ui-sanity/main.fmf b/Sanity/web-ui-sanity/main.fmf new file mode 100644 index 0000000..54af3b9 --- /dev/null +++ b/Sanity/web-ui-sanity/main.fmf @@ -0,0 +1,19 @@ +summary: Do several basic curl commands to CUPS Web UI +test: ./test.sh +framework: beakerlib +duration: 10m +component: + - cups +contact: + - Zdenek Dohnal +recommend: + - cups + - curl + - cups-printerapp + - grep +tier: '1' +enabled: true +adjust: + - enabled: false + when: distro < rhel-7 + continue: false diff --git a/Sanity/web-ui-sanity/test.sh b/Sanity/web-ui-sanity/test.sh new file mode 100755 index 0000000..e0ad0d2 --- /dev/null +++ b/Sanity/web-ui-sanity/test.sh @@ -0,0 +1,217 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +rlJournalStart + rlPhaseStartSetup + rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" + rlRun "pushd $tmp" + rlRun "set -o pipefail" + rlRun "rm -rf /var/cache/cups/*" + rlFileBackup --clean /etc/cups /var/spool/cups /var/cache/cups + if rlIsRHELLike '>=9' || rlIsFedora + then + rlRun "ippeveprinter -D file:/tmp/ps -c /usr/bin/cat 'test' &> /dev/null &" + URI="ipp://localhost:8000/ipp/print" + MOD="everywhere" + else + rlRun "echo 'FileDevice Yes' >> /etc/cups/cups-files.conf" + URI="file:/tmp/ps" + MOD="drv:///sample.drv/generic.ppd" + fi + + rlServiceStart cups + # RHEL 9 printers query looks into descriptions as well + rlRun "lpadmin -p test -v ${URI} -D some -m ${MOD} -E" + rlRun "lpadmin -p other -v ${URI} -D else -m ${MOD} -E" + rlRun "lpadmin -p test -c classtest1" + rlRun "lpadmin -p test -c classtest2" + rlRun "lp -d test /etc/fstab" + sleep 5 + rlRun "lp -d other /etc/fstab" + sleep 5 + rlPhaseEnd + + rlPhaseStartTest "Check index.html - should have tabs for admin, classes, help, jobs, printers..." + rlRun "curl http://localhost:631 > out" + # href and title are in upper case in RHEL 7, so ignore the case + rlAssertGrep 'Home - CUPS' out -i + + if rlIsRHELLike '<8' + then + SPACE="  " + else + SPACE="" + fi + + rlAssertGrep "href=\"/admin\">${SPACE}Administration" out -i + rlAssertGrep "href=\"/classes/\">${SPACE}Classes" out -i + + if rlIsRHELLike '<8' + then + rlAssertGrep "href=\"/help/\">${SPACE}Online Help" out -i + else + rlAssertGrep "href=\"/help/\">Help" out -i + fi + + rlAssertGrep "href=\"/jobs/\">${SPACE}Jobs" out -i + rlAssertGrep "href=\"/printers/\">${SPACE}Printers" out -i + rlPhaseEnd + + rlPhaseStartTest "No admin stuff without creds :)" + rlRun "curl http://localhost:631/admin > out" + if rlIsRHELLike '<10' + then + rlLog "This is bug in RHEL <= 9 - Admin page is accessible, authentication happens when adding the printers" + rlAssertNotGrep 'Unauthorized' out + else + rlAssertGrep 'Unauthorized' out + fi + rlPhaseEnd + + rlPhaseStartTest "Main page for classes" + rlRun "curl http://localhost:631/classes/ > out" + rlAssertGrep '<title>Classes - CUPS' out -i + rlAssertGrep '/classes/classtest1">classtest1' out + rlAssertGrep '/classes/classtest2">classtest2' out + rlPhaseEnd + + rlPhaseStartTest "URL ending with ? is for 'Manage classes'" + rlRun "curl http://localhost:631/classes/? > out" + rlAssertGrep '<title>Classes - CUPS' out -i + rlAssertGrep '/classes/classtest1">classtest1' out + rlAssertGrep '/classes/classtest2">classtest2' out + rlPhaseEnd + + rlPhaseStartTest "Search for classtest1" + rlRun "curl http://localhost:631/classes/?QUERY=classtest1 > out" + rlAssertGrep '<title>Classes - CUPS' out -i + rlAssertGrep '/classes/classtest1">classtest1' out + rlAssertNotGrep '/classes/classtest2">classtest2' out + rlPhaseEnd + + rlPhaseStartTest "Main Help page" + rlRun "curl http://localhost:631/help/ > out" + rlAssertGrep '<title>Online Help' out -i + rlPhaseEnd + + rlPhaseStartTest "Search in help for cupsGetDest" + rlRun "curl 'http://localhost:631/help/?QUERY=cupsGetDest&SEARCH=Search' > out" + rlAssertGrep '<title>Online Help' out -i + rlAssertGrep 'TYPE="SEARCH" NAME="QUERY" VALUE="cupsGetDest"' out + if rlIsRHELLike '8' + then + rlLog "Searching in Help page does not find anything in RHEL 8." + rlAssertGrep "No matches found." out + else + rlAssertGrep 'QUERY=cupsGetDest#cupsGetDest">cupsGetDest' out + fi + rlPhaseEnd + + rlPhaseStartTest "Main Jobs page" + rlRun "curl 'http://localhost:631/jobs/' > out" + rlAssertGrep '<title>Jobs - CUPS' out -i + rlAssertNotGrep '/printers/test">test</A>-1' out + rlAssertNotGrep '/printers/other">other</A>-2' out + rlPhaseEnd + + rlPhaseStartTest "Completed Jobs page" + rlRun "curl 'http://localhost:631/jobs?which_jobs=completed' > out" + rlAssertGrep '<title>Jobs - CUPS' out -i + rlAssertGrep '/printers/test">test</A>-1' out + rlAssertGrep '/printers/other">other</A>-2' out + rlPhaseEnd + + rlPhaseStartTest "Active Jobs page" + rlRun "cupsdisable test" + rlRun "lp -d test /etc/fstab" + sleep 5 + rlRun "curl 'http://localhost:631/jobs?' > out" + rlAssertGrep '<title>Jobs - CUPS' out -i + rlAssertGrep '/printers/test">test</A>-3' out + rlAssertNotGrep '/printers/test">test</A>-1' out + rlAssertNotGrep '/printers/other">other</A>-2' out + rlRun "cupsenable test" + rlPhaseEnd + + rlPhaseStartTest "All Jobs page" + rlRun "curl 'http://localhost:631/jobs?which_jobs=all' > out" + rlAssertGrep '<title>Jobs - CUPS' out -i + rlAssertGrep '/printers/test">test</A>-1' out + rlAssertGrep '/printers/other">other</A>-2' out + rlAssertGrep '/printers/test">test</A>-3' out + sleep 5 + rlPhaseEnd + + rlPhaseStartTest "Example search in all jobs" + rlRun "curl 'http://localhost:631/jobs/?which_jobs=all&QUERY=other' > out" + rlAssertGrep '<title>Jobs - CUPS' out -i + rlAssertNotGrep '/printers/test">test</A>-1' out + rlAssertGrep '/printers/other">other</A>-2' out + rlAssertNotGrep '/printers/test">test</A>-3' out + rlPhaseEnd + + rlPhaseStartTest "Main printers page" + rlRun "curl 'http://localhost:631/printers/' > out" + rlAssertGrep '<title>Printers - CUPS' out -i + rlAssertGrep '/printers/test">test' out + rlAssertGrep '/printers/other">other' out + rlPhaseEnd + + rlPhaseStartTest "URL ending with ? is for 'Manage Printers'" + rlRun "curl http://localhost:631/printers/? > out" + rlAssertGrep '<title>Printers - CUPS' out -i + rlAssertGrep '/printers/test">test' out + rlAssertGrep '/printers/other">other' out + rlPhaseEnd + + rlPhaseStartTest "Search for a printer" + rlRun "curl 'http://localhost:631/printers/?QUERY=test' > out" + rlAssertGrep '<title>Printers - CUPS' out -i + rlAssertGrep '/printers/test">test' out + rlAssertNotGrep '/printers/other">other' out + rlPhaseEnd + + rlPhaseStartTest "Give me a page of specific printer" + rlRun "curl 'http://localhost:631/printers/test' > out" + rlAssertGrep '<title>test - CUPS' out -i + rlAssertGrep "Connection:</TH><TD>${URI}" out + rlAssertGrep 'Description:</TH><TD>some' out + rlAssertNotGrep '/printers/test">test</A>-1' out + rlAssertNotGrep '/printers/test">test</A>-3' out + rlPhaseEnd + + rlPhaseStartTest "Search for jobs of specific printer" + rlRun "curl 'http://localhost:631/printers/test?which_jobs=all' > out" + rlAssertGrep '<title>test - CUPS' out -i + rlAssertGrep '/printers/test">test</A>-1' out + rlAssertGrep '/printers/test">test</A>-3' out + rlAssertNotGrep '/printers/other">other</A>-2' out + rlPhaseEnd + + rlPhaseStartTest "What about non-existing printer?" + rlRun "curl 'http://localhost:631/printers/err' > out" + if rlIsRHELLike '>=10' || rlIsFedora + then + rlAssertGrep 'Not Found' out + else + rlLog "This is not fixed on Centos/RHEL < 10" + rlAssertNotGrep 'Not Found' out + fi + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "lpadmin -x classtest1" + rlRun "lpadmin -x classtest2" + rlRun "lpadmin -x test" + rlRun "lpadmin -x other" + if rlIsRHELLike '>=9' || rlIsFedora + then + rlRun "kill $(pidof ippeveprinter)" + fi + rlServiceRestore cups + rlFileRestore + rlRun "popd" + rlRun "rm -r $tmp" 0 "Remove tmp directory" + rlPhaseEnd +rlJournalEnd