Skip to content

Commit b1c0882

Browse files
committed
initial commit
0 parents  commit b1c0882

File tree

164 files changed

+23111
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+23111
-0
lines changed

.circleci/Dockerfile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM ubuntu:16.04
2+
3+
RUN apt-get update && apt-get upgrade -y
4+
5+
RUN apt-get install build-essential -y
6+
7+
RUN echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
8+
9+
RUN echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections
10+
11+
RUN apt install mysql-server -y
12+
13+
RUN usermod -d /var/lib/mysql/ mysql
14+
15+
RUN mkdir /var/run/mysqld
16+
17+
ADD ./runMySQL.sh /runMySQL.sh
18+
19+
RUN chmod +x /runMySQL.sh
20+
21+
RUN apt-get install -y git-core
22+
23+
RUN apt-get install -y wget
24+
25+
# Install OpenJDK 12
26+
RUN wget https://download.java.net/java/GA/jdk12.0.2/e482c34c86bd4bf8b56c0b35558996b9/10/GPL/openjdk-12.0.2_linux-x64_bin.tar.gz
27+
28+
RUN mkdir /usr/java
29+
30+
RUN mv openjdk-12.0.2_linux-x64_bin.tar.gz /usr/java
31+
32+
RUN cd /usr/java && tar -xzvf openjdk-12.0.2_linux-x64_bin.tar.gz
33+
34+
RUN echo 'JAVA_HOME=/usr/java/jdk-12.0.2' >> /etc/profile
35+
RUN echo 'PATH=$PATH:$HOME/bin:$JAVA_HOME/bin' >> /etc/profile
36+
RUN echo 'export JAVA_HOME' >> /etc/profile
37+
RUN echo 'export JRE_HOME' >> /etc/profile
38+
RUN echo 'export PATH' >> /etc/profile
39+
40+
RUN update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-12.0.2/bin/java" 1
41+
RUN update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-12.0.2/bin/javac" 1
42+
43+
RUN apt-get install jq -y
44+
45+
RUN apt-get install curl -y
46+
47+
RUN apt-get install unzip -y

.circleci/config.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 2
2+
jobs:
3+
test:
4+
docker:
5+
- image: rishabhpoddar/supertokens_core_testing
6+
steps:
7+
- add_ssh_keys:
8+
fingerprints:
9+
- "5a:6d:8f:6a:6d:e3:d6:b3:f9:64:92:db:e7:2a:63:09"
10+
- checkout
11+
- run: (cd .circleci/ && ./doTests.sh)
12+
13+
workflows:
14+
version: 2
15+
tagged-build:
16+
jobs:
17+
- test:
18+
filters:
19+
tags:
20+
only: /dev-v[0-9]+(\.[0-9]+)*/
21+
branches:
22+
ignore: /.*/

