diff --git a/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php b/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php index 3df2825dfec1d..96f638b887ed8 100644 --- a/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php +++ b/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php @@ -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 @@ -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') @@ -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( 'Set exempt IP-addresses: ' . implode(', ', $this->maintenanceMode->getAddressInfo()) . diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php index 88038c2e817c1..a3f8de642fe74 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php @@ -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 */ @@ -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, + ], + ]; + } }