Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MaintenanceAllowIpsCommand extends AbstractSetupCommand
*/
const INPUT_KEY_IP = 'ip';
const INPUT_KEY_NONE = 'none';
const INPUT_KEY_ADD = 'add';

/**
* @var MaintenanceMode
Expand Down Expand Up @@ -69,6 +70,12 @@ protected function configure()
InputOption::VALUE_NONE,
'Clear allowed IP addresses'
),
new InputOption(
self::INPUT_KEY_ADD,
null,
InputOption::VALUE_NONE,
'Add the IP address to existing list'
),
];
$this->setName('maintenance:allow-ips')
->setDescription('Sets maintenance mode exempt IPs')
Expand All @@ -91,6 +98,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (!empty($addresses)) {
if ($input->getOption(self::INPUT_KEY_ADD)) {
$addresses = array_unique(array_merge($this->maintenanceMode->getAddressInfo(), $addresses));
}
$this->maintenanceMode->setAddresses(implode(',', $addresses));
$output->writeln(
'<info>Set exempt IP-addresses: ' . implode(' ', $this->maintenanceMode->getAddressInfo()) .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ public function testExecute(array $input, array $validatorMessages, $expectedMes
$this->assertEquals($expectedMessage, $tester->getDisplay());
}

/**
* @param array $addressInfo
* @param array $input
* @param array $validatorMessages
* @param string $expectedMessage
* @dataProvider executeWithAddDataProvider
*/
public function testExecuteWithAdd(array $addressInfo, array $input, array $validatorMessages, $expectedMessage)
{
$newAddressInfo = array_unique(array_merge($addressInfo, $input['ip']));

$this->ipValidator->expects($this->once())->method('validateIps')->willReturn($validatorMessages);
$this->maintenanceMode
->expects($this->once())
->method('setAddresses')
->with(implode(',', $newAddressInfo));

$this->maintenanceMode
->expects($this->exactly(2))
->method('getAddressInfo')
->willReturnOnConsecutiveCalls($addressInfo, $newAddressInfo);

$tester = new CommandTester($this->command);
$tester->execute($input);
$this->assertEquals($expectedMessage, $tester->getDisplay());
}

/**
* return array
*/
Expand Down Expand Up @@ -99,4 +126,31 @@ public function executeDataProvider()
]
];
}

/**
* return array
*/
public function executeWithAddDataProvider()
{
return [
[
[],
['ip' => ['127.0.0.1'], '--add' => true],
[],
'Set exempt IP-addresses: 127.0.0.1' . PHP_EOL,
],
[
['127.0.0.1'],
['ip' => ['127.0.0.1'], '--add' => true],
[],
'Set exempt IP-addresses: 127.0.0.1' . PHP_EOL,
],
[
['127.0.0.1'],
['ip' => ['127.0.0.2'], '--add' => true],
[],
'Set exempt IP-addresses: 127.0.0.1 127.0.0.2' . PHP_EOL,
],
];
}
}