Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Jul 8, 2024
1 parent fadc4b9 commit 3a7beba
Show file tree
Hide file tree
Showing 37 changed files with 21,199 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import io.supertokens.Main;
import io.supertokens.config.Config;
import io.supertokens.multitenancy.Multitenancy;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.output.Logging;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.utils.SemVer;
Expand Down Expand Up @@ -77,7 +76,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
try {
Multitenancy.saveWebsiteAndAPIDomainForApp(storage, appIdentifier, websiteDomain, apiDomain);
} catch (Exception e) {
// ignore errors
Logging.warn(main, appIdentifier.getAsPublicTenantIdentifier(), "Error while saving website/API domain: " + e.toString());
}
} catch (TenantOrAppNotFoundException | BadPermissionException e) {
throw new ServletException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.output.Logging;
import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
Expand Down Expand Up @@ -69,7 +68,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
}

try {
io.supertokens.webserver.api.emailpassword.Utils.checkIfEmailPasswordIsEnabledForTenant(main, tenantIdentifier, getVersionFromRequest(req));
io.supertokens.webserver.api.emailpassword.Utils.assertIfEmailPasswordIsEnabledForTenant(main, tenantIdentifier, getVersionFromRequest(req));

StorageAndUserIdMapping storageAndUserIdMapping =
getStorageAndUserIdMappingForTenantSpecificApi(req, userId, UserIdType.ANY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
TenantIdentifier tenantIdentifier = getTenantIdentifier(req);
Storage storage = getTenantStorage(req);

io.supertokens.webserver.api.emailpassword.Utils.checkIfEmailPasswordIsEnabledForTenant(main, tenantIdentifier, getVersionFromRequest(req));
io.supertokens.webserver.api.emailpassword.Utils.assertIfEmailPasswordIsEnabledForTenant(main, tenantIdentifier, getVersionFromRequest(req));

EmailPassword.ImportUserResponse importUserResponse = EmailPassword.importUserWithPasswordHash(
tenantIdentifier, storage, main, email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.supertokens.Main;
import io.supertokens.emailpassword.EmailPassword;
import io.supertokens.emailpassword.exceptions.WrongCredentialsException;
import io.supertokens.multitenancy.Multitenancy;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.output.Logging;
import io.supertokens.pluginInterface.RECIPE_ID;
Expand Down Expand Up @@ -77,7 +76,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
}

try {
io.supertokens.webserver.api.emailpassword.Utils.checkIfEmailPasswordIsEnabledForTenant(main, tenantIdentifier, getVersionFromRequest(req));
io.supertokens.webserver.api.emailpassword.Utils.assertIfEmailPasswordIsEnabledForTenant(main, tenantIdentifier, getVersionFromRequest(req));

AuthRecipeUserInfo user = EmailPassword.signIn(tenantIdentifier, storage, super.main, normalisedEmail,
password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.supertokens.ActiveUsers;
import io.supertokens.Main;
import io.supertokens.emailpassword.EmailPassword;
import io.supertokens.multitenancy.Multitenancy;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.output.Logging;
import io.supertokens.pluginInterface.RECIPE_ID;
Expand Down Expand Up @@ -80,7 +79,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
}

try {
io.supertokens.webserver.api.emailpassword.Utils.checkIfEmailPasswordIsEnabledForTenant(main, tenantIdentifier, getVersionFromRequest(req));
io.supertokens.webserver.api.emailpassword.Utils.assertIfEmailPasswordIsEnabledForTenant(main, tenantIdentifier, getVersionFromRequest(req));

AuthRecipeUserInfo user = EmailPassword.signUp(tenantIdentifier, storage, super.main, normalisedEmail,
password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import jakarta.servlet.ServletException;

public class Utils {
public static void checkIfEmailPasswordIsEnabledForTenant(Main main, TenantIdentifier tenantIdentifier,
SemVer version) throws ServletException {
public static void assertIfEmailPasswordIsEnabledForTenant(Main main, TenantIdentifier tenantIdentifier,
SemVer version) throws ServletException {
TenantConfig config = Multitenancy.getTenantInfo(main, tenantIdentifier);
if (!MultitenancyHelper.isEmailPasswordEnabled(config, version)) {
throw new ServletException(new BadPermissionException("Email password login not enabled for tenant"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.passwordless.PasswordlessDevice;
import io.supertokens.utils.SemVer;
import io.supertokens.webserver.InputParser;
import io.supertokens.webserver.WebserverAPI;
import jakarta.servlet.ServletException;
Expand Down Expand Up @@ -80,7 +79,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I

try {
TenantIdentifier tenantIdentifier = getTenantIdentifier(req);
io.supertokens.webserver.api.passwordless.Utils.checkIfPasswordlessIsEnabledForTenant(main,
io.supertokens.webserver.api.passwordless.Utils.assertIfPasswordlessIsEnabledForTenant(main,
tenantIdentifier, getVersionFromRequest(req));
Storage storage = this.getTenantStorage(req);
PasswordlessDevice consumedDevice = Passwordless.checkCodeAndReturnDevice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I

try {
TenantIdentifier tenantIdentifier = getTenantIdentifier(req);
io.supertokens.webserver.api.passwordless.Utils.checkIfPasswordlessIsEnabledForTenant(main,
io.supertokens.webserver.api.passwordless.Utils.assertIfPasswordlessIsEnabledForTenant(main,
tenantIdentifier, getVersionFromRequest(req));
Storage storage = this.getTenantStorage(req);
ConsumeCodeResponse consumeCodeResponse = Passwordless.consumeCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I

try {
TenantIdentifier tenantIdentifier = getTenantIdentifier(req);
io.supertokens.webserver.api.passwordless.Utils.checkIfPasswordlessIsEnabledForTenant(main,
io.supertokens.webserver.api.passwordless.Utils.assertIfPasswordlessIsEnabledForTenant(main,
tenantIdentifier, getVersionFromRequest(req));
CreateCodeResponse createCodeResponse = Passwordless.createCode(
tenantIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import jakarta.servlet.ServletException;

public class Utils {
public static void checkIfPasswordlessIsEnabledForTenant(Main main, TenantIdentifier tenantIdentifier,
public static void assertIfPasswordlessIsEnabledForTenant(Main main, TenantIdentifier tenantIdentifier,
SemVer version) throws ServletException {
TenantConfig config = Multitenancy.getTenantInfo(main, tenantIdentifier);
if (!MultitenancyHelper.isPasswordlessEnabled(config, version)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.supertokens.ActiveUsers;
import io.supertokens.Main;
import io.supertokens.emailpassword.exceptions.EmailChangeNotAllowedException;
import io.supertokens.multitenancy.Multitenancy;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.pluginInterface.RECIPE_ID;
import io.supertokens.pluginInterface.Storage;
Expand Down Expand Up @@ -142,7 +141,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I

try {
TenantIdentifier tenantIdentifier = getTenantIdentifier(req);
io.supertokens.webserver.api.thirdparty.Utils.checkIfThirdPartyIsEnabledForTenant(main,
io.supertokens.webserver.api.thirdparty.Utils.assertIfThirdPartyIsEnabledForTenant(main,
tenantIdentifier, getVersionFromRequest(req));
Storage storage = getTenantStorage(req);
ThirdParty.SignInUpResponse response = ThirdParty.signInUp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import jakarta.servlet.ServletException;

public class Utils {
public static void checkIfThirdPartyIsEnabledForTenant(Main main, TenantIdentifier tenantIdentifier,
SemVer version) throws ServletException {
public static void assertIfThirdPartyIsEnabledForTenant(Main main, TenantIdentifier tenantIdentifier,
SemVer version) throws ServletException {
TenantConfig config = Multitenancy.getTenantInfo(main, tenantIdentifier);
if (!MultitenancyHelper.isThirdPartyEnabled(config, version)) {
throw new ServletException(new BadPermissionException("ThirdParty login not enabled for tenant"));
Expand Down
53 changes: 53 additions & 0 deletions test-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Tenant create/update test cases

This folder contains test cases for the test: `io.supertokens.test.multitenant.api.TestTenantCreationBehaviour.
testCrossVersionCreateAndUpdateCases`.

The create / update tenant APIs have different inputs between CDI version 3.0-4.0, 5.0 and v2 API has been introduced
in 5.1. We created a playground to test how the input / output fares cross versions. Code for that is included in
this folder.

All the json files here constitute all possible test cases for the test mentioned above.
Each test case has the following structure:

```js
{
"tenantId": "public", // public or non public
"cv": "4", // CDI version used for tenant creation
"uv": "4", // CDI version used fo updating the tenant
"cbody": {
// ... body of the create operation
},
"ubody": {
// ... body of the update operation
},
"tenantState": { // state stored in the db
"tenantId": "public",
"emailPasswordEnabled": true,
"passwordlessEnabled": true,
"thirdPartyEnabled": true,
"firstFactors": null,
"requiredSecondaryFactors": null
},
"g4": { // expected output from GET tenant API for CDI version 4
"emailPasswordEnabled": true,
"thirdPartyEnabled": true,
"passwordlessEnabled": true
},
"g5": { // expected output from GET tenant API for CDI version 5
"emailPasswordEnabled": true,
"thirdPartyEnabled": true,
"passwordlessEnabled": true,
"firstFactors": null,
"requiredSecondaryFactors": null
},
"gv2": { // expected output from GET tenant API for CDI version 5.1
"firstFactors": null,
"requiredSecondaryFactors": null },
"invalidConfig": false // Indicates if create or update should result in an invalid config error
}
```

These test cases can be generated using the playground app in this folder.

Note that the test case files have been broken down into multiple files to be able to add to the git.
23 changes: 23 additions & 0 deletions test-data/playground/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions test-data/playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Loading

0 comments on commit 3a7beba

Please sign in to comment.