Description

The XMLFileMaskReceiver replaces the sensitive node within the source XML file with a synthetic value in a new XML file. It also uses a configuration file that defines the element within the template file to replicate and a set of tags used within the template file as placeholders where generated test data will be inserted during the replication process. 


In This Article


When Should This Receiver Be Used?

  • It should be used when sensitive node values in XML file(s) must be masked with synthetic test data. 


How Many Files Can Be Masked?

  • It can mask values in a single or multiple files within a specified directory.


How to Mask a Flat or Nested XML File

Note: Use cases are provided later in this article.

  1. Select a Project and Project Version.
  2. Create a Domain with Attributes (i.e., Values) to be masked.
  3. Make the id Attribute that is automatically created invisible.
  4. Change the Domain's loopCount (see next section for more information).
  5. Create a Configuration file and place it in the appropriate directory.
  6. (Optional) Modify assigned Generators. 
  7. Assign the XMLFileMaskReceiver to the Domain.
  8. Configure the Receiver's Parameters.
  9. Create a Scenario for the Domain and download it.
  10. Run the command at the command line to generate one or more masked XML files. 

Domain loopCount

  • Masking Single File - set to the maximum number of replacements within the file. 
    • Example - 4 elements will be masked in the file. The Domain loopCount should be '4'.

  • Masking Multiple Files - the number of replacements in one file must be multiplied by the number of files.
    • Example - 4 elements will be masked per file, and 5 files will be masked. The Domain loopCount should be '20' (e.g., 4 x 5 = 20).

  • Alternatively, a user can set the loopCount higher than the maximum number of replacements to ensure that all sensitive values are masked within the generated output file(s).


Receiver Parameters

The following parameters may be configured for the XMLFileMaskReceiver. Items with an asterisk* are required.  

  • sourcePath* - Defines the path where the source XML file exists. 
  • sourceSubDirectory - Defines an optional subdirectory under sourcePath where the XML source file is located. 
  • sourceFileName - Defines the name of the XML source file. 
  • destPath* - Defines the base path where the clean masked file will be stored.
  • destSubDirectory* - Defines the prefix name of sub-directories that are auto-created under the destPath and then appended with a number. Important: The original file will be overwritten if a value is not entered for this parameter. Example: 
    • data1
    • data2
    • data3

  • configPath* - Defines the path where the XML configuration file exists. This file contains the information that allows the Receiver to parse the template XML file and perform synthetic data replacement. 
  • configSubDir - Defines the sub-directory under the config path directory where the configuration files are stored. 
  • configName*- Defines the name of the XML config file. 



Receiver Attribute Property Keys

The Receiver defines one property key that can be modified on any of its associated Domain Attributes:

  • include - Defines whether the Domain Attribute will be used for masking. When 'true', the values will be masked for that Attribute.




XML Config File

The configuration file defines the path within the XML file containing the sensitive nodes (attribute or value) to be masked and what Domain Attribute will be used to mask the values. The information required in the configuration file will depend on whether you are masking node text, node attributes, or both within a file. 


Three pieces of information can be included in the configuration file: 

  • tag nodeIdentifier - Path to the sensitive data value within the XML file.
  • attribute key - Attribute name in the source file. This information is required when node attributes will be masked. 
  • attributeIdentifier - Domain Name and Attribute that will be used to generate synthetic data and mask sensitive data values. If this information does not match the Domain and Attribute names in GenRocket, then the sensitive node will not be masked. 

Node Text Only

<template>
      <tags>
            <tag nodeIdentifier='path in XML template file' attributeIdentifier="@DomainName.AttributeName@">
      </tags>
</template>


Node Attribute Only

<template>
  <tags>
     <tag nodeIdentifier='path in XML template file'>
      <attributes>
        <attribute key ='name of attribute' attributeIdentifier='@DomainName.AttributeName@'/>
      </attributes>
    </tag>
  </tags>
</template>


Sample Config File 1

In this example, role and experience Attributes will be masked in the Employee Node of the XML file.

<template>
  <tags>
  <tag nodeIdentifier='Company.Department.Employee'>
      <attributes>
        <attribute key ='role' attributeIdentifier='@Sample.role@'/>
     <attribute key ='experience' attributeIdentifier='@Sample.experience@'/>
      </attributes>
    </tag>
      </tags>
</template>


Sample Config File 2

In this example, both attributes and text values will be masked:

