diff options
author | Maxime Besson <maxime.besson@worteks.com> | 2020-08-10 11:54:19 +0300 |
---|---|---|
committer | Maxime Besson <maxime.besson@worteks.com> | 2020-08-18 19:41:54 +0300 |
commit | 8c4f9da56de99567c1da9cea8f5ad18685be42f0 (patch) | |
tree | 61987b032b2fe83da6d2ab0ca35ebe5436955950 /tests | |
parent | 0c494e82cf24fba9c22cfee165ac8646004d2bf9 (diff) |
Add occ command to dump metadata for a given provider
Signed-off-by: Maxime Besson <maxime.besson@worteks.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/Command/GetMetadataTest.php | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/unit/Command/GetMetadataTest.php b/tests/unit/Command/GetMetadataTest.php new file mode 100644 index 00000000..2ab745c4 --- /dev/null +++ b/tests/unit/Command/GetMetadataTest.php @@ -0,0 +1,102 @@ +<?php +/** + * @copyright Copyright (c) 2020 Maxime Besson <maxime.besson@worteks.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\User_SAML\Tests\Command; + +use OCA\User_SAML\Command\GetMetadata; +use OCA\User_SAML\SAMLSettings; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use OCP\IConfig; +use OCP\IRequest; +use OCP\ISession; +use OCP\IURLGenerator; + + +class GetMetadataTest extends \Test\TestCase { + + /** @var GetMetadata|\PHPUnit_Framework_MockObject_MockObject*/ + protected $GetMetadata; + /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ + private $request; + /** @var ISession|\PHPUnit_Framework_MockObject_MockObject */ + private $session; + /** @var SAMLSettings|\PHPUnit_Framework_MockObject_MockObject*/ + private $samlSettings; + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ + private $config; + /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ + private $urlGenerator; + + + protected function setUp(): void { + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->config = $this->createMock(IConfig::class); + $this->request = $this->createMock(IRequest::class); + $this->session = $this->createMock(ISession::class); + + $this->samlSettings = new SAMLSettings($this->urlGenerator, + $this->config, + $this->request, + $this->session); + $this->GetMetadata = new GetMetadata($this->samlSettings); + + parent::setUp(); + } + + public function testGetMetadata(){ + $inputInterface = $this->createMock(InputInterface::class); + $outputInterface = $this->createMock(OutputInterface::class); + $this->urlGenerator + ->expects($this->at(0)) + ->method('linkToRouteAbsolute') + ->with('user_saml.SAML.base') + ->willReturn('https://nextcloud.com/base/'); + $this->urlGenerator + ->expects($this->at(1)) + ->method('linkToRouteAbsolute') + ->with('user_saml.SAML.getMetadata') + ->willReturn('https://nextcloud.com/metadata/'); + $this->urlGenerator + ->expects($this->at(2)) + ->method('linkToRouteAbsolute') + ->with('user_saml.SAML.assertionConsumerService') + ->willReturn('https://nextcloud.com/acs/'); + $this->config->expects($this->any())->method('getAppValue') + ->willReturnCallback(function($app, $key, $default) { + if ($key == 'idp-entityId') { + return "dummy"; + } + if ($key == 'idp-singleSignOnService.url') { + return "https://example.com/sso"; + } + if ($key == 'idp-x509cert') { + return "DUMMY CERTIFICATE"; + } + return $default; + }); + + $outputInterface->expects($this->once())->method('writeln') + ->with($this->stringContains('md:EntityDescriptor')); + + $this->invokePrivate($this->GetMetadata, 'execute', [$inputInterface, $outputInterface]); + } +} |