Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test server for backend-sdk-testing #422

Merged
merged 30 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d6d5c75
fix: domains in apiversion call
sattvikc Jul 24, 2024
0e57e87
fix: boxy validation
sattvikc Jul 24, 2024
443958a
fix: IncludeInNonPublicTenantsByDefault in provider input
sattvikc Jul 24, 2024
ed69b82
fix: test server for backend-sdk-testing
sattvikc Jul 26, 2024
c0622ec
fix: thirdparty and multitenancy
sattvikc Jul 26, 2024
a651892
fix: jwks url fix
sattvikc Jul 26, 2024
29eef08
fix: jwks cache and test fixes
sattvikc Jul 26, 2024
d33398b
fix: changelog and version
sattvikc Jul 29, 2024
4a5b24f
fix: circle ci
sattvikc Jul 29, 2024
5c32c22
fix: generateConfig
sattvikc Jul 29, 2024
85818ee
fix: update circle ci image
sattvikc Jul 29, 2024
55af14d
fix: go script
sattvikc Jul 29, 2024
ae585fe
fix: go install
sattvikc Jul 29, 2024
3958e2f
fix: go version
sattvikc Jul 29, 2024
cc48162
fix: go.mod
sattvikc Jul 29, 2024
30d4f46
fix: circle ci script restore
sattvikc Jul 29, 2024
e441071
fix: pre commit
sattvikc Jul 29, 2024
12b798d
fix: pre commit
sattvikc Jul 29, 2024
3545586
fix: pre commit
sattvikc Jul 29, 2024
9b47d6d
fix: pr comment
sattvikc Jul 29, 2024
b5a9033
fix: pr comment
sattvikc Jul 29, 2024
d4cf075
fix: pr comment
sattvikc Jul 29, 2024
0a99e76
fix: pre commit
sattvikc Jul 29, 2024
ca07226
fix: pre commit
sattvikc Jul 29, 2024
538d7ae
fix: pre commit
sattvikc Jul 29, 2024
06a718c
fix: pre commit
sattvikc Jul 29, 2024
13cfa9a
fix: not exposing new session function used in test server
sattvikc Jul 29, 2024
d9365b1
fix: pr comments
sattvikc Jul 29, 2024
41cd5be
fix: pre commit hook
sattvikc Jul 29, 2024
3581e1a
fix: contributing
sattvikc Jul 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .circleci/config_continue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ jobs:
- run: go get ./...
- run: (cd .circleci/ && ./doUnitTests.sh << parameters.cdi-version >>)
- slack/status
test-backend-sdk-testing:
docker:
- image: rishabhpoddar/supertokens_node_driver_testing_node_20
resource_class: large
parameters:
cdi-version:
type: string
fdi-version:
type: string
steps:
- checkout
- run: apt-get install lsof
- run: echo "127.0.0.1 localhost.org" >> /etc/hosts
- run: rm -rf /etc/alternatives/java
- run: ln -s /usr/java/jdk-15.0.1/bin/java /etc/alternatives/java
- run:
name: Install Go 1.18.10
command: |
wget https://go.dev/dl/go1.18.10.linux-amd64.tar.gz
rm -rf /usr/local/go
tar -C /usr/local -xzf go1.18.10.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> $BASH_ENV
source $BASH_ENV
- run: go version
- run: go get ./...
- run: (cd .circleci/ && ./doBackendSDKTests.sh << parameters.cdi-version >> << parameters.fdi-version >>)
- slack/status
test-website:
docker:
- image: rishabhpoddar/supertokens_go_driver_testing
Expand Down Expand Up @@ -128,16 +155,30 @@ workflows:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
only: /test-cicd\/.*/
- test-backend-sdk-testing:
requires:
- test-dev-tag-as-not-passed
context:
- slack-notification
filters:
tags:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
only: /test-cicd\/.*/
matrix:
parameters:
cdi-version: placeholder
fdi-version: placeholder
- test-success:
requires:
- test-unit
- test-website
- test-authreact
- test-backend-sdk-testing
context:
- slack-notification
filters:
tags:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/

29 changes: 29 additions & 0 deletions .circleci/doBackendSDKTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
echo "Starting tests for CDI $1, FDI $2";

if [ -z "$SUPERTOKENS_API_KEY" ]; then
echo "SUPERTOKENS_API_KEY not set"
exit 1
fi

coreDriverVersion=$1
coreDriverVersion=`echo $coreDriverVersion | tr -d '"'`

frontendDriverVersion=$2

coreFree=`curl -s -X GET \
"https://api.supertokens.io/0/core-driver-interface/dependency/core/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$coreDriverVersion&driverName=golang" \
-H 'api-version: 1'`
if [[ `echo $coreFree | jq .core` == "null" ]]
then
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."
exit 1
fi
coreFree=$(echo $coreFree | jq .core | tr -d '"')

