Move DomainController::NODE* to Address::NODE*, make role mandatory in the database, change logic so that mail generated by the host comes from a node address.

This commit is contained in:
Deon George
2022-01-24 22:56:13 +11:00
parent efa7195633
commit d660d5a6df
15 changed files with 143 additions and 110 deletions

View File

@@ -28,9 +28,9 @@ class PacketTest extends TestCase
Zone::unguard();
Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>21,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>3,'node_id'=>151,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
$hub = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
$ao = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>4,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>3,'node_id'=>151,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
$hub = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
$ao = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>4,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_nomsgid_origin.pkt');
@@ -63,7 +63,7 @@ class PacketTest extends TestCase
Zone::unguard();
Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>10,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_nomsgid_noorigin.pkt');
@@ -92,7 +92,7 @@ class PacketTest extends TestCase
Zone::unguard();
Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>10,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
$src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_msgid_origin.pkt');

View File

@@ -2,14 +2,11 @@
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;
use App\Models\{Address,Domain};
class RoutingTest extends TestCase
{
@@ -36,7 +33,7 @@ class RoutingTest extends TestCase
// 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->assertEquals($ao->role,Address::NODE_ZC);
$this->assertCount(0,$ao->children);
$this->assertNull($ao->parent());
@@ -47,15 +44,15 @@ class RoutingTest extends TestCase
// 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($ao->role,Address::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($ao->role,Address::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);
$this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertCount(9,$ao->children);
@@ -64,15 +61,15 @@ class RoutingTest extends TestCase
// 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($ao->role,Address::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($ao->role,Address::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);
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/2001.0@domain-a');
$this->assertNULL($ao->children);
@@ -81,7 +78,7 @@ class RoutingTest extends TestCase
// 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);
$this->assertEquals($ao->role,Address::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);
@@ -90,7 +87,7 @@ class RoutingTest extends TestCase
// 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);
$this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(27,$ao->children);
@@ -107,7 +104,7 @@ class RoutingTest extends TestCase
// 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->assertEquals($ao->role,Address::NODE_RC);
$this->assertCount(0,$ao->children);
// Add session info, and we have 51 children
@@ -117,7 +114,7 @@ class RoutingTest extends TestCase
// Pick a NC and we have 10 less children
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_NC);
$this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertCount(9,$ao->children);
@@ -126,7 +123,7 @@ class RoutingTest extends TestCase
// 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);
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertNULL($ao->children);
@@ -135,7 +132,7 @@ class RoutingTest extends TestCase
// 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);
$this->assertEquals($ao->role,Address::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);
@@ -154,7 +151,7 @@ class RoutingTest extends TestCase
// 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->assertEquals($ao->role,Address::NODE_NC);
$this->assertCount(0,$ao->children);
// Add session info, we have 10 children
@@ -164,14 +161,14 @@ class RoutingTest extends TestCase
// 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);
$this->assertEquals($ao->role,Address::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);
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertCount(5,$ao->children);
@@ -188,7 +185,7 @@ class RoutingTest extends TestCase
// 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->assertEquals($ao->role,Address::NODE_HC);
$this->assertCount(0,$ao->children);
// Add session info, we have 2 children
@@ -209,7 +206,7 @@ class RoutingTest extends TestCase
// Node with session details still doesnt have any children
$ao = Address::findFTN('100:20/2001@domain-a');
$this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
$this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/2001@domain-a');
$this->assertNULL($ao->children);