logo

NJP

How to test Encryption Context with ServiceNow Automated Test Framework

Import · Mar 05, 2020 · article

One of the common test steps that is not supported via ATF’s is Encryption context.

Encryption context allows only users who are set to specific ‘encryption context’ to be able to view confidential data, for other users this data is encrypted at the database level and they have no access to it. This means that granting a role to a user is not enough, he has to manually click the encryption context picker and select the context that will allow him to see that sensitive data.

If your test relies on this, you will not see the data and your ATF will fail all further steps.

Changing encryption context can be done programmatically via REST API calls, however it can only be done via client side while ATF test runner is present on screen.

To achieve this:

1) Let’s create a service portal page named ‘encryption_testing’.

2) Create a widget that will do the REST API call and authenticate the user with document.cookie global object. You can choose to pass sys_id of encryption context via $sp.getParameter(‘sys_id’) server side or hardcode it in the client script. Use this for your client script:

data.sys_id = ‘sys_id_of_encryption_context’; // Get this from sys_encryption_context table

$http({
    method: 'PUT',
    url: '/api/now/ui/concoursepicker/encryption',
    headers: {
        'Content-Type': 'application/json',
        'Cookie' : document.cookie
    },
        data: { id: data.sys_id }
})

3) Create a module called “Encryption ATF Testing” which would lead to our portal page (can be sp or any other portal). If you used parameters value to indicate sys_id of the encryption context, you can add it as well to the module URL.

4) When creating your ATF test, use open a module ATF OOTB test step and choose “Ecryption ATF Testing” module.

View original source

https://servicenowthink.wordpress.com/2020/03/05/how-to-test-encryption-context-with-servicenow-automated-test-framework/