./setupAndTestBackendSDKWithFreeCore.sh $coreFree $coreDriverVersion $frontendDriverVersion
if [[ $? -ne 0 ]]
then
echo "test failed... exiting!"
exit 1
fi
rm -rf ../../supertokens-root
4 changes: 4 additions & 0 deletions .circleci/generateConfig.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
coreDriverJson=`cat ../coreDriverInterfaceSupported.json`
coreDriverArray=`echo $coreDriverJson | jq ".versions"`

frontendDriverJson=`cat ../frontendDriverInterfaceSupported.json`
frontendDriverArray=`echo $frontendDriverJson | jq ".versions"`

if [ -z "$SUPERTOKENS_API_KEY" ]; then
echo "SUPERTOKENS_API_KEY missing"
exit 1;
fi

sed -i -e 's/cdi-version: placeholder/cdi-version: '`printf "%q" $coreDriverArray`'/' config_continue.yml
sed -i -e 's/fdi-version: placeholder/fdi-version: '`printf "%q" $frontendDriverArray`'/' config_continue.yml
78 changes: 78 additions & 0 deletions .circleci/setupAndTestBackendSDKWithFreeCore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
coreInfo=`curl -s -X GET \
"https://api.supertokens.io/0/core/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$1" \
-H 'api-version: 0'`
if [[ `echo $coreInfo | jq .tag` == "null" ]]
then
echo "fetching latest X.Y.Z version for core, X.Y version: $1, planType: FREE gave response: $coreInfo"
exit 1
fi
coreTag=$(echo $coreInfo | jq .tag | tr -d '"')
coreVersion=$(echo $coreInfo | jq .version | tr -d '"')

pluginInterfaceVersionXY=`curl -s -X GET \
"https://api.supertokens.io/0/core/dependency/plugin-interface/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$1" \
-H 'api-version: 0'`
if [[ `echo $pluginInterfaceVersionXY | jq .pluginInterface` == "null" ]]
then
echo "fetching latest X.Y version for plugin-interface, given core X.Y version: $1, planType: FREE gave response: $pluginInterfaceVersionXY"
exit 1
fi
pluginInterfaceVersionXY=$(echo $pluginInterfaceVersionXY | jq .pluginInterface | tr -d '"')

pluginInterfaceInfo=`curl -s -X GET \
"https://api.supertokens.io/0/plugin-interface/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$pluginInterfaceVersionXY" \
-H 'api-version: 0'`
if [[ `echo $pluginInterfaceInfo | jq .tag` == "null" ]]
then
echo "fetching latest X.Y.Z version for plugin-interface, X.Y version: $pluginInterfaceVersionXY, planType: FREE gave response: $pluginInterfaceInfo"
exit 1
fi
pluginInterfaceTag=$(echo $pluginInterfaceInfo | jq .tag | tr -d '"')
pluginInterfaceVersion=$(echo $pluginInterfaceInfo | jq .version | tr -d '"')

echo "Backend SDK Testing with FREE core: $coreVersion, plugin-interface: $pluginInterfaceVersion, fdi-version: $3"

cd ../../
git clone [email protected]:supertokens/supertokens-root.git
cd supertokens-root
if [[ $2 == "2.0" ]] || [[ $2 == "2.1" ]] || [[ $2 == "2.2" ]]
then
git checkout 36e5af1b9a4e3b07247d0cf333cf82a071a78681
fi
echo -e "core,$1\nplugin-interface,$pluginInterfaceVersionXY" > modules.txt
./loadModules --ssh
cd supertokens-core
git checkout $coreTag
cd ../supertokens-plugin-interface
git checkout $pluginInterfaceTag
cd ../
echo $SUPERTOKENS_API_KEY > apiPassword
./utils/setupTestEnvLocal
cd ../project/

API_PORT=3030
ST_CONNECTION_URI=http://localhost:8081

# start test-server
pushd test/test-server
sh setup-for-test.sh
API_PORT=$API_PORT ST_CONNECTION_URI=$ST_CONNECTION_URI /usr/local/go/bin/go run . &
popd

frontendDriverVersion=$3
# run tests
cd ../
git clone [email protected]:supertokens/backend-sdk-testing.git
cd backend-sdk-testing
git checkout $frontendDriverVersion
npm install
npm run build

if ! [[ -z "${CIRCLE_NODE_TOTAL}" ]]; then
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')
else
API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npm test
fi

