1 #! /usr/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 ###############################################################################
  28 # start __stf_assertion__
  29 #
  30 # ASSERTION: svccfg_editprop_003
  31 #
  32 # DESCRIPTION:
  33 #       Calling the 'editprop' subcommand with a invalid 
  34 #       value of EDITOR results in a diagnostic message sent 
  35 #       to stderr.  Invalid values of EDITOR are non-existent 
  36 #       commands, non-editor commands.
  37 #
  38 # STRATEGY:
  39 #       Test with the following conditions:
  40 #       #1: The value of EDITOR does not exist
  41 #       #2: The value of EDITOR is not executable
  42 #       #3: EDITOR is null
  43 #
  44 # end __stf_assertion__
  45 ###############################################################################
  46 
  47 
  48 # First STF library
  49 . ${STF_TOOLS}/include/stf.kshlib
  50 
  51 # Load GL library
  52 . ${STF_SUITE}/include/gltest.kshlib
  53 
  54 # Assertion ID
  55 readonly assertion=svccfg_editprop_003
  56 
  57 readonly ME=$(whence -p ${0})
  58 readonly MYLOC=$(dirname ${ME})
  59 
  60 # Initialize test result 
  61 typeset -i RESULT=$STF_PASS
  62 
  63 function cleanup {
  64         
  65         # Note that $TEST_SERVICE may or may not exist so don't check
  66         # results.  Just make sure the service is gone.
  67 
  68         service_cleanup ${TEST_SERVICE}
  69         service_exists ${TEST_SERVICE}
  70         [[ $? -eq 0 ]] && {
  71                 echo "--DIAG: [${assertion}, cleanup]
  72                 service ${TEST_SERVICE} should not exist in 
  73                 repository after being deleted, but does"
  74 
  75                 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
  76         }
  77 
  78         rm -f $OUTFILE $ERRFILE 
  79 
  80         exit $RESULT
  81 } 
  82 
  83 trap cleanup 0 1 2 15
  84 
  85 # make sure that the environment is sane - svc.configd is up and running
  86 check_gl_env
  87 [[ $? -ne 0 ]] && {
  88         echo "--DIAG:
  89         Invalid test environment - svc.configd not available"
  90 
  91         RESULT=$STF_UNRESOLVED 
  92         exit $RESULT
  93 }
  94 
  95 # Before starting make sure that the test service doesn't already exist.
  96 # If it does then consider it a fatal error.
  97 service_exists $TEST_SERVICE
  98 [[ $? -eq 0 ]] && {
  99         echo "--DIAG: [${assertion}]
 100         service $TEST_SERVICE should not exist in repository but does"
 101 
 102         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 103         exit $RESULT
 104 }
 105 
 106 
 107 #
 108 # Add the service.  If this fails consider it a fatal error
 109 #
 110 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
 111 ret=$?
 112 [[ $ret -ne 0 ]] && {
 113         echo "--DIAG: [${assertion}]
 114         error adding service $TEST_SERVICE needed for test
 115         error output is $(cat $ERRFILE)"
 116 
 117         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 118         exit $RESULT
 119 }
 120 
 121 
 122 # extract and print assertion information from this source script.
 123 extract_assertion_info $ME
 124 
 125 #
 126 # Test #1: not existent file
 127 #
 128 
 129 echo "--INFO: Starting $assertion, test 1 (non-existent file)"
 130 
 131 typeset -i TEST_RESULT=$STF_PASS
 132 
 133 typeset editor_file=/tmp/tmp/foo.$$
 134 
 135 [[ -f "$editor_file" ]] && {
 136         echo "--DIAG: [${assertion}, test 1]
 137         error - file $editor_file should not exist but does"
 138 
 139         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 140         exit $RESULT
 141 }
 142 
 143 export EDITOR=$editor_file
 144 
 145 cat << EOF >> $CMDFILE
 146 select $TEST_SERVICE
 147 editprop 
 148 EOF
 149 
 150 svccfg -f $CMDFILE> $OUTFILE 2>$ERRFILE
 151 
 152 # Verify that nothing in stdout - non-fatal error
 153 [[ -s $OUTFILE ]] &&  {
 154         echo "--DIAG: [${assertion}, test 1]
 155         stdout not expected, but got $(cat $OUTFILE)"
 156 
 157         TEST_RESULT=$STF_FAIL
 158 }
 159 
 160 # Verify that message in stderr - non-fatal error
 161 if ! egrep -s "$not_FOUND_ERRMSG" $ERRFILE
 162 then
 163         echo "--DIAG: [${assertion}, test 1]
 164         Expected error message \"$not_FOUND_ERRMSG\"
 165         but got \"$(cat $ERRFILE)\""
 166 
 167         TEST_RESULT=$STF_FAIL
 168 fi
 169 
 170 rm -f $ERRFILE $OUTFILE $CMDFILE
 171 
 172 print_result $TEST_RESULT
 173 RESULT=$(update_result $TEST_RESULT $RESULT)
 174 
 175 #
 176 # Test #2: not existent file
 177 
 178 echo "--INFO: Starting $assertion, test 2 (non-executable file)"
 179 
 180 typeset -i TEST_RESULT=$STF_PASS
 181 
 182 typeset editor_file=/tmp/foo.$$
 183 
 184 touch $editor_file > /dev/null 2>&1
 185 chmod a-w $editor_file > /dev/null 2>&1
 186 
 187 [[ -x "$editor_file" ]] && {
 188         echo "--DIAG: [${assertion}, test 2]
 189         error - file $editor_file is executable, but shouldn't be"
 190 
 191         RESULT=$(update_result $STF_UNRESOLVED $RESULT)
 192         exit $RESULT
 193 }
 194 
 195 export EDITOR=$editor_file
 196 
 197 cat << EOF >> $CMDFILE
 198 select $TEST_SERVICE
 199 editprop 
 200 EOF
 201 
 202 svccfg -f $CMDFILE> $OUTFILE 2>$ERRFILE
 203 
 204 # Verify that nothing in stdout - non-fatal error
 205 [[ -s $OUTFILE ]] &&  {
 206         echo "--DIAG: [${assertion}, test 2]
 207         stdout not expected, but got $(cat $OUTFILE)"
 208 
 209         TEST_RESULT=$STF_FAIL
 210 }
 211 
 212 # Verify that message in stderr - non-fatal error
 213 if ! egrep -s "$CANNOT_EXECUTE_ERRMSG" $ERRFILE
 214 then
 215         echo "--DIAG: [${assertion}, test 2]
 216         Expected error message \"$CANNOT_EXECUTE_ERRMSG\"
 217         but got \"$(cat $ERRFILE)\""
 218 
 219         TEST_RESULT=$STF_FAIL
 220 fi
 221 
 222 
 223 rm -f $ERRFILE $OUTFILE $CMDFILE
 224 
 225 print_result $TEST_RESULT
 226 RESULT=$(update_result $TEST_RESULT $RESULT)
 227 
 228 #
 229 # Test #3: null definition
 230 #
 231 
 232 echo "--INFO: Starting $assertion, test 3 (null definition)"
 233 
 234 typeset -i TEST_RESULT=$STF_PASS
 235 
 236 
 237 export EDITOR=
 238 
 239 cat << EOF >> $CMDFILE
 240 select $TEST_SERVICE
 241 editprop 
 242 EOF
 243 
 244 svccfg -f $CMDFILE> $OUTFILE 2>$ERRFILE
 245 
 246 # Verify that nothing in stdout - non-fatal error
 247 [[ -s $OUTFILE ]] &&  {
 248         echo "--DIAG: [${assertion}, test 3]
 249         stdout not expected, but got $(cat $OUTFILE)"
 250 
 251         TEST_RESULT=$STF_FAIL
 252 }
 253 
 254 # Verify that message in stderr - non-fatal error
 255 if ! egrep -s "$CANNOT_EXECUTE_ERRMSG" $ERRFILE
 256 then
 257         echo "--DIAG: [${assertion}, test 3]
 258         Expected error message \"$CANNOT_EXECUTE_ERRMSG\"
 259         but got \"$(cat $ERRFILE)\""
 260 
 261         TEST_RESULT=$STF_FAIL
 262 fi
 263 
 264 
 265 rm -f $ERRFILE $OUTFILE $CMDFILE
 266 
 267 print_result $TEST_RESULT
 268 RESULT=$(update_result $TEST_RESULT $RESULT)
 269 
 270 exit $RESULT