Permalink
Browse files

Removing nested functions from validate.

  • Loading branch information...
1 parent d55beab commit 7b38833701411cda846f98a332cc93ef7aebc2d3 Andre Rodrigues committed Oct 13, 2012
View
4 lib/services/core/servicebussettings.js
@@ -25,8 +25,8 @@ var Validate = require('../../util/validate');
exports = module.exports = ServiceBusSettings;
-var serviceBusEndpointSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME, Validate.getIsValidUri());
-var wrapEndpointSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.WRAP_ENDPOINT_NAME, Validate.getIsValidUri());
+var serviceBusEndpointSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME, Validate.isValidUri);
+var wrapEndpointSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.WRAP_ENDPOINT_NAME, Validate.isValidUri);
var wrapNameSetting = ServiceSettings.setting(ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME);
var wrapPasswordSetting = ServiceSettings.setting(ConnectionStringKeys.SHARED_SECRET_VALUE_NAME);
View
2 lib/services/core/servicemanagementsettings.js
@@ -27,7 +27,7 @@ exports = module.exports = ServiceManagementSettings;
var endpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME,
- Validate.getIsValidUri()
+ Validate.isValidUri
);
var certificatePathSetting = ServiceSettings.setting(ConnectionStringKeys.CERTIFICATE_PATH_NAME);
View
4 lib/services/core/storageservicesettings.js
@@ -27,10 +27,10 @@ exports = module.exports = StorageServiceSettings;
var devStoreAccount = null;
var useDevelopmentStorageSetting = ServiceSettings.setting(ConnectionStringKeys.USE_DEVELOPMENT_STORAGE_NAME, true);
-var developmentStorageProxyUriSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.DEVELOPMENT_STORAGE_PROXY_URI_NAME, Validate.getIsValidUri());
+var developmentStorageProxyUriSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.DEVELOPMENT_STORAGE_PROXY_URI_NAME, Validate.isValidUri;
var defaultEndpointsProtocolSetting = ServiceSettings.setting(ConnectionStringKeys.DEFAULT_ENDPOINTS_PROTOCOL_NAME, 'http', 'https');
var accountNameSetting = ServiceSettings.setting(ConnectionStringKeys.ACCOUNT_NAME_NAME);
-var accountKeySetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.ACCOUNT_KEY_NAME, Validate.getIsBase64Encoded());
+var accountKeySetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.ACCOUNT_KEY_NAME, Validate.isBase64Encoded);
var blobEndpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.BLOB_ENDPOINT_NAME,
View
34 lib/util/validate.js
@@ -22,31 +22,27 @@ exports = module.exports;
*
* @return {function}
*/
-exports.getIsValidUri = function () {
- return function (uri) {
- try {
- // Check will throw if it is not valid.
- check(uri).isUrl();
- return true;
- } catch (e) {
- throw new Error('The provided URI "' + uri + '" is invalid.');
- }
- };
+exports.isValidUri = function (uri) {
+ try {
+ // Check will throw if it is not valid.
+ check(uri).isUrl();
+ return true;
+ } catch (e) {
+ throw new Error('The provided URI "' + uri + '" is invalid.');
+ }
};
/**
* Creates a anonymous function that check if a given key is base 64 encoded.
*
* @return {function}
*/
-exports.getIsBase64Encoded = function () {
- return function (key) {
- var isValidBase64String = key.match('^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$');
+exports.isBase64Encoded = function () {
+ var isValidBase64String = key.match('^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$');
- if (isValidBase64String) {
- return true;
- } else {
- throw new Error('The provided account key ' + key + ' is not a valid base64 string.');
- }
- };
+ if (isValidBase64String) {
+ return true;
+ } else {
+ throw new Error('The provided account key ' + key + ' is not a valid base64 string.');
+ }
};
View
16 test/util/validate-tests.js
@@ -20,25 +20,21 @@ var azure = testutil.libRequire('azure');
var Validate = azure.Validate;
suite('servicesettings-tests', function () {
- test('getIsValidUri', function () {
- var validUri = Validate.getIsValidUri();
-
- validUri('http://www.microsoft.com').should.be.ok;
- validUri('http://www.microsoft.com').should.equal(true);
+ test('isValidUri', function () {
+ Validate.isValidUri('http://www.microsoft.com').should.be.ok;
+ Validate.isValidUri('http://www.microsoft.com').should.equal(true);
(function() {
- validUri('something');
+ Validate.getIsValidUri()('something');
}).should.throw('The provided URI "something" is invalid.');
});
test('getIsBase64Encoded', function () {
- var validBase64 = Validate.getIsBase64Encoded();
-
- validBase64('AhlzsbLRkjfwObuqff3xrhB2yWJNh1EMptmcmxFJ6fvPTVX3PZXwrG2YtYWf5DPMVgNsteKStM5iBLlknYFVoA==').should.be.ok;
+ Validate.isBase64Encoded('AhlzsbLRkjfwObuqff3xrhB2yWJNh1EMptmcmxFJ6fvPTVX3PZXwrG2YtYWf5DPMVgNsteKStM5iBLlknYFVoA==').should.be.ok;
var key = '__A&*INVALID-@Key';
(function() {
- validBase64(key);
+ Validate.isBase64Encoded(key);
}).should.throw('The provided account key ' + key + ' is not a valid base64 string.');
});
});

0 comments on commit 7b38833

Please sign in to comment.