Dynamic Basic Auth from Seed Data

Document created by Dave Murphy Employee on Jul 19, 2017Last modified by Dave Murphy Employee on Jul 19, 2017
Version 3Show Document
  • View in full screen mode

The below script will scan the clip for any target which already contains Basic Auth information. For those clip targets which do contain Basic Auth, it will update the username and password to a value supplied to seed data. Targets which do not already contain Basic Auth will be skipped.

 

How to use this script:

1) Create a new script with the below code

2) Update lines 2 and 3 to reference your seed data properties containing username/password data

3) Place this script at the very beginning of your test clip

 

 

// Update the next two lines to point to the seed data prop with user data

var thisUsername = $prop.value("clip","SD_BasicAuthUserdata.Username"); var thisPassword = $prop.value("clip","SD_BasicAuthUserdata.Password");
// Get all targets from clip var clipTargets = $context.currentClip.targets;
function log(msg,array) {     if(!!array) {         $context.result.postMessage($context.result.LEVEL_INFO, msg, array);     } else {         $context.result.postMessage($context.result.LEVEL_INFO, msg);     } }  function updateBasicAuth(myTarget) {     // If we have basic auth already - update it.     if(!!myTarget.getPropertyValue("UserName")) {         log("Setting Username: " + thisUsername + " - Password: " + thisPassword);         myTarget.setPropertyValue("UserName",thisUsername);         myTarget.setPropertyValue("Password",thisPassword);     }     }  if(!!clipTargets) {      // If clip contains more than one target - Iterate through all, update only targets that already contain auth     if(Array.isArray(clipTargets)) {                  log("Found " + clipTargets.length + " targets.",clipTargets.join("\n"));                  for(var i = 0 ; i < clipTargets.length ; i++) {             var myTarget = clipTargets[i].systemPropertyList;             log("Updating Target: " + clipTargets[i].name);                          updateBasicAuth(myTarget);          }         }          // If we only have one target, then things get easy     else {          updateBasicAuth(clipTargets);     } }

Attachments

    Outcomes