Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Stories/GreylistTest.php
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | public function testWhitelistStale() | ||||
$whitelist->updated_at = \Carbon\Carbon::now()->subMonthsWithoutOverflow(2); | $whitelist->updated_at = \Carbon\Carbon::now()->subMonthsWithoutOverflow(2); | ||||
$whitelist->save(['timestamps' => false]); | $whitelist->save(['timestamps' => false]); | ||||
$this->assertTrue($request->shouldDefer()); | $this->assertTrue($request->shouldDefer()); | ||||
} | } | ||||
// public function testWhitelistUpdate() {} | // public function testWhitelistUpdate() {} | ||||
public function testNew() | |||||
{ | |||||
$data = [ | |||||
'sender' => 'someone@sender.domain', | |||||
'recipient' => $this->domainOwner->email, | |||||
'client_address' => $this->clientAddress, | |||||
'client_name' => 'some.mx' | |||||
]; | |||||
$response = $this->post('/api/webhooks/policy/greylist', $data); | |||||
$response->assertStatus(403); | |||||
} | |||||
public function testRetry() | public function testRetry() | ||||
{ | { | ||||
$connect = Greylist\Connect::create( | $connect = Greylist\Connect::create( | ||||
[ | [ | ||||
'sender_local' => 'someone', | 'sender_local' => 'someone', | ||||
'sender_domain' => 'sender.domain', | 'sender_domain' => 'sender.domain', | ||||
'recipient_hash' => hash('sha256', $this->domainOwner->email), | 'recipient_hash' => hash('sha256', $this->domainOwner->email), | ||||
'recipient_id' => $this->domainOwner->id, | 'recipient_id' => $this->domainOwner->id, | ||||
Show All 13 Lines | public function testRetry() | ||||
'recipient' => $this->domainOwner->email, | 'recipient' => $this->domainOwner->email, | ||||
'client_address' => $this->clientAddress | 'client_address' => $this->clientAddress | ||||
] | ] | ||||
); | ); | ||||
$this->assertFalse($request->shouldDefer()); | $this->assertFalse($request->shouldDefer()); | ||||
} | } | ||||
public function testInvalidDomain() | public function testInvalidRecipient() | ||||
{ | { | ||||
$connect = Greylist\Connect::create( | $connect = Greylist\Connect::create( | ||||
[ | [ | ||||
'sender_local' => 'someone', | 'sender_local' => 'someone', | ||||
'sender_domain' => 'sender.domain', | 'sender_domain' => 'sender.domain', | ||||
'recipient_hash' => hash('sha256', $this->domainOwner->email), | 'recipient_hash' => hash('sha256', $this->domainOwner->email), | ||||
'recipient_id' => 1234, | 'recipient_id' => 1234, | ||||
'recipient_type' => \App\Domain::class, | 'recipient_type' => \App\Domain::class, | ||||
Show All 9 Lines | public function testInvalidRecipient() | ||||
'recipient' => 'not.someone@that.exists', | 'recipient' => 'not.someone@that.exists', | ||||
'client_address' => $this->clientAddress | 'client_address' => $this->clientAddress | ||||
] | ] | ||||
); | ); | ||||
$this->assertTrue($request->shouldDefer()); | $this->assertTrue($request->shouldDefer()); | ||||
} | } | ||||
public function testInvalidUser() | |||||
{ | |||||
$connect = Greylist\Connect::create( | |||||
[ | |||||
'sender_local' => 'someone', | |||||
'sender_domain' => 'sender.domain', | |||||
'recipient_hash' => hash('sha256', $this->domainOwner->email), | |||||
'recipient_id' => 1234, | |||||
'recipient_type' => \App\User::class, | |||||
'connect_count' => 1, | |||||
'net_id' => $this->net->id, | |||||
'net_type' => \App\IP4Net::class | |||||
] | |||||
); | |||||
$request = new Greylist\Request( | |||||
[ | |||||
'sender' => 'someone@sender.domain', | |||||
'recipient' => 'not.someone@that.exists', | |||||
'client_address' => $this->clientAddress | |||||
] | |||||
); | |||||
$this->assertTrue($request->shouldDefer()); | |||||
} | |||||
public function testUserDisabled() | public function testUserDisabled() | ||||
{ | { | ||||
$connect = Greylist\Connect::create( | $connect = Greylist\Connect::create( | ||||
[ | [ | ||||
'sender_local' => 'someone', | 'sender_local' => 'someone', | ||||
'sender_domain' => 'sender.domain', | 'sender_domain' => 'sender.domain', | ||||
'recipient_hash' => hash('sha256', $this->domainOwner->email), | 'recipient_hash' => hash('sha256', $this->domainOwner->email), | ||||
'recipient_id' => $this->domainOwner->id, | 'recipient_id' => $this->domainOwner->id, | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | public function testMultipleUsersAnyEnabled() | ||||
if ($user->id == $this->jack->id) { | if ($user->id == $this->jack->id) { | ||||
$this->assertTrue($request->shouldDefer()); | $this->assertTrue($request->shouldDefer()); | ||||
} else { | } else { | ||||
$this->assertFalse($request->shouldDefer()); | $this->assertFalse($request->shouldDefer()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function testControllerNew() | |||||
{ | |||||
$data = [ | |||||
'sender' => 'someone@sender.domain', | |||||
'recipient' => $this->domainOwner->email, | |||||
'client_address' => $this->clientAddress, | |||||
'client_name' => 'some.mx' | |||||
]; | |||||
$response = $this->post('/api/webhooks/policy/greylist', $data); | |||||
$response->assertStatus(403); | |||||
} | |||||
public function testControllerNotNew() | |||||
{ | |||||
$connect = Greylist\Connect::create( | |||||
[ | |||||
'sender_local' => 'someone', | |||||
'sender_domain' => 'sender.domain', | |||||
'recipient_hash' => hash('sha256', $this->domainOwner->email), | |||||
'recipient_id' => $this->domainOwner->id, | |||||
'recipient_type' => \App\User::class, | |||||
'connect_count' => 1, | |||||
'net_id' => $this->net->id, | |||||
'net_type' => \App\IP4Net::class | |||||
] | |||||
); | |||||
$connect->created_at = \Carbon\Carbon::now()->subMinutes(6); | |||||
$connect->save(); | |||||
$data = [ | |||||
'sender' => 'someone@sender.domain', | |||||
'recipient' => $this->domainOwner->email, | |||||
'client_address' => $this->clientAddress, | |||||
'client_name' => 'some.mx' | |||||
]; | |||||
$response = $this->post('/api/webhooks/policy/greylist', $data); | |||||
$response->assertStatus(200); | |||||
} | |||||
} | } |