sforkowany z mirror/friendica
Add update possibility to BlockedServers
rodzic
7ce76d153a
commit
f05f02409e
|
@ -90,24 +90,37 @@ HELP;
|
||||||
}
|
}
|
||||||
|
|
||||||
$domain = $this->getArgument(1);
|
$domain = $this->getArgument(1);
|
||||||
|
|
||||||
$blocklist = $config->get('system', 'blocklist');
|
|
||||||
foreach ($blocklist as $blocked) {
|
|
||||||
if ($blocked['domain'] === $domain) {
|
|
||||||
$this->out(sprintf("The domain '%s' is already blocked. (Reason: '%s')", $domain, $blocked['reason']));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$reason = (count($this->args) === 3) ? $this->getArgument(2) : self::DEFAULT_REASON;
|
$reason = (count($this->args) === 3) ? $this->getArgument(2) : self::DEFAULT_REASON;
|
||||||
|
|
||||||
$blocklist[] = [
|
$update = false;
|
||||||
|
|
||||||
|
$currBlocklist = $config->get('system', 'blocklist');
|
||||||
|
$newBlockList = [];
|
||||||
|
foreach ($currBlocklist as $blocked) {
|
||||||
|
if ($blocked['domain'] === $domain) {
|
||||||
|
$update = true;
|
||||||
|
$newBlockList[] = [
|
||||||
'domain' => $domain,
|
'domain' => $domain,
|
||||||
'reason' => $reason,
|
'reason' => $reason,
|
||||||
];
|
];
|
||||||
|
} else {
|
||||||
|
$newBlockList[] = $blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($config->set('system', 'blocklist', $blocklist)) {
|
if (!$update) {
|
||||||
|
$newBlockList[] = [
|
||||||
|
'domain' => $domain,
|
||||||
|
'reason' => $reason,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($config->set('system', 'blocklist', $newBlockList)) {
|
||||||
|
if ($update) {
|
||||||
|
$this->out(sprintf("The domain '%s' is now updated. (Reason: '%s')", $domain, $reason));
|
||||||
|
} else {
|
||||||
$this->out(sprintf("The domain '%s' is now blocked. (Reason: '%s')", $domain, $reason));
|
$this->out(sprintf("The domain '%s' is now blocked. (Reason: '%s')", $domain, $reason));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
$this->out(sprintf("Couldn't save '%s' as blocked server", $domain));
|
$this->out(sprintf("Couldn't save '%s' as blocked server", $domain));
|
||||||
|
@ -143,7 +156,7 @@ HELP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
$this->out(sprintf("Domain '%s' is not blocked.", $domain));
|
$this->out(sprintf("The domain '%s' is not blocked.", $domain));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,43 @@ CONS;
|
||||||
$this->assertEquals('The domain \'testme.now\' is now blocked. (Reason: \'' . BlockedServers::DEFAULT_REASON . '\')' . PHP_EOL, $txt);
|
$this->assertEquals('The domain \'testme.now\' is now blocked. (Reason: \'' . BlockedServers::DEFAULT_REASON . '\')' . PHP_EOL, $txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test blockedservers add command on existed domain
|
||||||
|
*/
|
||||||
|
public function testUpdateBlockedServer()
|
||||||
|
{
|
||||||
|
$this->configMock
|
||||||
|
->shouldReceive('get')
|
||||||
|
->with('system', 'blocklist')
|
||||||
|
->andReturn($this->defaultBlockList)
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$newBlockList = [
|
||||||
|
[
|
||||||
|
'domain' => 'social.nobodyhasthe.biz',
|
||||||
|
'reason' => 'Illegal content',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'domain' => 'pod.ordoevangelistarum.com',
|
||||||
|
'reason' => 'Other reason',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->configMock
|
||||||
|
->shouldReceive('set')
|
||||||
|
->with('system', 'blocklist', $newBlockList)
|
||||||
|
->andReturn(true)
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$console = new BlockedServers($this->consoleArgv);
|
||||||
|
$console->setArgument(0, 'add');
|
||||||
|
$console->setArgument(1, 'pod.ordoevangelistarum.com');
|
||||||
|
$console->setArgument(2, 'Other reason');
|
||||||
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
|
$this->assertEquals('The domain \'pod.ordoevangelistarum.com\' is now updated. (Reason: \'Other reason\')' . PHP_EOL, $txt);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test blockedservers remove command
|
* Test blockedservers remove command
|
||||||
*/
|
*/
|
||||||
|
@ -163,6 +200,25 @@ CONS;
|
||||||
$this->assertStringStartsWith('[Warning] Unknown command', $txt);
|
$this->assertStringStartsWith('[Warning] Unknown command', $txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test blockedservers remove with not existing domain
|
||||||
|
*/
|
||||||
|
public function testRemoveBlockedServerNotExist()
|
||||||
|
{
|
||||||
|
$this->configMock
|
||||||
|
->shouldReceive('get')
|
||||||
|
->with('system', 'blocklist')
|
||||||
|
->andReturn($this->defaultBlockList)
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$console = new BlockedServers($this->consoleArgv);
|
||||||
|
$console->setArgument(0, 'remove');
|
||||||
|
$console->setArgument(1, 'not.exiting');
|
||||||
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
|
$this->assertEquals('The domain \'not.exiting\' is not blocked.' . PHP_EOL, $txt);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test blockedservers add command without argument
|
* Test blockedservers add command without argument
|
||||||
*/
|
*/
|
||||||
|
|
Ładowanie…
Reference in New Issue