# kill test-server
kill $(lsof -t -i:$API_PORT)
15 changes: 9 additions & 6 deletions .github/workflows/enforce-go-mod-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ on: [pull_request]
jobs:
go_mod_tidy_job:
runs-on: ubuntu-latest
container: rishabhpoddar/supertokens_go_driver_testing
steps:
- uses: actions/checkout@v2
# 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
- name: Set up go
uses: actions/setup-go@v5
- name: Create a new git repository
run: git init && git add --all && git -c user.name='test' -c user.email='[email protected]' commit -m 'init for pr action'
- name: Install latest go
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
run: rm -rf .git && git init && git add --all && git -c user.name='test' -c user.email='[email protected]' commit -m 'init for pr action'
- name: Go mod tidy for root project
run: go mod tidy
- name: Go mod tidy for example apps
working-directory: ./examples
run: go mod tidy
- name: Go mod tidy for test server
working-directory: ./test/test-server
run: go mod tidy
- name: git status
run: git status
- name: Check for file changes by go mod tidy
run: git status | grep -q 'nothing to commit, working directory clean' && exit 0 || exit 1
run: git status | grep -q 'nothing to commit, working tree clean' && exit 0 || exit 1
11 changes: 4 additions & 7 deletions .github/workflows/pre-commit-hook-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ jobs:
pr-title:
name: Pre commit hook check
runs-on: ubuntu-latest
container: rishabhpoddar/supertokens_go_driver_testing
steps:
- uses: actions/checkout@v2
- name: Set up node
uses: actions/setup-node@v1
- name: Set up go
uses: actions/setup-go@v5
with:
node-version: '12'
- run: git init && git add --all && git -c user.name='test' -c user.email='[email protected]' commit -m 'init for pr action'
- name: Install latest go
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
go-version: '1.18'
- run: rm -rf .git && git init && git add --all && git -c user.name='test' -c user.email='[email protected]' commit -m 'init for pr action'
- run: ./hooks/pre-commit.sh
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ releasePassword
.vscode/
.idea/
/test_report

build-errors.log
main

recipe/**/*_for_test_server.go
127 changes: 127 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,133 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.24.0] - 2024-07-29

### Changes

- Adds test server for `backend-sdk-testing`
- Sends `websiteDomain` and `apiDomain` to core for telemetry.
- `boxyURL` is no more mandatory input in `additionalConfig` while adding boxy-saml provider in thirdParty.
- Adds `JWKSRefreshIntervalSec` config to `sessmodels.TypeInput` to set the default JWKS cache duration. The default is 4 hours.


### Breaking changes

- Updates `NetworkInterceptor` function signature to return `error` along with `*http.Request`
- 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`.
- 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.

### Migration

#### Make providers available in non-public tenants by default

To make all the providers added in the ThirdParty.init available for non-public tenants by default,

Before:

```go
thirdparty.Init(&tpmodels.TypeInput{
SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{
Providers: []tpmodels.ProviderInput{
{
Config: tpmodels.ProviderConfig{
ThirdPartyId: "google",
// rest of the config
},
},
{
Config: tpmodels.ProviderConfig{
ThirdPartyId: "github",
// rest of the config
},
},
},
},
})
```

After:

```go
thirdparty.Init(&tpmodels.TypeInput{
SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{
Providers: []tpmodels.ProviderInput{
{
Config: tpmodels.ProviderConfig{
ThirdPartyId: "google",
// rest of the config
},

// Add the following line to make this provider available in non-public tenants by default
IncludeInNonPublicTenantsByDefault: true,
},
{
Config: tpmodels.ProviderConfig{
ThirdPartyId: "github",
// rest of the config
},

// Add the following line to make this provider available in non-public tenants by default
IncludeInNonPublicTenantsByDefault: true,
},
},
},
})
```

#### Migrating `oidcDiscoveryEndpoint` in core (for custom providers only):

For each tenant, do the following

1. GET `/appid-<appId>/<tenantId>/recipe/multitenancy/tenant/v2`

You should see the thirdParty providers in the response using `response.thirdParty.providers`

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.

Here's a sample code snippet to update the `oidcDiscoveryEndpoint`:

```go
package main

import (
"log"
"slices"
"strings"

"github.com/supertokens/supertokens-golang/recipe/multitenancy"
)

func isCustomProvider(thirdPartyId string) bool {
customProviders := []string{
"custom",
//... all your custom thirdPartyIds
}
return slices.Contains(customProviders, thirdPartyId)
}

func main() {
tenantRes, err := multitenancy.ListAllTenants()
if err != nil {
log.Fatal(err)
}

tenants := tenantRes.OK.Tenants

for _, tenant := range tenants {
for _, provider := range tenant.ThirdParty.Providers {
if isCustomProvider(provider.ThirdPartyId) && provider.OIDCDiscoveryEndpoint != "" {
provider.OIDCDiscoveryEndpoint = strings.TrimSuffix(provider.OIDCDiscoveryEndpoint, "/")
provider.OIDCDiscoveryEndpoint = provider.OIDCDiscoveryEndpoint + "/.well-known/openid-configuration"

multitenancy.CreateOrUpdateThirdPartyConfig(tenant.TenantId, provider, nil)
}
}
}
}
```


## [0.23.0] - 2024-07-10

### Breaking Changes
Expand Down
Loading
Loading