[mockbox] How do I mock a login for an integration test?

I am a beginner when it comes to integration tests am I am trying to figure out how to mock a login so I can test a handler that is behind my security service. Here’s the integration test:

`

component extends=“coldbox.system.testing.BaseTestCase” appMapping="/root"{

/**

  • You can remove this setup method if you do not have anything to setup
    */
    void function setup(){
    //Call the super setup method to setup the app.
    super.setup();

//create a mock user object
mockUser = getMockBox().createEmptyMock(“genesis.model.security.Player”).$(“hasData”, true).$(“getIsLoggedIn”, true);

// Mock the session facade, I am using the coldbox one, it can be any facade though
mockSession = getMockBox().createEmptyMock(className=‘coldbox.system.plugins.ClientStorage’);
mockSession.$(method=“setVar”,callLogging=true);

mockSession.setVar(“loggedInUser”, {
playerID = 2,
isLoggedIn = true,
// Initialize the active account to a player’s default
activeAccount = 2
});
}

function testindex(){
var event = “”;

//Place any variables on the form or URL scope to test the handler.
//URL.name = “luis”

// Execute Event
event = execute(event=“private:jurisdictions.index”, renderResults=true);

debug(event.getCollection());
debug(mockUser);

//Do your asserts below
$assert.isEqual( “Welcome to ColdBox!”, event.getValue( “welcomeMessage”, “”, true ) );
assert.equals( 1, event.getValue(“page”) );
}

function testeditor(){
var event = “”;

//Place any variables on the form or URL scope to test the handler.
//URL.name = “luis”

// Execute Event
event = execute(“private:jurisdictions.editor”);

//Do your asserts below
$assert.isEqual( 0, event.getValue( “jurisdictionID”, “” ) );
}

function testsave(){
var event = “”;

//Place any variables on the form or URL scope to test the handler.
//URL.name = “luis”

// Execute Event
event = execute(“private:jurisdictions.save”);

//Do your asserts below

}

function testremove(){
var event = “”;

//Place any variables on the form or URL scope to test the handler.
//URL.name = “luis”

// Execute Event
event = execute(“private:jurisdictions.remove”);

//Do your asserts below

}

}

`

As you can see from the code, I am attempting to mock an authenticated user using my Player object and I am also trying to mock the session variables created when a user logs in. Here’s my security interceptor and my user validator code:

`

{
class=“coldbox.system.interceptors.Security”,
name=“security@private”,
properties={
rulesSource = “model”,
rulesModel = “securityRuleService@genesis”,
rulesModelMethod = “getSecurityRules”,
validatorModel = “securityService@genesis”
}
}

`

`

/*

  • This is where is will be determined whether a user can access a desired page or not.
  • This function is a convention used by the ColdBox security interceptor. The name and
  • the arguments are pre-defined, but the implementation is customizable.
  • @rule A securityRule to check against the logged in user
  • @messagebox A reference to the MessageBox plugin so you can set messages to be displayed to the end user
  • @controller A reference to the ColdBox controller to call other plugins, persist keys, or anything you like
    */
    boolean function userValidator(required struct rule,any messagebox,any controller)
    {
    var user = getUser();
    if( clientStorage.exists(“loggedInUser”) )
    var activeAccount = clientStorage.getVar(“loggedInUser”).activeAccount;

// Verify that a user is logged in
if (user.getIsLoggedIn() AND user.hasData())
{
// Check the playerPermissions
if ( user.checkPlayerPermission(rule.permissionDescription, activeAccount) )
return true;

// Check the player’s team jurisdiction

}
messageBox.warn(“You do not have access to this page”);
return false;
}

`

The result of my test is that when I execute an event that is behind the security service, it redirects to the login page so I am not exactly sure how to mock the login so the security service allows the event to be executed in the test. So to reiterate my question in the subject, How do I mock a login for this integration test?

@Ortus - Any assistance on this roadblock would be greatly appreciated. Thanks in advance!