github.com/criteo/command-launcher@v0.0.0-20230407142452-fb616f546e98/test/integration/test-consent.sh (about)

     1  #!/bin/bash
     2  
     3  # required environment varibale
     4  # CL_PATH
     5  # CL_HOME
     6  # OUTPUT_DIR
     7  
     8  SCRIPT_DIR=${1:-$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )}
     9  
    10  ###
    11  # test consent
    12  ###
    13  # First copy the dropin packages for test
    14  rm -rf $CL_HOME/dropins
    15  mkdir -p $CL_HOME/dropins
    16  cp -R $SCRIPT_DIR/../packages-src/login $CL_HOME/dropins
    17  
    18  $CL_PATH config user_consent_life 3s
    19  $CL_PATH login -u test-user -p test-password
    20  
    21  echo "> test consent disabled"
    22  $CL_PATH config enable_user_consent false
    23  RESULT=$($CL_PATH bonjour-consent)
    24  echo "$RESULT"
    25  echo "$RESULT" | grep -q "test-user"
    26  if [ $? -eq 0 ]; then
    27    echo "OK"
    28  else
    29    echo "KO - should pass USERNAME resource to command"
    30    exit 1
    31  fi
    32  
    33  echo "$RESULT" | grep -q "test-password"
    34  if [ $? -eq 0 ]; then
    35    echo "OK"
    36  else
    37    echo "KO - should pass PASSWORD resource to command"
    38    exit 1
    39  fi
    40  
    41  echo "> test consent enabled - user refused"
    42  $CL_PATH config enable_user_consent true
    43  RESULT=$(echo 'n' | $CL_PATH bonjour-consent)
    44  echo "$RESULT"
    45  echo "$RESULT" | grep -q "authorize the access?"
    46  if [ $? -eq 0 ]; then
    47    echo "OK"
    48  else
    49    echo "KO - should request authorization"
    50    exit 1
    51  fi
    52  
    53  echo "$RESULT" | grep -q "test-user"
    54  if [ $? -eq 0 ]; then
    55    echo "KO - should NOT pass USERNAME resource to command"
    56    exit 1
    57  else
    58    echo "OK"
    59  fi
    60  
    61  echo "$RESULT" | grep -q "test-password"
    62  if [ $? -eq 0 ]; then
    63    echo "KO - should NOT pass PASSWORD resource to command"
    64    exit 1
    65  else
    66    echo "OK"
    67  fi
    68  
    69  echo "> test consent enabled - user authorized"
    70  $CL_PATH config enable_user_consent true
    71  RESULT=$(echo 'y' | $CL_PATH bonjour-consent)
    72  echo "$RESULT"
    73  echo "$RESULT" | grep -q "authorize the access?"
    74  if [ $? -eq 0 ]; then
    75    echo "OK"
    76  else
    77    echo "KO - should request authorization"
    78    exit 1
    79  fi
    80  
    81  echo "$RESULT" | grep -q "test-user"
    82  if [ $? -eq 0 ]; then
    83    echo "OK"
    84  else
    85    echo "KO - should pass USERNAME resource to command"
    86    exit 1
    87  fi
    88  
    89  echo "$RESULT" | grep -q "test-password"
    90  if [ $? -eq 0 ]; then
    91    echo "OK"
    92  else
    93    echo "KO - should pass PASSWORD resource to command"
    94    exit 1
    95  fi
    96  
    97  echo "> test consent authorized - should not request authorization again"
    98  $CL_PATH config enable_user_consent true
    99  RESULT=$(echo 'y' | $CL_PATH bonjour-consent)
   100  echo "$RESULT"
   101  echo "$RESULT" | grep -q "authorize the access?"
   102  if [ $? -eq 0 ]; then
   103    echo "KO - should NOT request authorization again"
   104    exit 1
   105  else
   106    echo "OK"
   107  fi
   108  
   109  echo "> test consent authorized - should request authorization once expired"
   110  sleep 5
   111  $CL_PATH config enable_user_consent true
   112  RESULT=$(echo 'y' | $CL_PATH bonjour-consent)
   113  echo "$RESULT"
   114  echo "$RESULT" | grep -q "authorize the access?"
   115  if [ $? -eq 0 ]; then
   116    echo "OK"
   117  else
   118    echo "KO - should request authorization again once expired"
   119    exit 1
   120  fi
   121  
   122