<template>
  <tags>
   <tag nodeIdentifier='Company.Department.Employee'>
      <attributes>
        <attribute key ='role' attributeIdentifier='@Sample.role@'/>
          <attribute key ='experience' attributeIdentifier='@Sample.experience@'/>
      </attributes>
    </tag>
   <tag nodeIdentifier='Company.Department.Employee.Name' attributeIdentifier='@Sample.name@'/>
   <tag nodeIdentifier='Company.Department.Employee.Dob' attributeIdentifier='@Sample.dob@'/>
  </tags>
</template>


Use Case 1 - Mask Node Text Value in a Simple XML Template File

A tester wants to mask sensitive node text values within an XML file with synthetically generated data. The XMLFileMaskReceiver can accomplish this. 

Prerequisites

  • The user has installed GenRocket Runtime.
  • The user has selected (or created) a Project/Project Version.


Source File
The XML file below provides a simple example where only the node text is masked. 


<shiporder orderid="100001">
  <shipto>
    <name>Acme Co</name>
    <address>123 Road Runner Dr</address>
    <city>Tuson</city>
    <country>USA</country>
  </shipto>
  <items>
    <item>
      <itemNumber>10000000</itemNumber>
      <productId>10010</productId>
      <note>Handle with care</note>
      <quantity>3</quantity>
      <price>10.95</price>
    </item>
    <item>
      <itemNumber>10000001</itemNumber>
      <productId>88005</productId>
      <note>Handle with care</note>
      <quantity>9</quantity>
      <price>31.50</price>
    </item>
    <item>
      <itemNumber>10000002</itemNumber>
      <productId>23422</productId>
      <note>Handle with care</note>
      <quantity>5</quantity>
      <price>57.35</price>
    </item>
  </items>
  <billTo>
    <name>Acme Co</name>
    <address>123 Road Runner Dr</address>
    <city>Tuson</city>
    <country>USA</country>
  </billTo>
</shiporder>


Note: One or more XML files containing sensitive data values must be present within the sourceSubDirectory parameter in the XMLFileMaskReceiver. 


Step 1 - Create a Domain with Attributes for Masking Values

A ShipOrder Domain has been created with these Attributes: id, shipToName, itemNumber, productId, and billToName.  The id Attribute is created automatically.



For this example, the following Generators are used: 

  • shipToName - SimplePatternGen
  • billToName - SimplePatternGen 
  • itemNumber - RandomStringGen (10 characters - numbers only)
  • productId - RandomStringGen (10 characters - letters and numbers)


Preview data for these Attributes (synthetic data used to mask sensitive values). 




Step 2 - Make the id Attribute Invisible

The id Attribute can be made invisible since it is not needed. To do so, uncheck the Visible box in the Attribute Dashboard.


Step 3 - Change the Domain loopCount

The Domain loopCount must be set to the maximum number of replacements within the file. For this example, the loopCount will be '4'.

This is because four values will be masked within the template file: shipToName, itemNumber, productId, and billToName. 



Step 4 - Create the Required Configuration File

This example uses the configuration shown below: 

<template>
  <tags>
    <tag nodeIdentifier='name' attributeIdentifier="@shipOrder.shipToName@">
    <tag nodeIdentifier='shiporder.items.item.itemNumber' attributeIdentifier="@shipOrder.itemNumber@">
    <tag nodeIdentifier='shiporder.items.item.productId' attributeIdentifier="@shipOrder.productId@">
    <tag nodeIdentifier='shiporder.billTo.name' attributeIdentifier="@shipOrder.billToName@">
  </tags>
</template>


Step 5 - Add the XMLFileMaskReceiver and Configure Parameters

Add the XMLFileMaskReceiver to the ShipOrder Domain. 



For this example, the following parameters have been modified within the XML FileMaskReceiver:

  • sourceFileName - The name of the single XML template file is 'shipOrderFile.xml'. 
  • destSubDirectory - The generated output file will be in a 'maskedData' subdirectory. Important: The original file will be overwritten if a value is not entered for this parameter.  
  • configSubDir - The configuration file will be stored in a 'config' subdirectory. 
  • configName - The configuration file is named 'config.xml.'


Step 6 - Create and Download a Scenario

Create a Scenario for the Domain and then use the Cloud icon to download it.


Step 7 - Run the genrocket -r Command to Generate Test Data

Open a Command Prompt or Terminal window and use the following command to generate the masked output file: 


genrocket -r <ScenarioName.grs>


Generic

Note: Make sure the directory path is correct before running the command. For example, if the Scenario is in your Downloads Folder, it should be there. 



