Permalink
Browse files

Fixing UT

  • Loading branch information...
1 parent 08b45d4 commit 501720b5221b953ee62f755e45754ac08d7609e9 @andrerod andrerod committed Oct 12, 2012
Showing with 24 additions and 14 deletions.
  1. +1 −11 lib/services/core/storageservicesettings.js
  2. +21 −2 lib/util/validate.js
  3. +2 −1 package.json
View
12 lib/services/core/storageservicesettings.js
@@ -30,17 +30,7 @@ var _useDevelopmentStorageSetting = ServiceSettings.setting(ConnectionStringKeys
var _developmentStorageProxyUriSetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.DEVELOPMENT_STORAGE_PROXY_URI_NAME, Validate.getIsValidUri());
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,
- // base64_decode will return false if the $key is not in base64 format.
- function (key) {
- isValidBase64String = new Buffer(key, 'base64').toString('ascii');
- if (isValidBase64String) {
- return true;
- } else {
- throw new Error('The provided account key ' + key + ' is not a valid base64 string.');
- }
- });
+var _accountKeySetting = ServiceSettings.settingWithFunc(ConnectionStringKeys.ACCOUNT_KEY_NAME, Validate.getIsBase64Encoded());
var _blobEndpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.BLOB_ENDPOINT_NAME,
View
23 lib/util/validate.js
@@ -13,6 +13,8 @@
* limitations under the License.
*/
+var check = require('validator').check;
+
exports = module.exports;
/**
@@ -22,12 +24,29 @@ exports = module.exports;
*/
exports.getIsValidUri = function () {
return function (uri) {
- var isValid = uri.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
-
+ var isValid = check(uri).isUrl();
+
if (isValid) {
return true;
} else {
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 = new Buffer(key, 'base64').toString('ascii');
+
+ if (isValidBase64String) {
+ return true;
+ } else {
+ throw new Error('The provided account key ' + key + ' is not a valid base64 string.');
+ }
+ };
};
View
3 package.json
@@ -27,7 +27,8 @@
"colors": "0.x.x",
"eyes": "0.x.x",
"easy-table": "0.0.1",
- "request": ">= 2.9.203"
+ "request": ">= 2.9.203",
+ "validator": ">= 0.4.12"
},
"devDependencies": {
"mocha": "*",

0 comments on commit 501720b

Please sign in to comment.