.circleci/doTests.sh

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
function cleanup {
2+
if test -f "pluginInterfaceExactVersionsOutput"; then
3+
rm pluginInterfaceExactVersionsOutput
4+
fi
5+
}
6+
7+
trap cleanup EXIT
8+
cleanup
9+
10+
pinnedDBJson=`curl -s -X GET \
11+
'https://api.supertokens.io/0/plugin/pinned?planType=FREE' \
12+
-H 'api-version: 0'`
13+
pinnedDBLength=`echo $pinnedDBJson | jq ".plugins | length"`
14+
pinnedDBArray=`echo $pinnedDBJson | jq ".plugins"`
15+
echo "got pinned dbs..."
16+
17+
pluginInterfaceJson=`cat ../pluginInterfaceSupported.json`
18+
pluginInterfaceLength=`echo $pluginInterfaceJson | jq ".versions | length"`
19+
pluginInterfaceArray=`echo $pluginInterfaceJson | jq ".versions"`
20+
echo "got plugin interface relations"
21+
22+
coreDriverJson=`cat ../coreDriverInterfaceSupported.json`
23+
coreDriverLength=`echo $coreDriverJson | jq ".versions | length"`
24+
coreDriverArray=`echo $coreDriverJson | jq ".versions"`
25+
echo "got core driver relations"
26+
27+
./getPluginInterfaceExactVersions.sh $pluginInterfaceLength "$pluginInterfaceArray"
28+
29+
if [[ $? -ne 0 ]]
30+
then
31+
echo "all plugin interfaces found... failed. exiting!"
32+
exit 1
33+
else
34+
echo "all plugin interfaces found..."
35+
fi
36+
37+
# get core version
38+
coreVersion=`cat ../build.gradle | grep -e "version =" -e "version="`
39+
while IFS='"' read -ra ADDR; do
40+
counter=0
41+
for i in "${ADDR[@]}"; do
42+
if [ $counter == 1 ]
43+
then
44+
coreVersion=$i
45+
fi
46+
counter=$(($counter+1))
47+
done
48+
done <<< "$coreVersion"
49+
50+
responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PUT \
51+
https://api.supertokens.io/0/core \
52+
-H 'Content-Type: application/json' \
53+
-H 'api-version: 0' \
54+
-d "{
55+
\"password\": \"$SUPERTOKENS_API_KEY\",
56+
\"planType\":\"FREE\",
57+
\"version\":\"$coreVersion\",
58+
\"pluginInterfaces\": $pluginInterfaceArray,
59+
\"coreDriverInterfaces\": $coreDriverArray
60+
}"`
61+
if [ $responseStatus -ne "200" ]
62+
then
63+
echo "failed core PUT API status code: $responseStatus. Exiting!"
64+
exit 1
65+
fi
66+
67+
someTestsRan=false
68+
while read line
69+
do
70+
if [[ $line = "" ]]; then
71+
continue
72+
fi
73+
i=0
74+
currTag=`echo $line | jq .tag`
75+
currTag=`echo $currTag | tr -d '"'`
76+
77+
currVersion=`echo $line | jq .version`
78+
currVersion=`echo $currVersion | tr -d '"'`
79+
piX=$(cut -d'.' -f1 <<<"$currVersion")
80+
piY=$(cut -d'.' -f2 <<<"$currVersion")
81+
piVersion="$piX.$piY"
82+
83+
while [ $i -lt $pinnedDBLength ]; do
84+
someTestsRan=true
85+
currPinnedDb=`echo $pinnedDBArray | jq ".[$i]"`
86+
currPinnedDb=`echo $currPinnedDb | tr -d '"'`
87+
88+
i=$((i+1))
89+
90+
response=`curl -s -X GET \
91+
"https://api.supertokens.io/0/plugin-interface/dependency/plugin/latest?password=$SUPERTOKENS_API_KEY
92+
&planType=FREE&mode=DEV&version=$piVersion&pluginName=$currPinnedDb" \
93+
-H 'api-version: 0'`
94+
if [[ `echo $response | jq .plugin` == "null" ]]
95+
then
96+
echo "fetching latest X.Y version for $currPinnedDb given plugin-interface X.Y version: $piVersion gave response: $response"
97+
exit 1
98+
fi
99+
pinnedDbVersionX2=$(echo $response | jq .plugin | tr -d '"')
100+
101+
response=`curl -s -X GET \
102+
"https://api.supertokens.io/0/plugin/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version
103+
=$pinnedDbVersionX2&name=$currPinnedDb" \
104+
-H 'api-version: 0'`
105+
if [[ `echo $response | jq .tag` == "null" ]]
106+
then
107+
echo "fetching latest X.Y.Z version for $currPinnedDb, X.Y version: $pinnedDbVersionX2 gave response: $response"
108+
exit 1
109+
fi
110+
pinnedDbVersionTag=$(echo $response | jq .tag | tr -d '"')
111+
pinnedDbVersion=$(echo $response | jq .version | tr -d '"')
112+
./startDb.sh $currPinnedDb
113+
cd ../../
114+
git clone [email protected]:vrai-labs/com-root.git
115+
cd com-root
116+
coreX=$(cut -d'.' -f1 <<<"$coreVersion")
117+
coreY=$(cut -d'.' -f2 <<<"$coreVersion")
118+
echo -e "core,$coreX.$coreY\nplugin-interface,$piVersion\n$currPinnedDb-plugin,$pinnedDbVersionX2" > modules.txt
119+
./loadModules
120+
cd com-core
121+
git checkout dev-v$coreVersion
122+
cd ../com-plugin-interface
123+
git checkout $currTag
124+
cd ../com-$currPinnedDb-plugin
125+
git checkout $pinnedDbVersionTag
126+
cd ../
127+
echo $SUPERTOKENS_API_KEY > apiPassword
128+
./startTestingEnv --cicd
129+
130+
if [[ $? -ne 0 ]]
131+
then
132+
cat logs/*
133+
cd ../project/
134+
echo "test failed... exiting!"
135+
exit 1
136+
fi
137+
cd ../
138+
rm -rf com-root
139+
curl -o supertokens.zip -s -X GET \
140+
"https://api.supertokens.io/0/app/download?pluginName=$currPinnedDb&os=linux&mode=DEV&binary=FREE&targetCore
141+
=$coreVersion&targetPlugin=$pinnedDbVersion" \
142+
-H 'api-version: 0'
143+
unzip supertokens.zip -d .
144+
rm supertokens.zip
145+
cd supertokens
146+
curl -s -X GET \
147+
"https://api.supertokens.io/0/development/license-key?password=$SUPERTOKENS_API_KEY&planType=FREE&onExpiry
148+
=DOWNGRADE&expired=false" \
149+
-H 'api-version: 0' \
150+
-H 'cache-control: no-cache' > licenseKey
151+
../project/.circleci/testCli.sh
152+
if [[ $? -ne 0 ]]
153+
then
154+
echo "cli testing failed... exiting!"
155+
exit 1
156+
fi
157+
cd ../
158+
rm -rf supertokens
159+
cd project/.circleci
160+
./stopDb.sh $currPinnedDb
161+
done
162+
done <<< `cat pluginInterfaceExactVersionsOutput`
163+
164+
if [[ $someTestsRan = "true" ]]
165+
then
166+
echo "calling /core PATCH to make testing passed"
167+
responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PATCH \
168+
https://api.supertokens.io/0/core \
169+
-H 'Content-Type: application/json' \
170+
-H 'api-version: 0' \
171+
-d "{
172+
\"password\": \"$SUPERTOKENS_API_KEY\",
173+
\"planType\":\"FREE\",
174+
\"version\":\"$coreVersion\",
175+
\"testPassed\": true
176+
}"`
177+
if [ $responseStatus -ne "200" ]
178+
then
179+
echo "patch api failed"
180+
exit 1
181+
fi
182+
else
183+
echo "no test ran"
184+
exit 1
185+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# args: <length of array> <array like ["0.0", "0.1"]>
2+
touch pluginInterfaceExactVersionsOutput
3+
i=0
4+
while [ $i -lt $1 ]; do
5+
currVersion=`echo $2 | jq ".[$i]"`
6+
currVersion=`echo $currVersion | tr -d '"'`
7+
i=$((i+1))
8+
9+
# now we have the current version like 0.0.
10+
# We now have to find something that matches dev-v0.0.* or v0.0.*
11+
response=`curl -s -X GET \
12+
"https://api.supertokens.io/0/plugin-interface/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version
13+
=$currVersion" \
14+
-H 'api-version: 0'`
15+
if [[ `echo $response | jq .tag` == "null" ]]
16+
then
17+
echo $response
18+
exit 1
19+
fi
20+
echo $response >> pluginInterfaceExactVersionsOutput
21+
done

.circleci/runMySQL.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld && service mysql start

.circleci/startDb.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
case $1 in
2+
mysql)
3+
(cd / && ./runMySQL.sh)
4+
mysql -u root --password=root -e "CREATE DATABASE auth_session;"
5+
;;
6+
esac

.circleci/stopDb.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
case $1 in
2+
mysql)
3+
service mysql stop
4+
;;
5+
esac

.circleci/testCli.sh

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# inside supertokens downloaded zip
2+
3+
./install
4+
5+
if [[ $? -ne 0 ]]
6+
then
7+
echo "cli testing failed... exiting!"
8+
exit 1
9+
fi
10+
11+
sed -i 's/# refresh_api_path:/refresh_api_path: \/refresh/g' /usr/lib/supertokens/config.yaml
12+
sed -i 's/# cookie_domain:/cookie_domain: supertokens.io/g' /usr/lib/supertokens/config.yaml
13+
sed -i 's/# mysql_user:/mysql_user: root/g' /usr/lib/supertokens/config.yaml
14+
sed -i 's/# mysql_password:/mysql_password: root/g' /usr/lib/supertokens/config.yaml
15+
16+
supertokens start dev --port=8888
17+
18+
if [[ $? -ne 0 ]]
19+
then
20+
echo "cli testing failed... exiting!"
21+
exit 1
22+
fi
23+
24+
supertokens list
25+
26+
if [[ $? -ne 0 ]]
27+
then
28+
echo "cli testing failed... exiting!"
29+
exit 1
30+
fi
31+
32+
supertokens start dev --port=8889
33+
34+
supertokens list
35+
36+
if [[ $? -ne 0 ]]
37+
then
38+
echo "cli testing failed... exiting!"
39+
exit 1
40+
fi
41+
42+
curl http://localhost:8889/hello
43+
44+
if [[ $? -ne 0 ]]
45+
then
46+
echo "cli testing failed... exiting!"
47+
exit 1
48+
fi
49+
50+
curl http://localhost:8888/hello
51+
52+
if [[ $? -ne 0 ]]
53+
then
54+
echo "cli testing failed... exiting!"
55+
exit 1
56+
fi
57+
58+
supertokens stop
59+
60+
if [[ $? -ne 0 ]]
61+
then
62+
echo "cli testing failed... exiting!"
63+
exit 1
64+
fi
65+
66+
supertokens uninstall
67+
68+
if [[ $? -ne 0 ]]
69+
then
70+
echo "cli testing failed... exiting!"
71+
exit 1
72+
fi

0 commit comments

Comments
 (0)