Masked XML Output File

<shiporder orderid="100001">
  <shipto>
    <name>ShiptoName1</name>
    <address>123 Road Runner Dr</address>
    <city>Tuson</city>
    <country>USA</country>
  </shipto>
  <items>
    <item>
      <itemNumber>3097049687</itemNumber>
      <productId>AQDHAJXOH6</productId>
      <note>Handle with care</note>
      <quantity>3</quantity>
      <price>10.95</price>
    </item>
    <item>
      <itemNumber>2695288717</itemNumber>
      <productId>QT2OQTDEU2</productId>
      <note>Handle with care</note>
      <quantity>9</quantity>
      <price>31.50</price>
    </item>
    <item>
      <itemNumber>5649644285</itemNumber>
      <productId>GASSOJA4BE</productId>
      <note>Handle with care</note>
      <quantity>5</quantity>
      <price>57.35</price>
    </item>
  </items>
  <billTo>
    <name>BillToName1</name>
    <address>123 Road Runner Dr</address>
    <city>Tuson</city>
    <country>USA</country>
  </billTo>
</shiporder>


Use Case 2 - Mask Node Values in Multiple XML Template Files

Note: This use case has the same project setup shown in Use Case 1 above. It uses the same sample XML template file (copied 5 times), configuration file, Domain, Attributes, Scenario, etc. 


The Receiver parameters and loopCount will differ depending on the number of files and how many attributes/values are being masked.


In this use case, five files need to be masked. They have been placed in an 'XMLTemplates' subdirectory at the path defined for the resource.output.directory resource.  


Domain loopCount

The Domain loopCount will be '20' since 4 elements will be masked in each of the 5 files. Please note that if the loopCount is too low, not all masked output files will be generated.



XMLFileMaskReceiver Configuration

For this example, the following parameters have been modified within the XMLFileMaskReceiver:

  • sourceSubdirectory - XML template files are in a subdirectory titled "XMLTemplates." 
  • sourceFileName - Leave blank when multiple template files need to be masked. 
  • destSubDirectory - Generated output files will be within a "maskedData" subdirectory. Important: The original files will be overwritten if a value is not entered for this parameter. 
  • configSubDrectory - The configuration file will be stored in a "config" subdirectory. 
  • configName - The name of the configuration file has been entered.


Masked XML Output Files

The same values will be masked for each file as in Use Case 1; however, it will be done for five files. These files will be created within the maskedData directory (shown below). 



Use Case 3 - Mask Node Attributes Only in a Complex XML Template File

The tester wants to mask node attributes within their complex XML file in this example. They want to mask each occurrence of the role and experience node attribute with synthetic data. In the source file below, each attribute must be masked 4 times. 


Source File

<Company name="TechCorp" location="New York" established="2005">
    <Department name="Human Resources" head="Alice Brown">
        <Employee id="101" role="Manager" experience="10 years">
            <Name>John Doe</Name>
            <Salary currency="USD">60000</Salary>
        </Employee>
        <Employee id="102" role="Recruiter" experience="5 years">
            <Name>Jane Smith</Name>
            <Salary currency="USD">50000</Salary>
        </Employee>
    </Department>
    <Department name="IT" head="Robert Wilson">
        <Employee id="201" role="Software Engineer" experience="7 years">
            <Name>Mike Johnson</Name>
            <Salary currency="USD">75000</Salary>
        </Employee>
        <Employee id="202" role="System Administrator" experience="6 years">
            <Name>Emily Davis</Name>
            <Salary currency="USD">70000</Salary>
        </Employee>
    </Department>
</Company>


Config File

<template>
  <tags>
     <tag nodeIdentifier='Company.Department.Employee'>
      <attributes>
        <attribute key ='role' attributeIdentifier='@Sample.role@'/>
        <attribute key ='experience' attributeIdentifier='@Sample.experience@'/>
      </attributes>
    </tag>
  </tags>
</template>


Project Setup

For this example, a Sample Domain has been set up with two Attributes: role and experience. The setup is similar to what is shown in Use Case 1 above. 



The following data will be generated for these Attributes. Each Attribute has been assigned the SimplePatternGen for this example.


The ID attribute has been made invisible.


The Sample Domain loopCount has been set to '4', the XMLFileMaskReceiver has been assigned to the Domain, and a Quick Scenario has been created.


The XMLFileMaskReciever configuration is shown below: 



Masked File

Employee role = masked with role1, role2, role3, role4

Employee experience = masked with experience1, experience2, experience3, experience4


