From 01428621f90abb843de360b2d344c55785ec0a30 Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Tue, 3 May 2016 13:10:11 -0700 Subject: [PATCH] [NodeJS] Redesigned the structure of AzureEnvironment and updated environment info (#998) * Enhancement to x-ms-parameterized-host extension * positionInOperation defaults to first * fixed setting default value for a complex object containing constant properties. * result of executing gulp regenerate:expected * Fixed fxcop warnings * remove null check validation for unixtime as they are treated as long in java * unixTime in node.js * modification * UnixTime tests * FxCop warnings * Redesigned the structure of AzureEnvironment and updated the environments with more values. * getting rid of underscore.js as a dependency from ms-rest-azure --- .../ms-rest-azure/lib/azureEnvironment.js | 176 ++++++++++--- .../applicationTokenCredentials.js | 4 +- .../lib/credentials/userTokenCredentials.js | 4 +- .../NodeJS/ms-rest-azure/lib/index.d.ts | 234 ++++++++++++------ .../NodeJS/ms-rest-azure/package.json | 1 - .../test/azureEnvironmentTests.js | 91 +++++++ .../NodeJS/ms-rest-azure/test/package.json | 3 +- .../NodeJS/ms-rest-azure/test/testlist.txt | 3 +- 8 files changed, 400 insertions(+), 116 deletions(-) create mode 100644 ClientRuntimes/NodeJS/ms-rest-azure/test/azureEnvironmentTests.js diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureEnvironment.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureEnvironment.js index 9aa5e6fb2a..e902c471c5 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureEnvironment.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureEnvironment.js @@ -2,48 +2,158 @@ // Licensed under the MIT License. See License.txt in the project root for license information. 'use strict'; - -var _ = require('underscore'); - +var util = require('util'); /** * @class * Initializes a new instance of the AzureEnvironment class. * @constructor - * @param {string} authenticationEndpoint - ActiveDirectory Endpoint for the Azure Environment. - * @param {string} tokenAudience - Token audience for an endpoint. - * @param {bool} [validateAuthority] - Determines whether the authentication endpoint should + * @param {string} parameters.name - The Environment name + * @param {string} parameters.portalUrl - the management portal URL + * @param {string} parameters.managementEndpointUrl - the management service endpoint + * @param {string} parameters.resourceManagerEndpointUrl - the resource management endpoint + * @param {string} parameters.activeDirectoryEndpointUrl - the Active Directory login endpoint + * @param {string} parameters.activeDirectoryResourceId - The resource ID to obtain AD tokens for + * @param {string} [parameters.publishingProfileUrl] - the publish settings file URL + * @param {string} [parameters.sqlManagementEndpointUrl] - the sql server management endpoint for mobile commands + * @param {string} [parameters.sqlServerHostnameSuffix] - the dns suffix for sql servers + * @param {string} [parameters.galleryEndpointUrl] - the template gallery endpoint + * @param {string} [parameters.activeDirectoryGraphResourceId] - the Active Directory resource ID + * @param {string} [parameters.activeDirectoryGraphApiVersion] - the Active Directory api version + * @param {string} [parameters.storageEndpointSuffix] - the endpoint suffix for storage accounts + * @param {string} [parameters.keyVaultDnsSuffix] - the keyvault service dns suffix + * @param {string} [parameters.azureDataLakeStoreFileSystemEndpointSuffix] - the data lake store filesystem service dns suffix + * @param {string} [parameters.azureDataLakeAnalyticsCatalogAndJobEndpointSuffix] - the data lake analytics job and catalog service dns suffix + * @param {bool} [parameters.validateAuthority] - Determines whether the authentication endpoint should * be validated with Azure AD. Default value is true. */ -function AzureEnvironment(authenticationEndpoint, tokenAudience, validateAuthority) { - this.authenticationEndpoint = authenticationEndpoint; - this.tokenAudience = tokenAudience; - this.validateAuthority = validateAuthority; -} +function AzureEnvironment(parameters) { + //Set defaults. + this.validateAuthority = true; -/** - * Provides the settings for authentication with Azure - */ -var Azure = new AzureEnvironment('https://login.microsoftonline.com/', - 'https://management.core.windows.net/', - true); + if (parameters) { + //Validate required parameters + var requiredParams = [ 'name', 'portalUrl', 'managementEndpointUrl', 'resourceManagerEndpointUrl', + 'activeDirectoryEndpointUrl', 'activeDirectoryResourceId']; + requiredParams.forEach(function (param) { + if (!parameters[param] || typeof parameters[param].valueOf() !== 'string') { + throw new Error(util.format('Please provide "%s" for the environment and it must be of type "string".', param)); + } + }); + //Assign provided parameters + for (var prop in parameters) { + this[prop] = parameters[prop]; + } + } +} +var supportedEnvironments = { + Azure: { + name: 'Azure', + portalUrl: 'http://go.microsoft.com/fwlink/?LinkId=254433', + publishingProfileUrl: 'http://go.microsoft.com/fwlink/?LinkId=254432', + managementEndpointUrl: 'https://management.core.windows.net', + resourceManagerEndpointUrl: 'https://management.azure.com/', + sqlManagementEndpointUrl: 'https://management.core.windows.net:8443/', + sqlServerHostnameSuffix: '.database.windows.net', + galleryEndpointUrl: 'https://gallery.azure.com/', + activeDirectoryEndpointUrl: 'https://login.microsoftonline.com', + activeDirectoryResourceId: 'https://management.core.windows.net/', + activeDirectoryGraphResourceId: 'https://graph.windows.net/', + activeDirectoryGraphApiVersion: '2013-04-05', + storageEndpointSuffix: '.core.windows.net', + keyVaultDnsSuffix: '.vault.azure.net', + azureDataLakeStoreFileSystemEndpointSuffix: 'azuredatalakestore.net', + azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: 'azuredatalakeanalytics.net' + }, + AzureChina: { + name: 'AzureChina', + portalUrl: 'http://go.microsoft.com/fwlink/?LinkId=301902', + publishingProfileUrl: 'http://go.microsoft.com/fwlink/?LinkID=301774', + managementEndpointUrl: 'https://management.core.chinacloudapi.cn', + resourceManagerEndpointUrl: 'https://management.chinacloudapi.cn', + sqlManagementEndpointUrl: 'https://management.core.chinacloudapi.cn:8443/', + sqlServerHostnameSuffix: '.database.chinacloudapi.cn', + galleryEndpointUrl: 'https://gallery.chinacloudapi.cn/', + activeDirectoryEndpointUrl: 'https://login.chinacloudapi.cn', + activeDirectoryResourceId: 'https://management.core.chinacloudapi.cn/', + activeDirectoryGraphResourceId: 'https://graph.chinacloudapi.cn/', + activeDirectoryGraphApiVersion: '2013-04-05', + storageEndpointSuffix: '.core.chinacloudapi.cn', + keyVaultDnsSuffix: '.vault.azure.cn', + // TODO: add dns suffixes for the china cloud for datalake store and datalake analytics once they are defined. + azureDataLakeStoreFileSystemEndpointSuffix: 'N/A', + azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: 'N/A' + }, + AzureUSGovernment: { + name: 'AzureUSGovernment', + portalUrl: 'https://manage.windowsazure.us', + publishingProfileUrl: 'https://manage.windowsazure.us/publishsettings/index', + managementEndpointUrl: 'https://management.core.usgovcloudapi.net', + resourceManagerEndpointUrl: 'https://management.usgovcloudapi.net', + sqlManagementEndpointUrl: 'https://management.core.usgovcloudapi.net:8443/', + sqlServerHostnameSuffix: '.database.usgovcloudapi.net', + galleryEndpointUrl: 'https://gallery.usgovcloudapi.net/', + activeDirectoryEndpointUrl: 'https://login.microsoftonline.com', + activeDirectoryResourceId: 'https://management.core.usgovcloudapi.net/', + activeDirectoryGraphResourceId: 'https://graph.windows.net/', + activeDirectoryGraphApiVersion: '2013-04-05', + storageEndpointSuffix: '.core.usgovcloudapi.net', + keyVaultDnsSuffix: '.vault.usgovcloudapi.net', + // TODO: add dns suffixes for the US government for datalake store and datalake analytics once they are defined. + azureDataLakeStoreFileSystemEndpointSuffix: 'N/A', + azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: 'N/A' + }, + AzureGermanCloud: { + name: 'AzureGermanCloud', + portalUrl: 'http://portal.microsoftazure.de/', + publishingProfileUrl: 'https://manage.microsoftazure.de/publishsettings/index', + managementEndpointUrl: 'https://management.core.cloudapi.de', + resourceManagerEndpointUrl: 'https://management.microsoftazure.de', + sqlManagementEndpointUrl: 'https://management.core.cloudapi.de:8443/', + sqlServerHostnameSuffix: '.database.cloudapi.de', + galleryEndpointUrl: 'https://gallery.cloudapi.de/', + activeDirectoryEndpointUrl: 'https://login.microsoftonline.de', + activeDirectoryResourceId: 'https://management.core.cloudapi.de/', + activeDirectoryGraphResourceId: 'https://graph.cloudapi.de/', + activeDirectoryGraphApiVersion: '2013-04-05', + storageEndpointSuffix: '.core.cloudapi.de', + keyVaultDnsSuffix: '.vault.microsoftazure.de', + // TODO: add dns suffixes for the US government for datalake store and datalake analytics once they are defined. + azureDataLakeStoreFileSystemEndpointSuffix: 'N/A', + azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: 'N/A' + } +}; /** - * Provides the settings for authentication with Azure China + * Adds a new instance of the AzureEnvironment to the prototype. + * @param {string} parameters.name - The Environment name + * @param {string} parameters.portalUrl - the management portal URL + * @param {string} parameters.managementEndpointUrl - the management service endpoint + * @param {string} parameters.resourceManagerEndpointUrl - the resource management endpoint + * @param {string} parameters.activeDirectoryEndpointUrl - the Active Directory login endpoint + * @param {string} parameters.activeDirectoryResourceId - The resource ID to obtain AD tokens for + * @param {string} [parameters.publishingProfileUrl] - the publish settings file URL + * @param {string} [parameters.sqlManagementEndpointUrl] - the sql server management endpoint for mobile commands + * @param {string} [parameters.sqlServerHostnameSuffix] - the dns suffix for sql servers + * @param {string} [parameters.galleryEndpointUrl] - the template gallery endpoint + * @param {string} [parameters.activeDirectoryGraphResourceId] - the Active Directory resource ID + * @param {string} [parameters.activeDirectoryGraphApiVersion] - the Active Directory api version + * @param {string} [parameters.storageEndpointSuffix] - the endpoint suffix for storage accounts + * @param {string} [parameters.keyVaultDnsSuffix] - the keyvault service dns suffix + * @param {string} [parameters.azureDataLakeStoreFileSystemEndpointSuffix] - the data lake store filesystem service dns suffix + * @param {string} [parameters.azureDataLakeAnalyticsCatalogAndJobEndpointSuffix] - the data lake analytics job and catalog service dns suffix + * @param {bool} [parameters.validateAuthority] - Determines whether the authentication endpoint should + * be validated with Azure AD. Default value is true. + * @return {AzureEnvironment} - Reference to the newly added Environment */ -var AzureChina = new AzureEnvironment('https://login.chinacloudapi.cn/', - 'https://management.core.chinacloudapi.cn/', - true); +AzureEnvironment.prototype.add = function(parameters) { + var _environment = new AzureEnvironment(parameters); + AzureEnvironment.prototype[_environment.name] = _environment; + return _environment; +}; -/** - * Provides the settings for authentication with Azure US Government - */ -var AzureUSGovernment = new AzureEnvironment('https://login.microsoftonline.com/', - 'https://management.core.usgovcloudapi.net/', - true); +//Adding the supported environments +for(var key in supportedEnvironments) { + AzureEnvironment.prototype.add(supportedEnvironments[key]); +} -_.extend(module.exports, { - Azure: Azure, - AzureChina: AzureChina, - AzureEnvironment: AzureEnvironment, - AzureUSGovernment: AzureUSGovernment -}); +module.exports = new AzureEnvironment(); \ No newline at end of file diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/credentials/applicationTokenCredentials.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/credentials/applicationTokenCredentials.js index 0c4fe85033..e096edbff2 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/credentials/applicationTokenCredentials.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/credentials/applicationTokenCredentials.js @@ -65,10 +65,10 @@ function ApplicationTokenCredentials(clientId, domain, secret, options) { */ ApplicationTokenCredentials.prototype.signRequest = function (webResource, callback) { var self = this; - var authorityUrl = self.environment.authenticationEndpoint + self.domain; + var authorityUrl = self.environment.activeDirectoryEndpointUrl + self.domain; var context = new adal.AuthenticationContext(authorityUrl, self.environment.validateAuthority, self.tokenCache); - context.acquireTokenWithClientCredentials(self.environment.tokenAudience, self.clientId, self.secret, function (err, result) { + context.acquireTokenWithClientCredentials(self.environment.activeDirectoryResourceId, self.clientId, self.secret, function (err, result) { if (err) { return callback(new Error('Failed to acquire token for application. \n' + err)); } diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/credentials/userTokenCredentials.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/credentials/userTokenCredentials.js index ea25138765..7b4f02cf72 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/credentials/userTokenCredentials.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/credentials/userTokenCredentials.js @@ -78,10 +78,10 @@ function UserTokenCredentials(clientId, domain, username, password, clientRedire */ UserTokenCredentials.prototype.signRequest = function (webResource, callback) { var self = this; - var authorityUrl = self.environment.authenticationEndpoint + self.domain; + var authorityUrl = self.environment.activeDirectoryEndpointUrl + self.domain; var context = new adal.AuthenticationContext(authorityUrl, self.environment.validateAuthority, self.tokenCache); - context.acquireTokenWithUsernamePassword(self.environment.tokenAudience, self.username, self.password, self.clientId, function (err, result) { + context.acquireTokenWithUsernamePassword(self.environment.activeDirectoryResourceId, self.username, self.password, self.clientId, function (err, result) { if (err) { return callback(new Error('Failed to acquire token. \n' + err)); } diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/index.d.ts b/ClientRuntimes/NodeJS/ms-rest-azure/lib/index.d.ts index 818d584985..ef4378cff4 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/index.d.ts +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/index.d.ts @@ -1,22 +1,22 @@ import * as msRest from 'ms-rest'; export interface AzureServiceClientOptions extends msRest.ServiceClientOptions { - // TODO: Make this property have right type - // * @param {Array} [options.longRunningOperationRetryTimeout] - Retry timeout - longRunningOperationRetryTimeout?: any; + // TODO: Make this property have right type + // * @param {Array} [options.longRunningOperationRetryTimeout] - Retry timeout + longRunningOperationRetryTimeout?: any; } export class AzureServiceClient extends msRest.ServiceClient { - /** - * @class - * Initializes a new instance of the AzureServiceClient class. - * @constructor - * @param {ServiceClientCredentials} credentials - ApplicationTokenCredentials or - * UserTokenCredentials object used for authentication. - * - * @param {object} options - The parameter options used by ServiceClient - * - * @param {string} [options.acceptLanguage] - Gets or sets the preferred language for the response. + /** + * @class + * Initializes a new instance of the AzureServiceClient class. + * @constructor + * @param {ServiceClientCredentials} credentials - ApplicationTokenCredentials or + * UserTokenCredentials object used for authentication. + * + * @param {object} options - The parameter options used by ServiceClient + * + * @param {string} [options.acceptLanguage] - Gets or sets the preferred language for the response. * Default value is: 'en-US'. * * @param {boolean} [options.generateClientRequestId] - When set to true a unique x-ms-client-request-id value @@ -24,81 +24,165 @@ export class AzureServiceClient extends msRest.ServiceClient { * * @param {number} [options.longRunningOperationRetryTimeout] - Gets or sets the retry timeout in seconds for * Long Running Operations. Default value is 30. - */ - constructor(credentials: msRest.ServiceClientCredentials, options: AzureServiceClientOptions) + */ + constructor(credentials: msRest.ServiceClientCredentials, options: AzureServiceClientOptions) } export class AzureEnvironment { - /** - * Initializes a new instance of the AzureEnvironment class. - * @param {string} authenticationEndpoint - ActiveDirectory Endpoint for the Azure Environment. - * @param {string} tokenAudience - Token audience for an endpoint. - * @param {bool} [validateAuthority] - Determines whether the authentication endpoint should - * be validated with Azure AD. Default value is true. - */ - constructor(authenticationEndpoint: string, tokenAudience: string, validateAuthority: boolean); - - /** - * ActiveDirectory Endpoint for the Azure Environment - */ - authenticationEndpoint: string; - - /** - * Token audience for an endpoint. - */ - tokenAudience: string; - - /** - * Determines whether the authentication endpoint should be validated with Azure AD. Default value is true. - */ - validateAuthority: boolean; + /** + * Initializes a new instance of the AzureEnvironment class. + * @param {string} parameters.name - The Environment name + * @param {string} parameters.portalUrl - The management portal URL + * @param {string} parameters.managementEndpointUrl - The management service endpoint + * @param {string} parameters.resourceManagerEndpointUrl - The resource management endpoint + * @param {string} parameters.activeDirectoryEndpointUrl - The Active Directory login endpoint + * @param {string} parameters.activeDirectoryResourceId - The resource ID to obtain AD tokens for (token audience) + * @param {string} [parameters.publishingProfileUrl] - The publish settings file URL + * @param {string} [parameters.sqlManagementEndpointUrl] - The sql server management endpoint for mobile commands + * @param {string} [parameters.sqlServerHostnameSuffix] - The dns suffix for sql servers + * @param {string} [parameters.galleryEndpointUrl] - The template gallery endpoint + * @param {string} [parameters.activeDirectoryGraphResourceId] - The Active Directory resource ID + * @param {string} [parameters.activeDirectoryGraphApiVersion] - The Active Directory api version + * @param {string} [parameters.storageEndpointSuffix] - The endpoint suffix for storage accounts + * @param {string} [parameters.keyVaultDnsSuffix] - The keyvault service dns suffix + * @param {string} [parameters.azureDataLakeStoreFileSystemEndpointSuffix] - The data lake store filesystem service dns suffix + * @param {string} [parameters.azureDataLakeAnalyticsCatalogAndJobEndpointSuffix] - The data lake analytics job and catalog service dns suffix + * @param {bool} [parameters.validateAuthority] - Determines whether the authentication endpoint should + * be validated with Azure AD. Default value is true. + */ + constructor(parameters: any); + + /** + * The Environment name. + */ + name: string; + + /** + * The management portal URL. + */ + portalUrl: string; + + /** + * The management service endpoint. + */ + managementEndpointUrl: string; + + /** + * The resource management endpoint. + */ + resourceManagerEndpointUrl: string; + + /** + * The Active Directory login endpoint. + */ + activeDirectoryEndpointUrl: string; + + /** + * The resource ID to obtain AD tokens for (token audience). + */ + activeDirectoryResourceId: string; + + /** + * The publish settings file URL. + */ + publishingProfileUrl: string; + + /** + * The sql server management endpoint for mobile commands. + */ + sqlManagementEndpointUrl: string; + + /** + * The dns suffix for sql servers. + */ + sqlServerHostnameSuffix: string; + + /** + * The template gallery endpoint. + */ + galleryEndpointUrl: string; + + /** + * The Active Directory resource ID. + */ + activeDirectoryGraphResourceId: string; + + /** + * The Active Directory api version. + */ + activeDirectoryGraphApiVersion: string; + + /** + * The endpoint suffix for storage accounts. + */ + storageEndpointSuffix: string; + + /** + * The keyvault service dns suffix. + */ + keyVaultDnsSuffix: string; + + /** + * The data lake store filesystem service dns suffix. + */ + azureDataLakeStoreFileSystemEndpointSuffix: string; + + /** + * The data lake analytics job and catalog service dns suffix. + */ + azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: string; + + /** + * Determines whether the authentication endpoint should be validated with Azure AD. Default value is true. + */ + validateAuthority: boolean; } export interface AzureTokenCredentialsOptions { - /** - * The Azure environment to authenticate with. - */ - environment?: AzureEnvironment; - - /** - * The authorization scheme. Default value is 'Bearer'. - */ - authorizationScheme?: string; - - // TODO: What type should this really have? How is it used? - /** - * The token cache. Default value is null. - */ - tokenCache?: any; + /** + * The Azure environment to authenticate with. + */ + environment?: AzureEnvironment; + + /** + * The authorization scheme. Default value is 'Bearer'. + */ + authorizationScheme?: string; + + // TODO: What type should this really have? How is it used? + /** + * The token cache. Default value is null. + */ + tokenCache?: any; } export class ApplicationTokenCredentials extends msRest.ServiceClientCredentials { - /** - * Creates a new ApplicationTokenCredentials object. - * See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net} - * for detailed instructions on creating an Azure Active Directory application. - * @param {string} clientId The active directory application client id. - * @param {string} domain The domain or tenant id containing this application. - * @param {string} secret The authentication secret for the application. - * @param {AzureTokenCredentialsOptions} options Object representing optional parameters. - */ - constructor(clientId: string, domain: string, secret: string, options?: AzureTokenCredentialsOptions); + /** + * Creates a new ApplicationTokenCredentials object. + * See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net} + * for detailed instructions on creating an Azure Active Directory application. + * @param {string} clientId The active directory application client id. + * @param {string} domain The domain or tenant id containing this application. + * @param {string} secret The authentication secret for the application. + * @param {AzureTokenCredentialsOptions} options Object representing optional parameters. + */ + constructor(clientId: string, domain: string, secret: string, options?: AzureTokenCredentialsOptions); } export class UserTokenCredentials extends msRest.ServiceClientCredentials { - /** - * Creates a new UserTokenCredentials object. - * See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net} - * for an example. - * @param {string} clientId The active directory application client id. - * @param {string} domain The domain or tenant id containing this application. - * @param {string} username The user name for the Organization Id account. - * @param {string} password The password for the Organization Id account. - * @param {string} clientRedirectUri The Uri where the user will be redirected after authenticating with AD. - * @param {AzureTokenCredentialsOptions} options Object representing optional parameters. - */ - constructor(clientId: string, domain: string, username: string, password: string, clientRedirectUri: string, options?: AzureTokenCredentialsOptions); + /** + * Creates a new UserTokenCredentials object. + * See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net} + * for an example. + * @param {string} clientId The active directory application client id. + * @param {string} domain The domain or tenant id containing this application. + * @param {string} username The user name for the Organization Id account. + * @param {string} password The password for the Organization Id account. + * @param {string} clientRedirectUri The Uri where the user will be redirected after authenticating with AD. + * @param {AzureTokenCredentialsOptions} options Object representing optional parameters. + */ + constructor(clientId: string, domain: string, username: string, password: string, clientRedirectUri: string, options?: AzureTokenCredentialsOptions); } // TODO: WHAT SHOULD WE EXPOSE HERE? diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/package.json b/ClientRuntimes/NodeJS/ms-rest-azure/package.json index 0cb2731447..9ca0985902 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/package.json +++ b/ClientRuntimes/NodeJS/ms-rest-azure/package.json @@ -24,7 +24,6 @@ "uuid": "2.0.1", "adal-node": "0.1.17", "ms-rest": "^1.12.0", - "underscore": "^1.4.0", "moment": "^2.6.0" }, "devDependencies": { diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureEnvironmentTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureEnvironmentTests.js new file mode 100644 index 0000000000..01b6fbfd81 --- /dev/null +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureEnvironmentTests.js @@ -0,0 +1,91 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +var should = require('should'); +var msRestAzure = require('../lib/msRestAzure'); + +describe('AzureEnvironment', function() { + it('can be properly required', function(done) { + var tempEnv = msRestAzure.AzureEnvironment; + tempEnv.validateAuthority.should.equal(true); + done(); + }); + + it('should show the details of Azure Production environment correctly', function(done) { + var tempEnv = msRestAzure.AzureEnvironment.Azure; + tempEnv.name.should.equal('Azure'); + tempEnv.activeDirectoryEndpointUrl.should.equal('https://login.microsoftonline.com'); + tempEnv.activeDirectoryResourceId.should.equal('https://management.core.windows.net/'); + tempEnv.managementEndpointUrl.should.equal('https://management.core.windows.net'); + tempEnv.resourceManagerEndpointUrl.should.equal('https://management.azure.com/'); + tempEnv.portalUrl.should.equal('http://go.microsoft.com/fwlink/?LinkId=254433'); + tempEnv.validateAuthority.should.equal(true); + done(); + }); + + it('should show the details of Azure China environment correctly', function(done) { + var tempEnv = msRestAzure.AzureEnvironment.AzureChina; + tempEnv.name.should.equal('AzureChina'); + tempEnv.activeDirectoryEndpointUrl.should.equal('https://login.chinacloudapi.cn'); + tempEnv.activeDirectoryResourceId.should.equal('https://management.core.chinacloudapi.cn/'); + tempEnv.managementEndpointUrl.should.equal('https://management.core.chinacloudapi.cn'); + tempEnv.resourceManagerEndpointUrl.should.equal('https://management.chinacloudapi.cn'); + tempEnv.portalUrl.should.equal('http://go.microsoft.com/fwlink/?LinkId=301902'); + tempEnv.validateAuthority.should.equal(true); + done(); + }); + + it('should show the details of Azure USGovernment environment correctly', function(done) { + var tempEnv = msRestAzure.AzureEnvironment.AzureUSGovernment; + tempEnv.name.should.equal('AzureUSGovernment'); + tempEnv.activeDirectoryEndpointUrl.should.equal('https://login.microsoftonline.com'); + tempEnv.activeDirectoryResourceId.should.equal('https://management.core.usgovcloudapi.net/'); + tempEnv.managementEndpointUrl.should.equal('https://management.core.usgovcloudapi.net'); + tempEnv.resourceManagerEndpointUrl.should.equal('https://management.usgovcloudapi.net'); + tempEnv.portalUrl.should.equal('https://manage.windowsazure.us'); + tempEnv.validateAuthority.should.equal(true); + done(); + }); + + it('should show the details of Azure GermanCloud environment correctly', function(done) { + var tempEnv = msRestAzure.AzureEnvironment.AzureGermanCloud; + tempEnv.name.should.equal('AzureGermanCloud'); + tempEnv.activeDirectoryEndpointUrl.should.equal('https://login.microsoftonline.de'); + tempEnv.activeDirectoryResourceId.should.equal('https://management.core.cloudapi.de/'); + tempEnv.managementEndpointUrl.should.equal('https://management.core.cloudapi.de'); + tempEnv.resourceManagerEndpointUrl.should.equal('https://management.microsoftazure.de'); + tempEnv.portalUrl.should.equal('http://portal.microsoftazure.de/'); + tempEnv.validateAuthority.should.equal(true); + done(); + }); + + it('should be able to add a new environment', function(done) { + var df = { + name: 'Dogfood', + portalUrl: 'http://go.microsoft.com/fwlink/?LinkId=254433', + managementEndpointUrl: 'https://management.core.windows.net', + resourceManagerEndpointUrl: 'https://management.azure.com/', + activeDirectoryEndpointUrl: 'https://login.microsoftonline.com', + activeDirectoryResourceId: 'https://management.core.windows.net/' + }; + var tempEnv = msRestAzure.AzureEnvironment; + var dfood = tempEnv.add(df); + dfood.name.should.equal('Dogfood'); + dfood.activeDirectoryEndpointUrl.should.equal('https://login.microsoftonline.com'); + dfood.activeDirectoryResourceId.should.equal('https://management.core.windows.net/'); + dfood.managementEndpointUrl.should.equal('https://management.core.windows.net'); + dfood.resourceManagerEndpointUrl.should.equal('https://management.azure.com/'); + dfood.portalUrl.should.equal('http://go.microsoft.com/fwlink/?LinkId=254433'); + dfood.validateAuthority.should.equal(true); + + //Verify that the environment properly got added to the prototype + tempEnv.Dogfood.name.should.equal('Dogfood'); + tempEnv.Dogfood.activeDirectoryEndpointUrl.should.equal('https://login.microsoftonline.com'); + tempEnv.Dogfood.activeDirectoryResourceId.should.equal('https://management.core.windows.net/'); + tempEnv.Dogfood.managementEndpointUrl.should.equal('https://management.core.windows.net'); + tempEnv.Dogfood.resourceManagerEndpointUrl.should.equal('https://management.azure.com/'); + tempEnv.Dogfood.portalUrl.should.equal('http://go.microsoft.com/fwlink/?LinkId=254433'); + tempEnv.Dogfood.validateAuthority.should.equal(true); + done(); + }); +}); \ No newline at end of file diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/package.json b/ClientRuntimes/NodeJS/ms-rest-azure/test/package.json index a4970d007d..248a41a885 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/package.json +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/package.json @@ -31,8 +31,7 @@ "xunit-file": "0.0.5", "mocha": "2.2.5", "should": "5.2.0", - "moment": "*", - "underscore": "*" + "moment": "*" }, "homepage": "https://github.com/Azure/AutoRest", "repository": { diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/testlist.txt b/ClientRuntimes/NodeJS/ms-rest-azure/test/testlist.txt index 6118755921..83a9769333 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/testlist.txt +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/testlist.txt @@ -1 +1,2 @@ -azureServiceClientTests.js \ No newline at end of file +azureServiceClientTests.js +azureEnvironmentTests.js \ No newline at end of file