apiVersion: v1
data:
  test_login: |
    set -e
    echo 'Start Test'
    endpoint="https://gitlab.example.com"
    cookie_read="-c /tmp/test_login.cookie"
    cookie_readwrite="$cookie_read -b /tmp/test_login.cookie"

    signin_url="$endpoint/users/sign_in"
    echo "Login to create a session: $signin_url"
    csrf=$(curl -L $signin_url --fail -s $cookie_read | grep -Po '<meta.*name="csrf-token".*content="\K[a-zA-Z0-9\+=\-\/]*')
    curl -X POST $signin_url -s $cookie_readwrite -F "authenticity_token=$csrf" -F 'user[login]=root' -F "user[password]=$(cat /initial_root_password)"

    profile_url="$endpoint/-/profile"
    echo "Confirm session valid: $profile_url"
    profile_status=$(curl -L -s -o /tmp/profile_output -w "%{http_code}" $cookie_readwrite $profile_url)

    if [ "$profile_status" != "200" ]; then
      echo "Error: Session Invalid"
      cat /tmp/profile_output
      exit 1
    fi

    echo 'Test Passed'
    exit 0
kind: ConfigMap
metadata:
  name: RELEASE-NAME-webservice-tests
  namespace: default
