Test the application with different user roles
C3 AI Platform makes it easy to develop complex workflows, including workflows where only users with a certain role can see specific UI pages, or specific information on a page.
This is accomplished by applying role-based access control to routes, and using conditional rendering components, to selectively hide or show specific components on a page.
When implementing this in your application, there are two steps to manually validate and preview your changes:
- Create users with the specific roles you want to test
- Configure your browser
- Test the workflow
Create users with the specific roles you want to test
Use TestIdp to create test users. This allows you to create multiple test users, each with different roles. In Static Console, run:
// Create new test user
let username = 'jane@test.com'
let user = TestIdp.createUser(username, 'Jane', 'Doe', username);
// Add test user to group
TestIdp.addUserToGroup(user, /* Group to add the user to*/);Now you have created a user which you can log in as.
Configure your browser
By default, when you are developing the front-end of the application by bundling your UI in VS Code, your browser will be authenticated even without a c3auth token cookie as long as VS Code is authenticated.
To test as a different user, do the following:
- From VS Code, start UI bundler, and navigate to the url presented when the bundling process has finished.
- In your browser, type in the URL
http://localhost:{port}/{env}/{app}/testidp/assumeUser/{userId}. In the example above, theuserIdwill bejane@test.com. There should be a message indicating you have successfully logged in as the desired user. - Navigate back to your app url. You are now authenticated as the test user, so you can now validate your application.
Clean up the configuration
Once you set the cookie, you are fully responsible to manage the token lifecycle. If the token expires, your browser will no longer render the application UI, and you need to generate new tokens.
Once you are finished testing, make sure you log out your test user. In your browser, type in the URL http://localhost:{port}/{env}/{app}/testidp/unassumeUser. Once you do this, your browser automatically starts using the token provided by VS Code. At this point C3 AI Platform automatically manages the token for you, and the UI will render based on your role and permissions (instead of a test user).
Troubleshooting
Your browser will always use the c3auth cookie as the authentication mechanism for all UI and API requests. If no cookie is set, VS Code will handle it for you.
If your UI is displaying a blank page or having some other issues where the UI is not being rendered, delete the c3auth cookie from your browser to reset the browser to its default behavior.
Whenever using this capability, make sure you delete the authentication cookie from the browser at the end of your testing session.