Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding more UT

  • Loading branch information...
commit 79c6e1cf357788fecf27018ae3860f834358262d 1 parent 96cd610
@andrerod andrerod authored
View
51 lib/services/core/servicemanagementsettings.js
@@ -23,7 +23,7 @@ var Constants = require('../../util/constants');
var ConnectionStringKeys = Constants.ConnectionStringKeys;
var Validate = require('../../util/validate');
-exports = module.exports = ServiceBusSettings;
+exports = module.exports = ServiceManagementSettings;
var _endpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME,
@@ -51,9 +51,56 @@ var validKeys = [
* @param {string} endpointUri The service management endpoint uri.
* @param {string} certificatePath The management certificate path.
*/
-function ServiceBusSettings(subscriptionId, endpointUri, certificatePath) {
+function ServiceManagementSettings(subscriptionId, endpointUri, certificatePath) {
this._subscriptionId = subscriptionId;
this._endpointUri = endpointUri;
this._certificatePath = certificatePath;
}
+/**
+* Creates a ServiceManagementSettings object from the given connection string.
+*
+* @param {string} connectionString The storage settings connection string.
+*
+* @return {ServiceManagementSettings}
+*/
+ServiceManagementSettings.createFromConnectionString = function (connectionString) {
+ var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
+
+ var matchedSpecs = ServiceSettings.matchedSpecification(
+ tokenizedSettings,
+ ServiceSettings.allRequired(
+ _subscriptionIdSetting,
+ _certificatePathSetting
+ ),
+ ServiceSettings.optional(
+ _endpointSetting
+ )
+ );
+
+ if (matchedSpecs) {
+ var endpointUri = util.tryGetValueInsensitive(
+ ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME,
+ tokenizedSettings,
+ Constants.SERVICE_MANAGEMENT_URL
+ );
+
+ var subscriptionId = util.tryGetValueInsensitive(
+ ConnectionStringKeys.SUBSCRIPTION_ID_NAME,
+ tokenizedSettings
+ );
+
+ var certificatePath = util.tryGetValueInsensitive(
+ ConnectionStringKeys.CERTIFICATE_PATH_NAME,
+ tokenizedSettings
+ );
+
+ return new ServiceManagementSettings(
+ subscriptionId,
+ endpointUri,
+ certificatePath
+ );
+ }
+
+ ServiceSettings.noMatch(connectionString);
+}
View
8 lib/util/constants.js
@@ -826,6 +826,14 @@ var Constants = {
DEV_STORE_URI: 'http://127.0.0.1',
/**
+ * The service management URI.
+ *
+ * @const
+ * @type {string}
+ */
+ SERVICE_MANAGEMENT_URL: 'https://management.core.windows.net',
+
+ /**
* Defines constants for use with blob operations.
*/
BlobConstants: {
View
69 test/services/core/servicemanagementsettings-tests.js
@@ -23,5 +23,72 @@ var ConnectionStringKeys = Constants.ConnectionStringKeys;
var ServiceManagementSettings = azure.ServiceManagementSettings;
suite('servicemanagementsettings-tests', function () {
-
+ test('testCreateFromConnectionStringWithAutomaticCase', function () {
+ // Setup
+ var expectedSubscriptionId = 'mySubscriptionId';
+ var expectedCertificatePath = 'C:\\path_to_my_cert.pem';
+ var expectedEndpointUri = Constants.SERVICE_MANAGEMENT_URL;
+ var connectionString = 'SubscriptionID=' + expectedSubscriptionId + ';CertificatePath=' + expectedCertificatePath;
+
+ // Test
+ var actual = ServiceManagementSettings.createFromConnectionString(connectionString);
+
+ // Assert
+ actual._subscriptionId.should.equal(expectedSubscriptionId);
+ actual._certificatePath.should.equal(expectedCertificatePath);
+ actual._endpointUri.should.equal(expectedEndpointUri)
+ });
+
+ test('testCreateFromConnectionStringWithExplicitCase', function () {
+ // Setup
+ var expectedSubscriptionId = 'mySubscriptionId';
+ var expectedCertificatePath = 'C:\\path_to_my_cert.pem';
+ var expectedEndpointUri = 'http://myprivatedns.com';
+ var connectionString = 'SubscriptionID=' + expectedSubscriptionId + ';CertificatePath=' + expectedCertificatePath + ';ServiceManagementEndpoint=' + expectedEndpointUri;
+
+ // Test
+ var actual = ServiceManagementSettings.createFromConnectionString(connectionString);
+
+ // Assert
+ actual._subscriptionId.should.equal(expectedSubscriptionId);
+ actual._certificatePath.should.equal(expectedCertificatePath);
+ actual._endpointUri.should.equal(expectedEndpointUri)
+ });
+
+ test('testCreateFromConnectionStringWithMissingKeyFail', function () {
+ // Setup
+ var connectionString = 'CertificatePath=C:\\path_to_my_cert.pem;ServiceManagementEndpoint=http://myprivatedns.com';
+
+ // Test
+ (function() {
+ ServiceManagementSettings.createFromConnectionString(connectionString);
+ }).should.throw('The provided connection string ' + connectionString + ' does not have complete configuration settings.');
+ });
+
+ test('testCreateFromConnectionStringWithInvalidServiceManagementKeyFail', function () {
+ // Setup
+ var invalidKey = 'InvalidKey';
+ var connectionString = invalidKey + '=value;SubscriptionID=12345;CertificatePath=C:\\path_to_cert;ServiceManagementEndpoint=http://endpoint.com';
+
+ // Test
+ (function() {
+ ServiceManagementSettings.createFromConnectionString(connectionString);
+ }).should.throw('Invalid connection string setting key ' + invalidKey.toLowerCase());
+ });
+
+ test('testCreateFromConnectionStringWithCaseInsensitive', function () {
+ // Setup
+ var expectedSubscriptionId = 'mySubscriptionId';
+ var expectedCertificatePath = 'C:\\path_to_my_cert.pem';
+ var expectedEndpointUri = 'http://myprivatedns.com';
+ var connectionString = 'suBscriptIonId=' + expectedSubscriptionId + ';ceRtiFicAtepAth=' + expectedCertificatePath + ';ServiCemAnagemenTendPoinT=' + expectedEndpointUri;
+
+ // Test
+ var actual = ServiceManagementSettings.createFromConnectionString(connectionString);
+
+ // Assert
+ actual._subscriptionId.should.equal(expectedSubscriptionId);
+ actual._certificatePath.should.equal(expectedCertificatePath);
+ actual._endpointUri.should.equal(expectedEndpointUri)
+ });
});
View
1  test/testlist.txt
@@ -13,6 +13,7 @@ services/core/exponentialretrypolicyfilter-tests.js
services/core/linearretrypolicyfilter-tests.js
services/core/servicesettings-tests.js
services/core/servicebussettings-tests.js
+services/core/servicemanagementsettings-tests.js
services/core/storageservicesettings-tests.js
services/queue/queueservice-tests.js
services/table/batchserviceclient-tests.js
Please sign in to comment.
Something went wrong with that request. Please try again.