Skip to content

Commit 2dee331

Browse files
MAGETWO-88281: [Forwardport] Add option to add IP address to existing list + add test #13783
- Merge Pull Request #13783 from serhii-balko/magento2:2.3-develop-PR-port-13586 - Merged commits: 1. aec1858
2 parents a083717 + aec1858 commit 2dee331

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class MaintenanceAllowIpsCommand extends AbstractSetupCommand
2424
*/
2525
const INPUT_KEY_IP = 'ip';
2626
const INPUT_KEY_NONE = 'none';
27+
const INPUT_KEY_ADD = 'add';
2728

2829
/**
2930
* @var MaintenanceMode
@@ -69,6 +70,12 @@ protected function configure()
6970
InputOption::VALUE_NONE,
7071
'Clear allowed IP addresses'
7172
),
73+
new InputOption(
74+
self::INPUT_KEY_ADD,
75+
null,
76+
InputOption::VALUE_NONE,
77+
'Add the IP address to existing list'
78+
),
7279
];
7380
$this->setName('maintenance:allow-ips')
7481
->setDescription('Sets maintenance mode exempt IPs')
@@ -91,6 +98,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
9198
}
9299

93100
if (!empty($addresses)) {
101+
if ($input->getOption(self::INPUT_KEY_ADD)) {
102+
$addresses = array_unique(array_merge($this->maintenanceMode->getAddressInfo(), $addresses));
103+
}
94104
$this->maintenanceMode->setAddresses(implode(',', $addresses));
95105
$output->writeln(
96106
'<info>Set exempt IP-addresses: ' . implode(' ', $this->maintenanceMode->getAddressInfo()) .

setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@ public function testExecute(array $input, array $validatorMessages, $expectedMes
6666
$this->assertEquals($expectedMessage, $tester->getDisplay());
6767
}
6868

69+
/**
70+
* @param array $addressInfo
71+
* @param array $input
72+
* @param array $validatorMessages
73+
* @param string $expectedMessage
74+
* @dataProvider executeWithAddDataProvider
75+
*/
76+
public function testExecuteWithAdd(array $addressInfo, array $input, array $validatorMessages, $expectedMessage)
77+
{
78+
$newAddressInfo = array_unique(array_merge($addressInfo, $input['ip']));
79+
80+
$this->ipValidator->expects($this->once())->method('validateIps')->willReturn($validatorMessages);
81+
$this->maintenanceMode
82+
->expects($this->once())
83+
->method('setAddresses')
84+
->with(implode(',', $newAddressInfo));
85+
86+
$this->maintenanceMode
87+
->expects($this->exactly(2))
88+
->method('getAddressInfo')
89+
->willReturnOnConsecutiveCalls($addressInfo, $newAddressInfo);
90+
91+
$tester = new CommandTester($this->command);
92+
$tester->execute($input);
93+
$this->assertEquals($expectedMessage, $tester->getDisplay());
94+
}
95+
6996
/**
7097
* return array
7198
*/
@@ -99,4 +126,31 @@ public function executeDataProvider()
99126
]
100127
];
101128
}
129+
130+
/**
131+
* return array
132+
*/
133+
public function executeWithAddDataProvider()
134+
{
135+
return [
136+
[
137+
[],
138+
['ip' => ['127.0.0.1'], '--add' => true],
139+
[],
140+
'Set exempt IP-addresses: 127.0.0.1' . PHP_EOL,
141+
],
142+
[
143+
['127.0.0.1'],
144+
['ip' => ['127.0.0.1'], '--add' => true],
145+
[],
146+
'Set exempt IP-addresses: 127.0.0.1' . PHP_EOL,
147+
],
148+
[
149+
['127.0.0.1'],
150+
['ip' => ['127.0.0.2'], '--add' => true],
151+
[],
152+
'Set exempt IP-addresses: 127.0.0.1 127.0.0.2' . PHP_EOL,
153+
],
154+
];
155+
}
102156
}

0 commit comments

Comments
 (0)