SBX - Search With Button

SBX - Forum Post Title

SysTest framework supports role-based testing?

Dynamics 365 for Finance and Operations Forum

JJR93 asked a question on 4 Jul 2017 3:00 AM
My Badges

Question Status

Verified

Hi, 

There is documentation from Microsoft online which says the SysTest framework supports role-based testing. I have scoured the internet but can't seem to find anyone who has utilised this feature.

If anyone could point me in the right direction to any information, or let me know the feasibility of such tests then that would be much appreciated.

Regards,

Jack

Reply
JJR93 responded on 5 Jul 2017 4:37 AM
My Badges
Verified Answer

For anyone who runs in to a similar issue in the future, the one bit of documentation I found to be useful on the matter is located at blogs.msdn.microsoft.com/.../automated-testing-guidance-for-ax-7

The code provided on this article is useful but needs a bit of tweaking to get working. The useful bit is the SysTestSecurityAttribute section, let me know if you need any further info by commenting on this post or messaging me

Reply
jwaugh930 responded on 11 Oct 2017 12:00 PM

Hello,

I am very interested in this topic. I created a table and form with restricted access. I am attempting to run a test under specific security role contexts such that under the correct role context, the test would pass (allowed to edit the table), and under the incorrect role the test would fail. I've tried using SysTestSecurityAttribute and SysTestSecurityContext class but have not been able to get it working.

Any advice or further resources would be greatly appreciated.

Reply
JJR93 responded on 30 Oct 2017 10:56 AM
My Badges

Sorry for the delay in getting back to you. I had to give up access to the developer VM we were using for the proof of concept we were undertaking. The following code specifies two roles for the test to use:

#define.PersonaSecRole('u1')

[SysTestTargetAttribute(classStr(SysTestSecurityContext), UtilElementType::Class), SysTestSecurityAttribute(#PersonaSecRole, ['57df6343-4dd9-4dc0-8a6b-61e454b023e4',  'd6c1da0e-521b-4261-b1db-eb47c6c129f5', 'TestEssentialsRole'], true)]

If you define this at the class level you should be fine.

The roles are the hex numbers (custom roles appear like this in the AOT). I retrieved these roles by clicking Dynamics 365 -> Addins -> View related roles for all duties in Visual Studio.

Jack

Reply
Alex Meyer responded on 29 Jan 2019 5:58 PM
My Badges

JJR93,

I'm also trying to get something like this working, I have the following and I can't get it to fail regardless of the role I put into the SysTestSecurityAttribute:

[SysTestTargetAttribute(classStr(SysTestSecurityContext), UtilElementType::Class),SysTestSecurityAttribute('test', ['TMSLOGISTICSMANAGER'], true)]
class ProjTests extends SysTestCase
{
[SysTestMethodAttribute] public void TestRoleAccess() { SecurityContext context = SecurityContext::constructFromEntryPoint(SecurableType::MenuItemDisplay, menuItemDisplayStr(VendTableListPage), ''); context.push(); this.assertTrue(context.isTableOperationAllowed(tableNum(VendTable), StatementType::Delete)); SecurityContext::pop(); }
}

Edit:

The above works as long as you do a build between running the the test suite, if you don't the last build's data is still being used. I'm going to leave it as it is a working code example but I don't need help anymore. Thanks for the initial post!

Reply
JJR93 responded on 5 Jul 2017 4:37 AM
My Badges
Verified Answer

For anyone who runs in to a similar issue in the future, the one bit of documentation I found to be useful on the matter is located at blogs.msdn.microsoft.com/.../automated-testing-guidance-for-ax-7

The code provided on this article is useful but needs a bit of tweaking to get working. The useful bit is the SysTestSecurityAttribute section, let me know if you need any further info by commenting on this post or messaging me

Reply

SBX - Two Col Forum

SBX - Migrated JS