<Company established="2005" name="TechCorp" location="New York">
  <Department head="Alice Brown" name="Human Resources">
    <Employee role="role1" id="101" experience="experience1">
      <Name>John Doe</Name>
      <Salary currency="USD">60000</Salary>
    </Employee>
    <Employee role="role2" id="102" experience="experience2">
      <Name>Jane Smith</Name>
      <Salary currency="USD">50000</Salary>
    </Employee>
  </Department>
  <Department head="Robert Wilson" name="IT">
    <Employee role="role3" id="201" experience="experience3">
      <Name>Mike Johnson</Name>
      <Salary currency="USD">75000</Salary>
    </Employee>
    <Employee role="role4" id="202" experience="experience4">
      <Name>Emily Davis</Name>
      <Salary currency="USD">70000</Salary>
    </Employee>
  </Department>
</Company>


Use Case 4 - Mask Node Attributes and Text Values in an XML Template File

This use case is similar to Use Case 3. The source file has been slightly modified to include a Dob node for each employee. The following node attributes and values will be masked:

  • Employee role (Attribute)
  • Employee experience (Attribute)
  • Employee Name
  • Employee Dob 


Source File

<Company name="TechCorp" location="New York" established="2005">
    <Department name="Human Resources" head="Alice Brown">
        <Employee id="101" role="Manager" experience="10 years">
            <Name>John Doe</Name>
            <Dob>02-08-1992</Dob>
            <Salary currency="USD">60000</Salary>
        </Employee>
        <Employee id="102" role="Recruiter" experience="5 years">
            <Name>Jane Smith</Name>
            <Dob>09-22-2002</Dob>
            <Salary currency="USD">50000</Salary>
        </Employee>
    </Department>
    <Department name="IT" head="Robert Wilson">
        <Employee id="201" role="Software Engineer" experience="7 years">
            <Name>Mike Johnson</Name>
            <Dob>12-08-1981</Dob>
            <Salary currency="USD">75000</Salary>
        </Employee>
        <Employee id="202" role="System Administrator" experience="6 years">
            <Name>Emily Davis</Name>
            <Dob>05-15-2008</Dob>
            <Salary currency="USD">70000</Salary>
        </Employee>
    </Department>
</Company>


Config File

<template>
  <tags>
   <tag nodeIdentifier='Company.Department.Employee'>
      <attributes>
        <attribute key ='role' attributeIdentifier='@Sample.role@'/>
          <attribute key ='experience' attributeIdentifier='@Sample.experience@'/>
      </attributes>
    </tag>
   <tag nodeIdentifier='Company.Department.Employee.Name' attributeIdentifier='@Sample.name@'/>
   <tag nodeIdentifier='Company.Department.Employee.Dob' attributeIdentifier='@Sample.dob@'/>
  </tags>
</template>


Project Setup

As with previous examples, a Sample Domain has been created with the required Attributes, the XMLFileMaskReceiver, and a Quick Scenario. The id Attribute has been made invisible.

The following Attributes have been created for the Domain:


The following values will be used to mask the sensitive nodes: 



Domain loopCount

The Domain loopCount has been set to '4'.



XMLFileMaskReceiver Configuration

The configuration is the same as in Use Case 3 (see image below) 



Masked File

Employee role = masked with role1, role2, role3, role4

Employee experience = masked with experience1, experience2, experience3, experience4

Employee Name = name1, name2, name3, name4

Employee Dob = 05-01-2001, 05-01-2002, 03-01-2003, 09-01-2004

<Company established="2005" name="TechCorp" location="New York">
  <Department head="Alice Brown" name="Human Resources">
    <Employee role="role1" id="101" experience="experience1">
      <Name>name1</Name>
      <Dob>05-01-2001</Dob>
      <Salary currency="USD">60000</Salary>
    </Employee>
    <Employee role="role2" id="102" experience="experience2">
      <Name>name2</Name>
      <Dob>05-01-2002</Dob>
      <Salary currency="USD">50000</Salary>
    </Employee>
  </Department>
  <Department head="Robert Wilson" name="IT">
    <Employee role="role3" id="201" experience="experience3">
      <Name>name3</Name>
      <Dob>03-01-2003</Dob>
      <Salary currency="USD">75000</Salary>
    </Employee>
    <Employee role="role4" id="202" experience="experience4">
      <Name>name4</Name>
      <Dob>09-01-2004</Dob>
      <Salary currency="USD">70000</Salary>
    </Employee>
  </Department>
</Company>