From b484824e464f869312c21eb8bc89ae99b1dfa69a Mon Sep 17 00:00:00 2001 From: Felix Gradinaru Date: Tue, 3 Oct 2023 11:50:22 +0200 Subject: [PATCH] Improve other tests --- Tests/Unit/ZoomApiAccessTokenFactoryTest.php | 35 +++++++++++++++++++- Tests/Unit/ZoomApiServiceTest.php | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Tests/Unit/ZoomApiAccessTokenFactoryTest.php b/Tests/Unit/ZoomApiAccessTokenFactoryTest.php index 526b020..25c272f 100644 --- a/Tests/Unit/ZoomApiAccessTokenFactoryTest.php +++ b/Tests/Unit/ZoomApiAccessTokenFactoryTest.php @@ -47,7 +47,7 @@ public static function getInvalidConfigurations(): array * @dataProvider getInvalidConfigurations * @test */ - public function invalidConfigurationWillThrowException($invalidConfiguration): void + public function invalidConfigurationWillThrowException(array $invalidConfiguration): void { $this->expectException(ZoomApiException::class); $this->expectExceptionMessage('Please set a Zoom Account ID, Client ID and Secret for CodeQ.ZoomApi to be able to authenticate.'); @@ -81,6 +81,39 @@ public function unsuccessfulRequestThrowsZoomApiException(): void $factoryMock->createFromConfiguration(); } + public static function getInvalidAccessTokenScopes(): array + { + return [ + ['recording:read:admin,meeting:read:admin'], + ['user:read:admin,meeting:read:admin'], + ['user:read:admin,recording:read:admin'], + ]; + } + + /** + * @test + * @dataProvider getInvalidAccessTokenScopes + * @param string $scopes + * + * @return void + */ + public function missingAccessTokenScopesThrowsZoomApiException(string $scopes): void + { + $this->expectException(ZoomApiException::class); + $this->expectExceptionMessage('Please ensure your Zoom app has the following scopes: user:read:admin, recording:read:admin, meeting:read:admin'); + + + $handlerStack = HandlerStack::create( + new MockHandler([ + new Response(200, [], json_encode(['access_token' => '1234567890', 'scope' => $scopes])) + ]) + ); + $factoryMock = $this->getFactory($handlerStack); + + + $factoryMock->createFromConfiguration(); + } + private function getFactory(HandlerStack $handlerStack = null): ZoomApiAccessTokenFactory|MockObject { $factory = $this->getAccessibleMock(ZoomApiAccessTokenFactory::class, ['buildClient'], [], '', false); diff --git a/Tests/Unit/ZoomApiServiceTest.php b/Tests/Unit/ZoomApiServiceTest.php index b74c636..f5ed8d7 100644 --- a/Tests/Unit/ZoomApiServiceTest.php +++ b/Tests/Unit/ZoomApiServiceTest.php @@ -238,7 +238,7 @@ public function getUpcomingMeetingsWithEmptyResponseThrowsException() } /** - * @param Client $client + * @param HandlerStack|null $handlerStack * * @return ZoomApiService|MockObject */