github.com/emreu/go-swagger@v0.22.1/fixtures/bugs/1558/exercise.sh (about)

     1  #! /bin/bash
     2  fixturePath="./gen-fixture-1558-flatten/cmd/nrcodegen-server"
     3  cmd="${fixturePath}/nrcodegen-server"
     4  captured="./srv.log"
     5  
     6  # build fresh server
     7  ./gen-fixtures.sh
     8  
     9  function runWithOpts() {
    10      opts=$1
    11      expectedRet=${2:-0}
    12      echo "Running with opts: ${opts}"
    13      echo "Expected return: ${expectedRet}"
    14  
    15      echo "${cmd} ${opts} 1>${captured} 2>&1 &"
    16      ${cmd} ${opts} 1>${captured} 2>&1 &
    17      pid=$!
    18      sleep 1
    19      ps -efo pid|grep -q ${pid}
    20      isInactive=$? 
    21      if [[ ${isInactive} -eq 0 ]] ; then
    22          ./killme.sh ${pid}
    23      fi
    24      wait $pid
    25      ret=$?
    26      if [[ ${ret} -eq 0 ]] ; then
    27          if [[ ! ${expectedRet} -eq 0 ]] ; then
    28              echo "Expected startup error, got a success instead"
    29              wrong=1
    30          fi
    31          kill ${pid}
    32      else
    33          if [[ ${expectedRet} -eq 0 ]] ; then
    34              echo "Expected correct startup, got an error instead"
    35              wrong=1
    36          else
    37              echo "Expected startup error. OK"
    38          fi
    39      fi
    40      echo "Terminated with ret=${ret}"
    41      if [[ ${expectedRet} -eq 0 ]] ; then
    42          # verifies graceful shutdown
    43          grep -qi "Shutting down" ${captured}
    44          cond1=$?
    45          grep -qi "Stopped serving" ${captured}
    46          cond2=$?
    47          if [[ ${cond1} -ne 0 || ${cond2} -ne 0 ]] ; then
    48              echo "expected graceful shutdown, got:"
    49              wrong=1
    50          else
    51              echo "Terminated gracefully. OK"
    52          fi
    53      fi
    54      if [[ ${wrong} -eq 1 ]] ; then 
    55          echo "Unexpected startup behavior"
    56      fi
    57      echo "Here is the captured output:"
    58      cat ${captured}
    59      rm -f ${captured}
    60  }
    61  
    62  opts1="\
    63      --scheme=https \
    64      --tls-host=0.0.0.0 \
    65      --tls-port=12345 \
    66      --tls-certificate=mycert1.crt \
    67      --tls-ca=myCA.crt \
    68      --tls-key=mycert1.key"
    69  
    70  runWithOpts "${opts1}"
    71  
    72  # wrong ca cert
    73  opts2="\
    74      --scheme=https \
    75      --tls-host=0.0.0.0 \
    76      --tls-port=12345 \
    77      --tls-certificate=mycert1.crt \
    78      --tls-ca=noWheremyCA.crt \
    79      --tls-key=mycert1.key"
    80  
    81  runWithOpts "${opts2}" "1"
    82  
    83  # encrypted priv key
    84  opts3="\
    85      --scheme=https \
    86      --tls-host=0.0.0.0 \
    87      --tls-port=12345 \
    88      --tls-certificate=mycert1.crt \
    89      --tls-key=mycert1.encrypted.key"
    90  
    91  runWithOpts "${opts3}" "1"
    92  
    93  # wrong cert file
    94  opts4="\
    95      --scheme=https \
    96      --tls-host=0.0.0.0 \
    97      --tls-port=12345 \
    98      --tls-certificate=noWheremycert1.crt \
    99      --tls-key=mycert1.key"
   100  
   101  runWithOpts "${opts4}" "1"
   102  
   103  # corrupted CA cert file
   104  opts5="\
   105      --scheme=https \
   106      --tls-host=0.0.0.0 \
   107      --tls-port=12345 \
   108      --tls-certificate=mycert1.crt \
   109      --tls-ca=myCA.corrupted.crt \
   110      --tls-key=mycert1.key"
   111  
   112  runWithOpts "${opts5}" "1"
   113  
   114  # corrupted cert file
   115  opts6="\
   116      --scheme=https \
   117      --tls-host=0.0.0.0 \
   118      --tls-port=12345 \
   119      --tls-certificate=mycert1.corrupted.crt \
   120      --tls-key=mycert1.key"
   121  
   122  runWithOpts "${opts6}" "1"
   123  
   124  # missing cert file
   125  opts7="\
   126      --scheme=https \
   127      --tls-host=0.0.0.0 \
   128      --tls-port=12345 \
   129      --tls-key=mycert1.key"
   130  
   131  runWithOpts "${opts7}" "1"
   132  
   133  # missing key file
   134  opts8="\
   135      --scheme=https \
   136      --tls-host=0.0.0.0 \
   137      --tls-port=12345 \
   138      --tls-certificate=mycert1.crt"
   139  
   140  runWithOpts "${opts8}" "1"
   141