kind: ConfigMap
apiVersion: v1
metadata:
    name: gitlab-unicorn-tests
    namespace: gitlab
    selfLink: /api/v1/namespaces/gitlab/configmaps/gitlab-unicorn-tests
    uid: 98103e64-398b-11ea-b115-42010a8001d6
    resourceVersion: '2016135'
    creationTimestamp: '2020-01-18T00:43:50Z'
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 $signin_url --fail -s $cookie_read | grep -Po
        '<meta.*name="csrf-token".*content="\K[a-zA-Z0-9\+=\-\/]*')

        curl --fail -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 -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

