diff --git a/src/Common/Internal/Resources.php b/src/Common/Internal/Resources.php index b9e674cb4..1e9ef566c 100644 --- a/src/Common/Internal/Resources.php +++ b/src/Common/Internal/Resources.php @@ -61,6 +61,7 @@ class Resources { const CERTIFICATE_PATH_NAME = 'CertificatePath'; const SERVICE_MANAGEMENT_ENDPOINT_NAME = 'ServiceManagementEndpoint'; const SERVICE_BUS_ENDPOINT_NAME = 'Endpoint'; + const SERVICE_BUS_ENTITY_PATH = 'EntityPath'; const SHARED_SECRET_ISSUER_NAME = 'SharedSecretIssuer'; const SHARED_SECRET_VALUE_NAME = 'SharedSecretValue'; const SHARED_SHARED_ACCESS_KEY_NAME = 'SharedAccessKeyName'; diff --git a/src/Common/Internal/ServiceBusSettings.php b/src/Common/Internal/ServiceBusSettings.php index 78a853438..59d2c2da3 100644 --- a/src/Common/Internal/ServiceBusSettings.php +++ b/src/Common/Internal/ServiceBusSettings.php @@ -49,6 +49,11 @@ class ServiceBusSettings extends ServiceSettings { */ private $_serviceBusEndpointUri; + /** + * @var string|null + */ + private $_serviceBusEntityPath; + /** * @var string */ @@ -90,6 +95,13 @@ class ServiceBusSettings extends ServiceSettings { */ private static $_serviceBusEndpointSetting; + /** + * Validator for the EntityPath setting. + * + * @var array + */ + private static $_serviceBusEntityPathSetting; + /** * Validator for the StsEndpoint setting. Must be a valid Uri. * @@ -128,6 +140,10 @@ protected static function init() { Validate::getIsValidUri() ); + self::$_serviceBusEntityPathSetting = self::setting( + Resources::SERVICE_BUS_ENTITY_PATH + ); + self::$_wrapNameSetting = self::setting( Resources::SHARED_SECRET_ISSUER_NAME ); @@ -150,6 +166,7 @@ protected static function init() { ); self::$validSettingKeys[] = Resources::SERVICE_BUS_ENDPOINT_NAME; + self::$validSettingKeys[] = Resources::SERVICE_BUS_ENTITY_PATH; self::$validSettingKeys[] = Resources::SHARED_SECRET_ISSUER_NAME; self::$validSettingKeys[] = Resources::SHARED_SECRET_VALUE_NAME; self::$validSettingKeys[] = Resources::SHARED_SHARED_ACCESS_KEY_NAME; @@ -161,14 +178,16 @@ protected static function init() { * Creates new Service Bus settings instance. * @param type $serviceBusEndpoint The Service Bus endpoint uri * @param type $filter + * @param string $serviceBusEntityPath */ public function __construct( $serviceBusEndpoint, - $filter + $filter, + $serviceBusEntityPath = null ) { $this->_serviceBusEndpointUri = $serviceBusEndpoint; $this->_filter = $filter; - + $this->_serviceBusEntityPath = $serviceBusEntityPath; } /** @@ -182,6 +201,7 @@ private static function createServiceBusWithWrapAuthentication(array $tokenizedS self::$_wrapPasswordSetting, ]; $optional = [ + self::$_serviceBusEntityPathSetting, self::$_wrapEndpointUriSetting, ]; @@ -191,6 +211,10 @@ private static function createServiceBusWithWrapAuthentication(array $tokenizedS Resources::SERVICE_BUS_ENDPOINT_NAME, $tokenizedSettings ); + $entityPath = Utilities::tryGetValueInsensitive( + Resources::SERVICE_BUS_ENTITY_PATH, + $tokenizedSettings + ); // Parse the namespace part from the URI $namespace = explode('.', parse_url($endpoint, PHP_URL_HOST)); @@ -214,7 +238,7 @@ private static function createServiceBusWithWrapAuthentication(array $tokenizedS $issuerName, $issuerValue, self::createWrapService($wrapEndpointUri) - )); + ), $entityPath); } /** * @param array $tokenizedSettings @@ -227,6 +251,7 @@ private static function createServiceBusWithSasAuthentication(array $tokenizedSe self::$_sasKeySetting, ]; $optional = [ + self::$_serviceBusEntityPathSetting, self::$_wrapEndpointUriSetting, ]; $matchedSpecs = self::getMatchedSpecs($tokenizedSettings, $required, $optional, $connectionString); @@ -235,6 +260,10 @@ private static function createServiceBusWithSasAuthentication(array $tokenizedSe Resources::SERVICE_BUS_ENDPOINT_NAME, $tokenizedSettings ); + $entityPath = Utilities::tryGetValueInsensitive( + Resources::SERVICE_BUS_ENTITY_PATH, + $tokenizedSettings + ); $sharedAccessKeyName = Utilities::tryGetValueInsensitive( Resources::SHARED_SHARED_ACCESS_KEY_NAME, @@ -248,7 +277,7 @@ private static function createServiceBusWithSasAuthentication(array $tokenizedSe return new self($endpoint, new SASFilter( $sharedAccessKeyName, $sharedAccessKey - )); + ), $entityPath); } /** * @param $wrapEndpointUri @@ -305,6 +334,15 @@ public function getServiceBusEndpointUri() { return $this->_serviceBusEndpointUri; } + /** + * Gets the Service Bus entity path. + * + * @return string|null + */ + public function getServiceBusEntityPath() { + return $this->_serviceBusEntityPath; + } + /** * Gets the wrap endpoint URI. * diff --git a/tests/unit/WindowsAzure/Common/Internal/ServiceBusSettingsTest.php b/tests/unit/WindowsAzure/Common/Internal/ServiceBusSettingsTest.php index 1abe081c5..d4ed99b61 100644 --- a/tests/unit/WindowsAzure/Common/Internal/ServiceBusSettingsTest.php +++ b/tests/unit/WindowsAzure/Common/Internal/ServiceBusSettingsTest.php @@ -129,7 +129,7 @@ public function testCreateFromConnectionStringWithInvalidServiceBusKeyFail() $expectedMsg = sprintf( Resources::INVALID_CONNECTION_STRING_SETTING_KEY, $invalidKey, - implode("\n", ['Endpoint', 'SharedSecretIssuer', 'SharedSecretValue']) + implode("\n", ['Endpoint', 'EntityPath', 'SharedSecretIssuer', 'SharedSecretValue']) ); $this->setExpectedException('\RuntimeException', $expectedMsg); @@ -182,15 +182,16 @@ public function testGetFilter() * @covers \WindowsAzure\Common\Internal\ServiceSettings::parseAndValidateKeys * @covers \WindowsAzure\Common\Internal\ServiceSettings::noMatch */ - public function testCreateFromConnectionStringWithCaseInvesitive() + public function testCreateFromConnectionStringWithCaseInsensitive() { // Setup - $namepspace = 'mynamespace'; - $expectedServiceBusEndpoint = "https://$namepspace.servicebus.windows.net"; + $namespace = 'mynamespace'; + $expectedServiceBusEndpoint = "https://$namespace.servicebus.windows.net"; + $expectedServiceBusEntityPath = 'myqueue'; $expectedWrapName = 'myname'; $expectedWrapPassword = 'mypassword'; - $expectedWrapEndpointUri = "https://$namepspace-sb.accesscontrol.windows.net/WRAPv0.9"; - $connectionString = "eNdPoinT=$expectedServiceBusEndpoint;sHarEdsecRetiSsuer=$expectedWrapName;shArEdsecrEtvAluE=$expectedWrapPassword"; + $expectedWrapEndpointUri = "https://$namespace-sb.accesscontrol.windows.net/WRAPv0.9"; + $connectionString = "eNdPoinT=$expectedServiceBusEndpoint;sHarEdsecRetiSsuer=$expectedWrapName;shArEdsecrEtvAluE=$expectedWrapPassword;eNtItYpAtH=$expectedServiceBusEntityPath"; // Test $actual = ServiceBusSettings::createFromConnectionString($connectionString); @@ -198,6 +199,7 @@ public function testCreateFromConnectionStringWithCaseInvesitive() // Assert $this->assertInstanceOf('WindowsAzure\Common\Internal\IServiceFilter', $actual->getFilter()); $this->assertEquals($expectedServiceBusEndpoint, $actual->getServiceBusEndpointUri()); + $this->assertEquals($expectedServiceBusEntityPath, $actual->getServiceBusEntityPath()); } /**