From 9a00f2022b58a92ac27ff789fd8338cb5ba59c18 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Tue, 22 Jan 2013 16:14:26 -0800 Subject: [PATCH] 20: Fix issue with xml2js upgrade by keeping it on 1.0 version for now and adding some SM UT --- lib/services/core/serviceclient.js | 10 +- .../models/parseserverresponse.js | 4 +- .../servicemanagementservice.js | 5 +- .../servicemanagementservice-tests.js | 175 ++++++++++++++++++ test/testlist.txt | 1 + 5 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 test/services/serviceManagement/servicemanagementservice-tests.js diff --git a/lib/services/core/serviceclient.js b/lib/services/core/serviceclient.js index 761d55fd7a..a520a6acc8 100644 --- a/lib/services/core/serviceclient.js +++ b/lib/services/core/serviceclient.js @@ -117,6 +117,8 @@ function ServiceClient(host, authenticationProvider) { this.proxyProtocol = 'http:' this.authenticationProvider = authenticationProvider; this.logger = new Logger(Logger.LogLevels.INFO); + + this.xml2jsVersion = '0.2'; } util.inherits(ServiceClient, events.EventEmitter); @@ -493,7 +495,13 @@ ServiceClient.prototype._parseResponse = function (response) { parsedBody = { parsingError: error }; } } else { - var parser = new xml2js.Parser({normalize: false, trim: false}); + var settings = xml2js.defaults[this.xml2jsVersion]; + settings.normalize = false; + settings.trim = false; + settings.attrkey = Constants.XML_METADATA_MARKER; + settings.charkey = Constants.XML_VALUE_MARKER; + + var parser = new xml2js.Parser(settings); var parseError = null; parser.on('error', function (e) { parseError = e; }); parser.parseString(response.body); diff --git a/lib/services/serviceManagement/models/parseserverresponse.js b/lib/services/serviceManagement/models/parseserverresponse.js index 3d1b4cc6a0..416837021b 100644 --- a/lib/services/serviceManagement/models/parseserverresponse.js +++ b/lib/services/serviceManagement/models/parseserverresponse.js @@ -29,7 +29,7 @@ function parseResult(body) { return; } - var result = null; + var result = body; if( _.isArray(body)) { if (body.length === 1 && !_.isUndefined(body[0]) && !_.isObject(body[0])) { @@ -41,7 +41,7 @@ function parseResult(body) { result.push(parseResult(entry)); }); } - } else { + } else if (_.isObject(body)) { result = { }; _.each(_.keys(body), function (entry) { if (entry !== Constants.XML_METADATA_MARKER) { diff --git a/lib/services/serviceManagement/servicemanagementservice.js b/lib/services/serviceManagement/servicemanagementservice.js index 63e66a6120..903d4c9dca 100644 --- a/lib/services/serviceManagement/servicemanagementservice.js +++ b/lib/services/serviceManagement/servicemanagementservice.js @@ -55,6 +55,7 @@ function ServiceManagementService(subscriptionId, authentication, hostOptions) { this.subscriptionId = subscriptionId; this.serialize = new ServiceManagementSerialize(); + this.xml2jsVersion = '0.1'; } util.inherits(ServiceManagementService, ServiceManagementClient); @@ -1366,8 +1367,8 @@ ServiceManagementService.prototype.addCertificate = function(serviceName, data, * Deletes a specified certificate. * * @param {string} serviceName The name of the hosted service. Required. -* @param {string} serviceName Certificate thumbprint algorithm. Required. -* @param {string} serviceName Certificate thumbprint. Required. +* @param {string} algorithm Certificate thumbprint algorithm. Required. +* @param {string} thumbprint Certificate thumbprint. Required. * @param {function} callback The callback function called on completion. Required. */ ServiceManagementService.prototype.deleteCertificate = function(serviceName, algorithm, thumbprint, callback) { diff --git a/test/services/serviceManagement/servicemanagementservice-tests.js b/test/services/serviceManagement/servicemanagementservice-tests.js new file mode 100644 index 0000000000..1224af7cd1 --- /dev/null +++ b/test/services/serviceManagement/servicemanagementservice-tests.js @@ -0,0 +1,175 @@ +/** +* Copyright (c) Microsoft. All rights reserved. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +var should = require('should'); +var mocha = require('mocha'); +var uuid = require('node-uuid'); + +var testutil = require('../../util/util'); + +var azure = testutil.libRequire('azure'); + +describe('Service Management', function () { + var service; + + before(function () { + var subscriptionId = process.env['AZURE_SUBSCRIPTION_ID']; + var auth = { keyvalue: process.env['AZURE_CERTIFICATE_KEY'], certvalue: process.env['AZURE_CERTIFICATE'] }; + service = azure.createServiceManagementService( + subscriptionId, auth, + { serializetype: 'XML'}); + }); + + describe('list locations', function () { + it('should list all locations', function (done) { + service.listLocations(function (err, response) { + should.exist(response.body); + should.exist(response.body.filter(function (location) { + return location.DisplayName === 'West Europe' && + location.Name === 'West Europe' && + location.AvailableServices !== undefined && + location.AvailableServices.AvailableService !== undefined && + location.AvailableServices.AvailableService.length === 3 + })); + + done(err); + }); + }); + }); + + describe('hosted services', function () { + var originalHostedServices; + var hostedServiceName = 'xplatcli-' + uuid.v4().substr(0, 8); + var hostedServiceLocation = 'West US'; + + before(function (done) { + service.listHostedServices(function (err, response) { + originalHostedServices = response; + + service.createHostedService(hostedServiceName, { Location: hostedServiceLocation }, done); + }); + }); + + after(function (done) { + service.deleteHostedService(hostedServiceName, done); + }); + + it('should list created hosted service', function (done) { + service.listHostedServices(function (err, response) { + should.not.exist(err); + should.exist(response.body.filter(function (hostedService) { + return hostedService.ServiceName === hostedServiceName; + })); + + done(err); + }); + }); + + it('should get created hosted service', function (done) { + service.getHostedService(hostedServiceName, function (err, response) { + should.not.exist(err); + + response.body.ServiceName.should.equal(hostedServiceName); + response.body.HostedServiceProperties.Description.should.equal('Service host'); + response.body.HostedServiceProperties.Location.should.equal(hostedServiceLocation); + response.body.HostedServiceProperties.Status.should.equal('Created'); + + done(err); + }); + }); + + it('should get created hosted service properties', function (done) { + service.getHostedServiceProperties(hostedServiceName, function (err, response) { + should.not.exist(err); + + response.body.ServiceName.should.equal(hostedServiceName); + response.body.HostedServiceProperties.Description.should.equal('Service host'); + response.body.HostedServiceProperties.Location.should.equal(hostedServiceLocation); + response.body.HostedServiceProperties.Status.should.equal('Created'); + + done(err); + }); + }); + + it('should get created hosted service properties', function (done) { + service.getHostedServiceProperties(hostedServiceName, function (err, response) { + should.not.exist(err); + + response.body.ServiceName.should.equal(hostedServiceName); + response.body.HostedServiceProperties.Description.should.equal('Service host'); + response.body.HostedServiceProperties.Location.should.equal(hostedServiceLocation); + response.body.HostedServiceProperties.Status.should.equal('Created'); + + done(err); + }); + }); + }); + + describe('storage accounts', function () { + var originalStorageAccounts; + var storageAccountName = 'xplatcli' + uuid.v4().substr(0, 8).replace(/-/g, ''); + var storageAccountLocation = 'West US'; + + before(function (done) { + service.listStorageAccounts(function (err, response) { + originalStorageAccounts = response; + + service.createStorageAccount(storageAccountName, { Location: storageAccountLocation }, done); + }); + }); + + after(function (done) { + service.deleteStorageAccount(storageAccountName, done); + }); + + it('should list storage accounts', function (done) { + service.listStorageAccounts(function (err, response) { + should.not.exist(err); + + should.exist(response.body.filter(function (storageAccount) { + return storageAccount.ServiceName === storageAccountName; + })); + + done(err); + }); + }); + + it('should get created storage account properties', function (done) { + service.getStorageAccountProperties(storageAccountName, function (err, response) { + should.not.exist(err); + + response.body.ServiceName.should.equal(storageAccountName); + + // TODO: fix issue with handling null values for description + // response.body.StorageServiceProperties.Description.should.be.null + + response.body.StorageServiceProperties.Location.should.equal(storageAccountLocation); + + done(err); + }); + }); + + it('should get created storage account keys', function (done) { + service.getStorageAccountKeys(storageAccountName, function (err, response) { + should.not.exist(err); + + response.body.StorageServiceKeys.Primary.should.not.be.null; + response.body.StorageServiceKeys.Secondary.should.not.be.null; + + done(err); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/testlist.txt b/test/testlist.txt index c3ba67e6d9..994692ea18 100644 --- a/test/testlist.txt +++ b/test/testlist.txt @@ -22,6 +22,7 @@ services/table/sharedkeylitetable-tests.js services/serviceBus/servicebusservice-tests.js services/serviceBus/wrapservice-tests.js services/serviceBus/wraptokenmanager-tests.js +services/serviceManagement/servicemanagementservice-tests.js services/serviceManagement/sqldatabaseservice-tests.js services/table/tablequery-tests.js services/table/tableservice-batch-tests.js