Skip to content

Commit 1bc30e2

Browse files
committed
Fix tests
1 parent 0ca7032 commit 1bc30e2

File tree

4 files changed

+114
-3
lines changed

4 files changed

+114
-3
lines changed

.circleci/config.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ jobs:
4646
- checkout
4747
- run: apt-get install lsof
4848
- run: git config --global url."https://github.com/".insteadOf ssh://[email protected]/
49-
- run: curl -fsSL https://deb.nodesource.com/setup_16.x | bash
50-
- run: apt install -y nodejs
49+
- run: curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
50+
- run: |
51+
set +e
52+
export NVM_DIR="$HOME/.nvm"
53+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
54+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
55+
nvm install 16
56+
57+
echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
58+
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
5159
- run: node --version
5260
- run: echo "127.0.0.1 localhost.org" >> /etc/hosts
5361
- run: go version

.circleci/setupAndTestWithAuthReact.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ git clone [email protected]:supertokens/supertokens-auth-react.git
4949
cd supertokens-auth-react
5050
git checkout $2
5151
npm run init
52-
(cd ./examples/for-tests && npm run link) # this is there because in linux machine, postinstall in npm doesn't work..
5352
cd ./test/server/
5453
npm i -d
5554
npm i git+https://github.com:supertokens/supertokens-node.git#$3

test/auth-react-server/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,43 @@ func callSTInit(passwordlessConfig *plessmodels.TypeInput) {
675675
rw.WriteHeader(200)
676676
rw.Write([]byte("{\"status\": \"OK\"}"))
677677
}).ServeHTTP(rw, r)
678+
} else if r.URL.Path == "/deleteUser" {
679+
bodyBytes, err := ioutil.ReadAll(r.Body)
680+
if err != nil {
681+
rw.WriteHeader(500)
682+
rw.Write([]byte("Internal error"))
683+
return
684+
}
685+
var body map[string]interface{}
686+
err = json.Unmarshal(bodyBytes, &body)
687+
if err != nil {
688+
rw.WriteHeader(500)
689+
rw.Write([]byte("Internal error"))
690+
return
691+
}
692+
693+
if body["rid"] != "emailpassword" {
694+
rw.WriteHeader(400)
695+
rw.Write([]byte("{\"message\": \"Not Implemented\"}"))
696+
return
697+
}
698+
699+
user, err := emailpassword.GetUserByEmail(body["email"].(string))
700+
if err != nil {
701+
rw.WriteHeader(500)
702+
rw.Write([]byte("Internal error"))
703+
return
704+
}
705+
706+
err = supertokens.DeleteUser(user.ID)
707+
if err != nil {
708+
rw.WriteHeader(500)
709+
rw.Write([]byte("Internal error"))
710+
return
711+
}
712+
713+
rw.WriteHeader(200)
714+
rw.Write([]byte("{\"status\": \"OK\"}"))
678715
}
679716
}))
680717

test/frontendIntegration/main.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
package main
1818

1919
import (
20+
"encoding/base64"
2021
"encoding/json"
2122
"fmt"
2223
"io/ioutil"
2324
"net/http"
2425
"os"
2526
"strconv"
2627
"strings"
28+
"time"
2729

2830
"github.com/supertokens/supertokens-golang/recipe/session"
2931
"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
@@ -170,6 +172,8 @@ func callSTInit(enableAntiCsrf bool, enableJWT bool, jwtPropertyName string) {
170172
setEnableJWT(rw, r)
171173
} else if r.URL.Path == "/login" && r.Method == "POST" {
172174
login(rw, r)
175+
} else if r.URL.Path == "/login-2.18" && r.Method == "POST" {
176+
login218(rw, r)
173177
} else if r.URL.Path == "/beforeeach" && r.Method == "POST" {
174178
beforeeach(rw, r)
175179
} else if r.URL.Path == "/testUserConfig" && r.Method == "POST" {
@@ -411,6 +415,69 @@ func login(response http.ResponseWriter, request *http.Request) {
411415
response.Write([]byte(sess.GetUserID()))
412416
}
413417

418+
func login218(response http.ResponseWriter, request *http.Request) {
419+
var body map[string]interface{}
420+
_ = json.NewDecoder(request.Body).Decode(&body)
421+
422+
userID := body["userId"].(string)
423+
payload := body["payload"].(map[string]interface{})
424+
425+
querier, err := supertokens.GetNewQuerierInstanceOrThrowError("session")
426+
427+
if err != nil {
428+
response.WriteHeader(500)
429+
response.Write([]byte(""))
430+
return
431+
}
432+
433+
supertokens.SetQuerierApiVersionForTests("2.18")
434+
resp, err := querier.SendPostRequest("/recipe/session", map[string]interface{}{
435+
"userId": userID,
436+
"userDataInJWT": payload,
437+
"userDataInDatabase": map[string]interface{}{},
438+
"enableAntiCsrf": false,
439+
})
440+
441+
if err != nil {
442+
response.WriteHeader(500)
443+
response.Write([]byte(""))
444+
return
445+
}
446+
447+
supertokens.SetQuerierApiVersionForTests("")
448+
449+
responseByte, err := json.Marshal(resp)
450+
if err != nil {
451+
response.WriteHeader(500)
452+
response.Write([]byte(""))
453+
return
454+
}
455+
var sessionResp sessmodels.CreateOrRefreshAPIResponse
456+
err = json.Unmarshal(responseByte, &sessionResp)
457+
if err != nil {
458+
response.WriteHeader(500)
459+
response.Write([]byte(""))
460+
return
461+
}
462+
463+
legacyAccessToken := sessionResp.AccessToken.Token
464+
legacyRefreshToken := sessionResp.RefreshToken.Token
465+
466+
parsed, _ := json.Marshal(map[string]interface{}{
467+
"uid": userID,
468+
"ate": uint64(time.Now().UnixNano()/1000000) + 3600000,
469+
"up": payload,
470+
})
471+
data := []byte(parsed)
472+
473+
frontToken := base64.StdEncoding.EncodeToString(data)
474+
475+
response.Header().Set("st-access-token", legacyAccessToken)
476+
response.Header().Set("st-refresh-token", legacyRefreshToken)
477+
response.Header().Set("front-token", frontToken)
478+
response.Write([]byte(""))
479+
}
480+
414481
func fail(w http.ResponseWriter, r *http.Request) {
415482
w.WriteHeader(404)
416483
w.Write([]byte(""))

0 commit comments

Comments
 (0)