Simulating Mail User Activity with Groovy and JMeter

By Matt Harrington

With the development and performance testing of the new Responsive Delivery feature of PhishMe, it became apparent early on that there was a need to be able to generate valid Exchange subscription notifications for actual mail user actions.  During initial development, it was sufficient to develop and test with one or two actual exchange users by signing onto their respective test accounts and performing actions in their respective mailboxes.  However, as development of the feature progressed and the performance of the feature was more of a concern, there became a need for a method to generate tens of thousands, or even hundreds of thousands, of valid Exchange user event notifications without human intervention.  JMeter and Taurus were looked at as viable methods to create the number of notifications we wanted, but we could not simulate that number of valid subscriptions or valid notifications for those subscriptions.  With a bit more research, we discovered that we could run custom groovy code as a JMeter JSR223Sampler and have that groovy code perform the desired actions both at random and at high volume.

To do this for Exchange mail users, we coded up some groovy to randomly connect to a test user (1 of 45000 created in our in-house Exchange instance) and perform various mailbox actions.  You can do this with any of the various Microsoft Exchange APIs available like the Exchange Web Services API, JWebServices API, or even Microsoft’s Graph API

Now, by creating a JMeter jmx file to include a JSR223Sampler test (either by hand or via the JMeter UI), you can run that groovy code with JMeter by calling out your groovy filename and the scriptLanguage of “groovy”:

<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler" enabled="true">
<stringProp name="cacheKey">false</stringProp>
<stringProp name="filename">my_groovy_code.groovy</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="script"></stringProp>
<stringProp name="scriptLanguage">groovy</stringProp>
</JSR223Sampler>

Lastly, you could configure the test threads and run time and execute that test right from the JMeter UI, or you can configure a test run with a yaml file and run it using BlazeMeter Taurus via the command line.  To configure the Taurus yaml, create your execution section with your threading, iteration, and/or run time specifics and a scenario section that calls out the jmx file created above.  See http://gettaurus.org/docs/ConfigSyntax/ for more info on this.  Here is an example:

execution:
- executor: jmeter
concurrency: 1000
ramp-up: 10m
hold-for: 50m
scenario: MyScenario

scenarios:
MyScenario:
properties:
user.classpath: lib
script: my_jmx_file.jmx

Add a user.classpath property for any libraries that your groovy code may require in order to run.  In the case of Exchange, you want this classpath to be able to find the JWebServices jar.

 

All third-party trademarks referenced by Cofense whether in logo form, name form or product form, or otherwise, remain the property of their respective holders, and use of these trademarks in no way indicates any relationship between Cofense and the holders of the trademarks.