Mail routing parent/children, domain name validation, nodelist import changes and other fixes

This commit is contained in:
Deon George
2021-07-26 21:21:58 +10:00
parent 49bc946024
commit b179b1b3e9
15 changed files with 537 additions and 171 deletions

View File

@@ -2,16 +2,22 @@
namespace Tests\Feature;
use App\Http\Controllers\DomainController;
use App\Models\Address;
use Database\Seeders\NodeHierarchy;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use App\Models\Domain;
class RoutingTest extends TestCase
{
use DatabaseTransactions;
private function zone(): Collection
{
$do = Domain::where('name','Domain A')->singleOrFail();
$do = Domain::where('name','domain-a')->singleOrFail();
$zo = $do->zones->where('zone_id',100)->pop();
return $zo->addresses;
}
@@ -23,36 +29,118 @@ class RoutingTest extends TestCase
*/
public function test_zc()
{
$this->seed(NodeHierarchy::class);
$nodes = $this->zone();
$this->assertEquals(51,$nodes->count());
$this->assertEquals(52,$nodes->count());
/*
* ZCs addresses are not in the address table, so we cannot workout children
$zc = $nodes->where('role',DomainController::NODE_ZC);
$this->assertEquals(1,$zc->count());
$zc = $zc->pop();
// Pick ZC without any session info - we have 0 children
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ZC);
$this->assertCount(0,$ao->children);
$this->assertNull($ao->parent());
// ZC has 2 Region and 3 nodes as children
$this->assertEquals(5,$zc->children());
*/
// Add session info, and we have 51 children
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(51,$ao->children);
// A node's parent should be the ZC
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
$ao = Address::findFTN('100:21/2001.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
// Pick a NC and we have 10 less children
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertCount(9,$ao->children);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(41,$ao->children);
// A node's parent should be the ZC
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
$ao = Address::findFTN('100:10/2001.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
$this->assertEquals('100:10/0.0@domain-a',$ao->parent()->ftn);
// Pick a Node and we have 1 less child
$ao = Address::findFTN('100:21/2001.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/2001.0@domain-a');
$this->assertNULL($ao->children);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(40,$ao->children);
// Define address on a HC and we have 3 less children
$ao = Address::findFTN('100:21/1000.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/1000.0@domain-a');
$this->assertCount(2,$ao->children);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(37,$ao->children);
// Define address on a NC and we have 10 less children
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(27,$ao->children);
}
/**
* Test the RC address.
* Test the ZC address.
*
* @return void
*/
public function test_rc()
{
$nodes = $this->zone();
$rc = $nodes->where('role','Region');
$this->assertEquals(2,$rc->count());
$this->seed(NodeHierarchy::class);
// First RC
$rc = $rc->pop();
// Pick ZC without any session info - we have 0 children
$ao = Address::findFTN('100:1/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_RC);
$this->assertCount(0,$ao->children);
// RC has 3 nodes and 2 hosts as children
$this->assertEquals(5,$rc->children->count());
// Add session info, and we have 51 children
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:1/0@domain-a');
$this->assertCount(23,$ao->children);
// Pick a NC and we have 10 less children
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertCount(9,$ao->children);
$ao = Address::findFTN('100:1/0@domain-a');
$this->assertCount(13,$ao->children);
// Pick a Node and we have 1 less child
$ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertNULL($ao->children);
$ao = Address::findFTN('100:1/0@domain-a');
$this->assertCount(12,$ao->children);
// Define address on a HC and we have 3 less children
$ao = Address::findFTN('100:11/1000.0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:11/1000.0@domain-a');
$this->assertCount(2,$ao->children);
$ao = Address::findFTN('100:1/0@domain-a');
$this->assertCount(9,$ao->children);
}
/**
@@ -62,15 +150,31 @@ class RoutingTest extends TestCase
*/
public function test_nc()
{
$nodes = $this->zone();
$nc = $nodes->where('role','Host');
$this->assertEquals(4,$nc->count());
$this->seed(NodeHierarchy::class);
// First NC
$nc = $nc->pop();
// Pick a HC without any session info - we have 0 children
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC);
$this->assertCount(0,$ao->children);
// NC has 3 nodes and 2 hubs as children
$this->assertEquals(5,$nc->children->count());
// Add session info, we have 10 children
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertCount(9,$ao->children);
// Add session info to a hub, we have 3 less children
$ao = Address::findFTN('100:20/2000@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertCount(6,$ao->children);
// Add session info to a node, we have 1 less child
$ao = Address::findFTN('100:20/1@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertCount(5,$ao->children);
}
/**
@@ -80,15 +184,34 @@ class RoutingTest extends TestCase
*/
public function test_hc()
{
$nodes = $this->zone();
$hc = $nodes->where('role','Hub');
//dd($hc->pluck('ftn'));
$this->assertEquals(8,$hc->count());
$this->seed(NodeHierarchy::class);
// First HC
$hc = $hc->pop();
// Pick a HC without any session info - we have 0 children
$ao = Address::findFTN('100:20/2000@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_HC);
$this->assertCount(0,$ao->children);
// HC has 2 children
$this->assertEquals(2,$hc->children->count());
// Add session info, we have 2 children
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/2000@domain-a');
$this->assertCount(2,$ao->children);
// Add session info to 1 child, we have 1 children
$ao = Address::findFTN('100:20/2001@domain-a');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/2000@domain-a');
$this->assertCount(1,$ao->children);
}
public function test_node()
{
$this->seed(NodeHierarchy::class);
// Node with session details still doesnt have any children
$ao = Address::findFTN('100:20/2001@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/2001@domain-a');
$this->assertNULL($ao->children);
}
}