Skip to content

Commit 7e53b10

Browse files
authored
fix: test server for backend-sdk-testing (#422)
* fix: domains in apiversion call * fix: boxy validation * fix: IncludeInNonPublicTenantsByDefault in provider input * fix: test server for backend-sdk-testing * fix: thirdparty and multitenancy * fix: jwks url fix * fix: jwks cache and test fixes * fix: changelog and version * fix: circle ci * fix: generateConfig * fix: update circle ci image * fix: go script * fix: go install * fix: go version * fix: go.mod * fix: circle ci script restore * fix: pre commit * fix: pre commit * fix: pre commit * fix: pr comment * fix: pr comment * fix: pr comment * fix: pre commit * fix: pre commit * fix: pre commit * fix: pre commit * fix: not exposing new session function used in test server * fix: pr comments * fix: pre commit hook * fix: contributing
1 parent 319c4c2 commit 7e53b10

Some content is hidden

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

48 files changed

+2540
-128
lines changed

.circleci/config_continue.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@ jobs:
2929
- run: go get ./...
3030
- run: (cd .circleci/ && ./doUnitTests.sh << parameters.cdi-version >>)
3131
- slack/status
32+
test-backend-sdk-testing:
33+
docker:
34+
- image: rishabhpoddar/supertokens_node_driver_testing_node_20
35+
resource_class: large
36+
parameters:
37+
cdi-version:
38+
type: string
39+
fdi-version:
40+
type: string
41+
steps:
42+
- checkout
43+
- run: apt-get install lsof
44+
- run: echo "127.0.0.1 localhost.org" >> /etc/hosts
45+
- run: rm -rf /etc/alternatives/java
46+
- run: ln -s /usr/java/jdk-15.0.1/bin/java /etc/alternatives/java
47+
- run:
48+
name: Install Go 1.18.10
49+
command: |
50+
wget https://go.dev/dl/go1.18.10.linux-amd64.tar.gz
51+
rm -rf /usr/local/go
52+
tar -C /usr/local -xzf go1.18.10.linux-amd64.tar.gz
53+
echo 'export PATH=$PATH:/usr/local/go/bin' >> $BASH_ENV
54+
source $BASH_ENV
55+
- run: go version
56+
- run: go get ./...
57+
- run: (cd .circleci/ && ./doBackendSDKTests.sh << parameters.cdi-version >> << parameters.fdi-version >>)
58+
- slack/status
3259
test-website:
3360
docker:
3461
- image: rishabhpoddar/supertokens_go_driver_testing
@@ -128,16 +155,30 @@ workflows:
128155
only: /dev-v[0-9]+(\.[0-9]+)*/
129156
branches:
130157
only: /test-cicd\/.*/
158+
- test-backend-sdk-testing:
159+
requires:
160+
- test-dev-tag-as-not-passed
161+
context:
162+
- slack-notification
163+
filters:
164+
tags:
165+
only: /dev-v[0-9]+(\.[0-9]+)*/
166+
branches:
167+
only: /test-cicd\/.*/
168+
matrix:
169+
parameters:
170+
cdi-version: placeholder
171+
fdi-version: placeholder
131172
- test-success:
132173
requires:
133174
- test-unit
134175
- test-website
135176
- test-authreact
177+
- test-backend-sdk-testing
136178
context:
137179
- slack-notification
138180
filters:
139181
tags:
140182
only: /dev-v[0-9]+(\.[0-9]+)*/
141183
branches:
142184
ignore: /.*/
143-

.circleci/doBackendSDKTests.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
echo "Starting tests for CDI $1, FDI $2";
2+
3+
if [ -z "$SUPERTOKENS_API_KEY" ]; then
4+
echo "SUPERTOKENS_API_KEY not set"
5+
exit 1
6+
fi
7+
8+
coreDriverVersion=$1
9+
coreDriverVersion=`echo $coreDriverVersion | tr -d '"'`
10+
11+
frontendDriverVersion=$2
12+
13+
coreFree=`curl -s -X GET \
14+
"https://api.supertokens.io/0/core-driver-interface/dependency/core/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$coreDriverVersion&driverName=golang" \
15+
-H 'api-version: 1'`
16+
if [[ `echo $coreFree | jq .core` == "null" ]]
17+
then
18+
echo "fetching latest X.Y version for core given core-driver-interface X.Y version: $coreDriverVersion, planType: FREE gave response: $coreFree. Please make sure all relevant cores have been pushed."
19+
exit 1
20+
fi
21+
coreFree=$(echo $coreFree | jq .core | tr -d '"')
22+
23+
./setupAndTestBackendSDKWithFreeCore.sh $coreFree $coreDriverVersion $frontendDriverVersion
24+
if [[ $? -ne 0 ]]
25+
then
26+
echo "test failed... exiting!"
27+
exit 1
28+
fi
29+
rm -rf ../../supertokens-root

.circleci/generateConfig.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
coreDriverJson=`cat ../coreDriverInterfaceSupported.json`
22
coreDriverArray=`echo $coreDriverJson | jq ".versions"`
33

4+
frontendDriverJson=`cat ../frontendDriverInterfaceSupported.json`
5+
frontendDriverArray=`echo $frontendDriverJson | jq ".versions"`
6+
47
if [ -z "$SUPERTOKENS_API_KEY" ]; then
58
echo "SUPERTOKENS_API_KEY missing"
69
exit 1;
710
fi
811

912
sed -i -e 's/cdi-version: placeholder/cdi-version: '`printf "%q" $coreDriverArray`'/' config_continue.yml
13+
sed -i -e 's/fdi-version: placeholder/fdi-version: '`printf "%q" $frontendDriverArray`'/' config_continue.yml
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
coreInfo=`curl -s -X GET \
2+
"https://api.supertokens.io/0/core/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$1" \
3+
-H 'api-version: 0'`
4+
if [[ `echo $coreInfo | jq .tag` == "null" ]]
5+
then
6+
echo "fetching latest X.Y.Z version for core, X.Y version: $1, planType: FREE gave response: $coreInfo"
7+
exit 1
8+
fi
9+
coreTag=$(echo $coreInfo | jq .tag | tr -d '"')
10+
coreVersion=$(echo $coreInfo | jq .version | tr -d '"')
11+
12+
pluginInterfaceVersionXY=`curl -s -X GET \
13+
"https://api.supertokens.io/0/core/dependency/plugin-interface/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$1" \
14+
-H 'api-version: 0'`
15+
if [[ `echo $pluginInterfaceVersionXY | jq .pluginInterface` == "null" ]]
16+
then
17+
echo "fetching latest X.Y version for plugin-interface, given core X.Y version: $1, planType: FREE gave response: $pluginInterfaceVersionXY"
18+
exit 1
19+
fi
20+
pluginInterfaceVersionXY=$(echo $pluginInterfaceVersionXY | jq .pluginInterface | tr -d '"')
21+
22+
pluginInterfaceInfo=`curl -s -X GET \
23+
"https://api.supertokens.io/0/plugin-interface/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$pluginInterfaceVersionXY" \
24+
-H 'api-version: 0'`
25+
if [[ `echo $pluginInterfaceInfo | jq .tag` == "null" ]]
26+
then
27+
echo "fetching latest X.Y.Z version for plugin-interface, X.Y version: $pluginInterfaceVersionXY, planType: FREE gave response: $pluginInterfaceInfo"
28+
exit 1
29+
fi
30+
pluginInterfaceTag=$(echo $pluginInterfaceInfo | jq .tag | tr -d '"')
31+
pluginInterfaceVersion=$(echo $pluginInterfaceInfo | jq .version | tr -d '"')
32+
33+
echo "Backend SDK Testing with FREE core: $coreVersion, plugin-interface: $pluginInterfaceVersion, fdi-version: $3"
34+
35+
cd ../../
36+
git clone git@github.com:supertokens/supertokens-root.git
37+
cd supertokens-root
38+
if [[ $2 == "2.0" ]] || [[ $2 == "2.1" ]] || [[ $2 == "2.2" ]]
39+
then
40+
git checkout 36e5af1b9a4e3b07247d0cf333cf82a071a78681
41+
fi
42+
echo -e "core,$1\nplugin-interface,$pluginInterfaceVersionXY" > modules.txt
43+
./loadModules --ssh
44+
cd supertokens-core
45+
git checkout $coreTag
46+
cd ../supertokens-plugin-interface
47+
git checkout $pluginInterfaceTag
48+
cd ../
49+
echo $SUPERTOKENS_API_KEY > apiPassword
50+
./utils/setupTestEnvLocal
51+
cd ../project/
52+
53+
API_PORT=3030
54+
ST_CONNECTION_URI=http://localhost:8081
55+
56+
# start test-server
57+
pushd test/test-server
58+
sh setup-for-test.sh
59+
API_PORT=$API_PORT ST_CONNECTION_URI=$ST_CONNECTION_URI /usr/local/go/bin/go run . &
60+
popd
61+
62+
frontendDriverVersion=$3
63+
# run tests
64+
cd ../
65+
git clone git@github.com:supertokens/backend-sdk-testing.git
66+
cd backend-sdk-testing
67+
git checkout $frontendDriverVersion
68+
npm install
69+
npm run build
70+
71+
if ! [[ -z "${CIRCLE_NODE_TOTAL}" ]]; then
72+
API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npx mocha --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --no-config --timeout 500000 $(npx mocha-split-tests -r ./runtime.log -t $CIRCLE_NODE_TOTAL -g $CIRCLE_NODE_INDEX -f 'test/**/*.test.js')
73+
else
74+
API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npm test
75+
fi
76+
77+
# kill test-server
78+
kill $(lsof -t -i:$API_PORT)

.github/workflows/enforce-go-mod-tidy.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ on: [pull_request]
33
jobs:
44
go_mod_tidy_job:
55
runs-on: ubuntu-latest
6-
container: rishabhpoddar/supertokens_go_driver_testing
76
steps:
87
- uses: actions/checkout@v2
9-
# When using actions/checkout in a custom container, the directory is not treated as a git repo and does not have a .git directory, therefore we need to initialize it as a git repo. This will allows us to track changes made after go mod tidy runs
8+
- name: Set up go
9+
uses: actions/setup-go@v5
1010
- name: Create a new git repository
11-
run: git init && git add --all && git -c user.name='test' -c user.email='test@example.com' commit -m 'init for pr action'
12-
- name: Install latest go
13-
run: wget https://go.dev/dl/go1.21.3.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go*.tar.gz && export PATH=$PATH:/usr/local/go/bin && rm go1.21.3.linux-amd64.tar.gz
11+
run: rm -rf .git && git init && git add --all && git -c user.name='test' -c user.email='test@example.com' commit -m 'init for pr action'
1412
- name: Go mod tidy for root project
1513
run: go mod tidy
1614
- name: Go mod tidy for example apps
1715
working-directory: ./examples
1816
run: go mod tidy
17+
- name: Go mod tidy for test server
18+
working-directory: ./test/test-server
19+
run: go mod tidy
20+
- name: git status
21+
run: git status
1922
- name: Check for file changes by go mod tidy
20-
run: git status | grep -q 'nothing to commit, working directory clean' && exit 0 || exit 1
23+
run: git status | grep -q 'nothing to commit, working tree clean' && exit 0 || exit 1

.github/workflows/pre-commit-hook-run.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ jobs:
1212
pr-title:
1313
name: Pre commit hook check
1414
runs-on: ubuntu-latest
15-
container: rishabhpoddar/supertokens_go_driver_testing
1615
steps:
1716
- uses: actions/checkout@v2
18-
- name: Set up node
19-
uses: actions/setup-node@v1
17+
- name: Set up go
18+
uses: actions/setup-go@v5
2019
with:
21-
node-version: '12'
22-
- run: git init && git add --all && git -c user.name='test' -c user.email='test@example.com' commit -m 'init for pr action'
23-
- name: Install latest go
24-
run: wget https://go.dev/dl/go1.21.3.linux-amd64.tar.gz && rm -rf /usr/local/go && tar -C /usr/local -xzf go*.tar.gz && export PATH=$PATH:/usr/local/go/bin && rm go1.21.3.linux-amd64.tar.gz
20+
go-version: '1.18'
21+
- run: rm -rf .git && git init && git add --all && git -c user.name='test' -c user.email='test@example.com' commit -m 'init for pr action'
2522
- run: ./hooks/pre-commit.sh

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ releasePassword
2323
.vscode/
2424
.idea/
2525
/test_report
26+
27+
build-errors.log
28+
main
29+
30+
recipe/**/*_for_test_server.go

CHANGELOG.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,133 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.24.0] - 2024-07-29
11+
12+
### Changes
13+
14+
- Adds test server for `backend-sdk-testing`
15+
- Sends `websiteDomain` and `apiDomain` to core for telemetry.
16+
- `boxyURL` is no more mandatory input in `additionalConfig` while adding boxy-saml provider in thirdParty.
17+
- Adds `JWKSRefreshIntervalSec` config to `sessmodels.TypeInput` to set the default JWKS cache duration. The default is 4 hours.
18+
19+
20+
### Breaking changes
21+
22+
- Updates `NetworkInterceptor` function signature to return `error` along with `*http.Request`
23+
- SDK will no longer add `.well-known/openid-configuration` to the `OIDCDiscoveryEndpoint` config in thirdParty providers. If you have specified any custom `OIDCDiscoveryEndpoint` in the ThirdParty.init or added to the core, please make sure to update them to include `.well-known/openid-configuration`.
24+
- For a non-public tenant, when there are no providers added in the core, the SDK used to fallback to the providers added in the ThirdParty.init. Now, the SDK will not fallback to the providers added in the ThirdParty.init by default. If you require a thirdparty provider to be available for non-public tenants, you can make it available by setting `IncludeInNonPublicTenantsByDefault` for each of the providers. See the migration section below to see how to do this. Note that this only affects non-public tenants when there are no providers added in core.
25+
26+
### Migration
27+
28+
#### Make providers available in non-public tenants by default
29+
30+
To make all the providers added in the ThirdParty.init available for non-public tenants by default,
31+
32+
Before:
33+
34+
```go
35+
thirdparty.Init(&tpmodels.TypeInput{
36+
SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{
37+
Providers: []tpmodels.ProviderInput{
38+
{
39+
Config: tpmodels.ProviderConfig{
40+
ThirdPartyId: "google",
41+
// rest of the config
42+
},
43+
},
44+
{
45+
Config: tpmodels.ProviderConfig{
46+
ThirdPartyId: "github",
47+
// rest of the config
48+
},
49+
},
50+
},
51+
},
52+
})
53+
```
54+
55+
After:
56+
57+
```go
58+
thirdparty.Init(&tpmodels.TypeInput{
59+
SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{
60+
Providers: []tpmodels.ProviderInput{
61+
{
62+
Config: tpmodels.ProviderConfig{
63+
ThirdPartyId: "google",
64+
// rest of the config
65+
},
66+
67+
// Add the following line to make this provider available in non-public tenants by default
68+
IncludeInNonPublicTenantsByDefault: true,
69+
},
70+
{
71+
Config: tpmodels.ProviderConfig{
72+
ThirdPartyId: "github",
73+
// rest of the config
74+
},
75+
76+
// Add the following line to make this provider available in non-public tenants by default
77+
IncludeInNonPublicTenantsByDefault: true,
78+
},
79+
},
80+
},
81+
})
82+
```
83+
84+
#### Migrating `oidcDiscoveryEndpoint` in core (for custom providers only):
85+
86+
For each tenant, do the following
87+
88+
1. GET `/appid-<appId>/<tenantId>/recipe/multitenancy/tenant/v2`
89+
90+
You should see the thirdParty providers in the response using `response.thirdParty.providers`
91+
92+
2. For each config in providers list, if you have `oidcDiscoveryEndpoint` in the config, update it to include `.well-known/openid-configuration` at the end.
93+
94+
Here's a sample code snippet to update the `oidcDiscoveryEndpoint`:
95+
96+
```go
97+
package main
98+
99+
import (
100+
"log"
101+
"slices"
102+
"strings"
103+
104+
"github.com/supertokens/supertokens-golang/recipe/multitenancy"
105+
)
106+
107+
func isCustomProvider(thirdPartyId string) bool {
108+
customProviders := []string{
109+
"custom",
110+
//... all your custom thirdPartyIds
111+
}
112+
return slices.Contains(customProviders, thirdPartyId)
113+
}
114+
115+
func main() {
116+
tenantRes, err := multitenancy.ListAllTenants()
117+
if err != nil {
118+
log.Fatal(err)
119+
}
120+
121+
tenants := tenantRes.OK.Tenants
122+
123+
for _, tenant := range tenants {
124+
for _, provider := range tenant.ThirdParty.Providers {
125+
if isCustomProvider(provider.ThirdPartyId) && provider.OIDCDiscoveryEndpoint != "" {
126+
provider.OIDCDiscoveryEndpoint = strings.TrimSuffix(provider.OIDCDiscoveryEndpoint, "/")
127+
provider.OIDCDiscoveryEndpoint = provider.OIDCDiscoveryEndpoint + "/.well-known/openid-configuration"
128+
129+
multitenancy.CreateOrUpdateThirdPartyConfig(tenant.TenantId, provider, nil)
130+
}
131+
}
132+
}
133+
}
134+
```
135+
136+
10137
## [0.23.0] - 2024-07-10
11138

12139
### Breaking Changes

0 commit comments

Comments
 (0)