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

     1  #!/bin/bash
     2  
     3  # availeble environment varibale
     4  # CL_PATH: the path of the command launcher binary
     5  # CL_HOME: the path of the command launcher home directory
     6  # OUTPUT_DIR: the output folder
     7  SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
     8  
     9  METRICS_FILE=$OUTPUT_DIR/../metrics.txt
    10  
    11  # clean up the dropin folder
    12  rm -rf $CL_HOME/dropins
    13  mkdir -p $CL_HOME/dropins
    14  cp -R $SCRIPT_DIR/../packages-src/login $CL_HOME/dropins
    15  
    16  # clean up local repository, remove local repo + configuration
    17  rm -rf $CL_HOME/current
    18  rm -f $CL_HOME/config.json
    19  rm -f $OUTPUT_DIR/../metrics.txt
    20  
    21  
    22  # enable metrics
    23  $CL_PATH config usage_metrics_enabled true
    24  
    25  # setup remote package using local file
    26  echo "> test download remote package with local filer"
    27  # work around to make sure the native path on windows
    28  NATIVE_SCRIPT_DIR=${SCRIPT_DIR/\/c\//C:/}
    29  NATIVE_SCRIPT_DIR=${NATIVE_SCRIPT_DIR/\/d\//D:/}
    30  NATIVE_SCRIPT_DIR=${NATIVE_SCRIPT_DIR/\/e\//E:/}
    31  NATIVE_SCRIPT_DIR=${NATIVE_SCRIPT_DIR/\/f\//F:/}
    32  echo $NATIVE_SCRIPT_DIR
    33  
    34  # enable package setup hook
    35  $CL_PATH config enable_package_setup_hook true
    36  
    37  RESULT=$($OUTPUT_DIR/cl config command_repository_base_url file://${NATIVE_SCRIPT_DIR}/../remote-repo)
    38  RESULT=$($CL_PATH)
    39  
    40  echo "$RESULT"
    41  
    42  echo "$RESULT" | grep -q "hello"
    43  if [ $? -eq 0 ]; then
    44    # ok
    45    echo "OK"
    46  else
    47    echo "KO - hello command should exist"
    48    exit 1
    49  fi
    50  
    51  
    52  echo "> test package setup hook"
    53  echo "$RESULT" | grep -q "calling setup"
    54  if [ $? -eq 0 ]; then
    55    # ok
    56    echo "OK"
    57  else
    58    echo "KO - package setup hook should be called"
    59    exit 1
    60  fi
    61  
    62  
    63  echo "> test system command should not exist"
    64  echo "$RESULT" | grep -q "metrics"
    65  if [ $? -ne 0 ]; then
    66    # ok
    67    echo "OK"
    68  else
    69    echo "KO - system command 'metrics' should not exist"
    70    exit 1
    71  fi
    72  
    73  echo "> test login extension without setup system package"
    74  echo "* should NOT use username returned from extension"
    75  RESULT=$($CL_PATH login -u test-user -p test-password)
    76  RESULT=$($CL_PATH bonjour-consent)
    77  echo "$RESULT" | grep -q "SECRET_1"
    78  if [ $? -ne 0 ]; then
    79    # ok
    80    echo "OK"
    81  else
    82    echo "KO - should NOT use username returned from extension"
    83    exit 1
    84  fi
    85  
    86  echo "* should NOT use password returned from extension"
    87  echo "$RESULT" | grep -q "SECRET_2"
    88  if [ $? -ne 0 ]; then
    89    # ok
    90    echo "OK"
    91  else
    92    echo "KO - should NOT use password returned from extension"
    93    exit 1
    94  fi
    95  
    96  echo "> test metrics extension without setup system package config"
    97  if [ -f $METRICS_FILE ]; then
    98    echo "KO - should NOT have extension metrics file generated"
    99    exit 1
   100  else
   101    echo "OK"
   102  fi
   103  
   104  echo "> test login extension enabled by system package config"
   105  # set system package name
   106  RESULT=$($CL_PATH config system_package system-pkg-demo)
   107  $CL_PATH login -u test-user -p test-password
   108  RESULT=$($CL_PATH bonjour-consent)
   109  
   110  echo "* should use username returned from extension"
   111  echo "$RESULT" | grep -q "SECRET_1"
   112  if [ $? -eq 0 ]; then
   113    # ok
   114    echo "OK"
   115  else
   116    echo "KO - should use username returned from extension"
   117    exit 1
   118  fi
   119  
   120  echo "* should use password returned from extension"
   121  echo "$RESULT" | grep -q "SECRET_2"
   122  if [ $? -eq 0 ]; then
   123    # ok
   124    echo "OK"
   125  else
   126    echo "KO - should use password returned from extension"
   127    exit 1
   128  fi
   129  
   130  echo "* should use login token returned from extension"
   131  echo "$RESULT"
   132  echo "$RESULT" | grep -q "SECRET_3"
   133  if [ $? -eq 0 ]; then
   134    # ok
   135    echo "OK"
   136  else
   137    echo "KO - should use auth_token returned from extension"
   138    exit 1
   139  fi
   140  
   141  echo "> test metrics extension with setup system package config"
   142  echo "* should have metrics file generated by extension"
   143  if [ -f $METRICS_FILE ]; then
   144    echo "OK"
   145  else
   146    echo "KO - should have extension metrics file generated"
   147    exit 1
   148  fi
   149  
   150  echo "> test metrics content"
   151  RESULT=$(cat $OUTPUT_DIR/../metrics.txt)
   152  echo "$RESULT" | grep 'default default default default'
   153  if [ $? -eq 0 ]; then
   154    echo "OK"
   155  else
   156    echo "KO - should have default command in metrics"
   157    exit 1
   158  fi
   159  
   160  echo "$RESULT" | grep 'dropin bonjour default bonjour-consent'
   161  if [ $? -eq 0 ]; then
   162    echo "OK"
   163  else
   164    echo "KO - should have root exectuble command in metrics"
   165    exit 1
   166  fi
   167  
   168  # cleanup
   169  rm -f $OUTPUT_DIR/../metrics.txt