home = getenv('HOME'); $this->homedrive = getenv('HOMEDRIVE'); $this->homepath = getenv('HOMEPATH'); } public function tear_down() { putenv('HOME=' . $this->home); putenv('HOMEDRIVE=' . $this->homedrive); putenv('HOMEPATH=' . $this->homepath); } public function testSsoTokenProviderSuccess() { $dir = $this->clearEnv(); $expiration = time() + 1000; $ini = << [ 'accessKeyId' => 'foo', 'secretAccessKey' => 'assumedSecret', 'sessionToken' => null, 'expiration' => $expiration ], ]; $sso = $this->getTestClient('SsoOidc', ['credentials' => false]); $this->addMockResults($sso, [ new Result($result) ]); try { $token = call_user_func(TokenProvider::sso( 'default', $configFilename, ['ssoClient' => $sso] ))->wait(); $this->assertSame('token', $token->getToken()); $this->assertSame('2500-12-25T21:30:00Z', $token->getExpiration()); $this->assertNull($token->getRegistrationExpiresAt()); } finally { unlink($dir . '/config'); unlink($tokenLocation); rmdir(dirname($tokenLocation)); } } public function testThrowsExceptionWithOnlyStartUrl() { $dir = $this->clearEnv(); $ini = <<expectException(TokenException::class); $this->expectExceptionMessage("must contain the following keys: sso_start_url and sso_region."); try { $tokenProvider = new SsoTokenProvider('test', $dir . '/config'); $tokenProvider()->wait(); } finally { unlink($dir . '/config'); } } public function testThrowsExceptionWithOnlySsoRegion() { $dir = $this->clearEnv(); $ini = <<expectException(TokenException::class); $this->expectExceptionMessage("must contain the following keys: sso_start_url and sso_region."); try { $tokenProvider = new SsoTokenProvider('test', $dir . '/config'); $tokenProvider()->wait(); } finally { unlink($configFilename); } } public function testThrowsExceptionWithNonExistingSession() { $dir = $this->clearEnv(); $ini = <<expectException(TokenException::class); $this->expectExceptionMessage("Profile test does not exist"); try { $tokenProvider = new SsoTokenProvider('test', $dir . '/config'); $tokenProvider()->wait(); } finally { unlink($dir . '/config'); } } public function testSsoSessionUnspecified() { $dir = $this->clearEnv(); $ini = <<wait(); $this->assertNull($token); } catch (\Exception $e) { throw $e; } finally { unlink($dir . '/config'); } } }