diff --git a/src/UnleashBuilder.php b/src/UnleashBuilder.php index d2b02f87..6f0cac3c 100755 --- a/src/UnleashBuilder.php +++ b/src/UnleashBuilder.php @@ -529,6 +529,7 @@ public function build(): Unleash if ($this->proxyKey !== null) { $configuration->setProxyKey($this->proxyKey); + $configuration->setHeaders(array_merge($this->headers, ['Authorization' => $this->proxyKey])); $proxyRepository = new DefaultUnleashProxyRepository( $configuration, $httpClient, diff --git a/tests/UnleashBuilderTest.php b/tests/UnleashBuilderTest.php index fa5956a0..2668c456 100755 --- a/tests/UnleashBuilderTest.php +++ b/tests/UnleashBuilderTest.php @@ -883,6 +883,27 @@ public function testBuilderWithProxyKeyYieldsProxyUnleash() self::assertInstanceOf(DefaultProxyUnleash::class, $base->build()); } + public function testbuilderWithProxyKeyYieldsAuthorizationHeader() + { + $base = $this->instance->withProxy('proxy-key')->withAppUrl('https://localhost')->withInstanceId('test')->withAppName('test'); + $unleash = $base->build(); + $reflection = new ReflectionObject($unleash); + $repositoryProperty = $reflection->getProperty('repository'); + $repositoryProperty->setAccessible(true); + $repository = $repositoryProperty->getValue($unleash); + + $reflection = new ReflectionObject($repository); + $configurationProperty = $reflection->getProperty('configuration'); + $configurationProperty->setAccessible(true); + $configuration = $configurationProperty->getValue($repository); + + $reflection = new ReflectionObject($configuration); + $headersPropertyBuilt = $reflection->getProperty('headers'); + $headersPropertyBuilt->setAccessible(true); + $headersBuilt = $headersPropertyBuilt->getValue($configuration); + self::assertArrayHasKey('Authorization', $headersBuilt); + } + private function getConfiguration(DefaultUnleash $unleash): UnleashConfiguration { $configurationProperty = (new ReflectionObject($unleash))->getProperty('configuration');