Skip to content
This repository
Browse code

Adding more UT

  • Loading branch information...
commit fc16eff0f77d5c73353d147d5742a7073ee5f01e 1 parent c43007a
André Rodrigues authored
1  lib/azure.js
@@ -152,6 +152,7 @@ exports.Logger = require('./diagnostics/logger');
152 152
 exports.ConnectionStringParser = require('./services/core/connectionstringparser');
153 153
 exports.ServiceSettings = require('./services/core/servicesettings');
154 154
 exports.StorageServiceSettings = require('./services/core/storageservicesettings');
  155
+exports.ServiceBusSettings = require('./services/core/servicebussettings');
155 156
 exports.Validate = require('./util/validate');
156 157
 
157 158
 /*
20  lib/services/core/servicebussettings.js
@@ -45,8 +45,8 @@ var validKeys = [
45 45
 */
46 46
 function ServiceBusSettings(serviceBusEndpointUri, namespace, wrapName, wrapPassword) {
47 47
   this._namespace = namespace;
48  
-  this._serviceBusEndpointUri = serviceBusEndpoint;
49  
-  this._wrapEndpointUri = 'https://' + namespace + '.accesscontrol.windows.net/WRAPv0.9';
  48
+  this._serviceBusEndpointUri = serviceBusEndpointUri;
  49
+  this._wrapEndpointUri = 'https://' + namespace + '-sb.accesscontrol.windows.net/WRAPv0.9';
50 50
   this._wrapName = wrapName;
51 51
   this._wrapPassword = wrapPassword;
52 52
 }
@@ -59,7 +59,7 @@ function ServiceBusSettings(serviceBusEndpointUri, namespace, wrapName, wrapPass
59 59
 * @return {ServiceBusSettings}
60 60
 */
61 61
 ServiceBusSettings.createFromConnectionString = function (connectionString) {
62  
-  var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString);
  62
+  var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
63 63
 
64 64
   var matchedSpecs = ServiceSettings.matchedSpecification(
65 65
     tokenizedSettings,
@@ -71,23 +71,21 @@ ServiceBusSettings.createFromConnectionString = function (connectionString) {
71 71
   );
72 72
 
73 73
   if (matchedSpecs) {
74  
-    endpoint = util.tryGetValueInsensitive(
  74
+    var endpoint = util.tryGetValueInsensitive(
75 75
       ConnectionStringKeys.SERVICE_BUS_ENDPOINT_NAME,
76 76
       tokenizedSettings
77 77
     );
78 78
       
79 79
     // Parse the namespace part from the URI
80  
-
81  
-    // TODO: to be implemented
82  
-    // var namespace   = explode('.', parse_url(endpoint, PHP_URL_HOST));
83  
-    var namespace   = namespace[0];
  80
+    var parsedUrl = url.parse(endpoint);
  81
+    var namespace = parsedUrl.host.split('.')[0];
84 82
 
85 83
     var issuerName  = util.tryGetValueInsensitive(
86 84
         ConnectionStringKeys.SHARED_SECRET_ISSUER_NAME,
87 85
         tokenizedSettings
88 86
     );
89 87
 
90  
-    var issuerValue = Utilities::tryGetValueInsensitive(
  88
+    var issuerValue = util.tryGetValueInsensitive(
91 89
         ConnectionStringKeys.SHARED_SECRET_VALUE_NAME,
92 90
         tokenizedSettings
93 91
     );
@@ -101,6 +99,4 @@ ServiceBusSettings.createFromConnectionString = function (connectionString) {
101 99
   }
102 100
 
103 101
   ServiceSettings.noMatch(connectionString);
104  
-}
105  
-
106  
-
  102
+};
71  test/services/core/servicebussettings-tests.js
@@ -13,3 +13,74 @@
13 13
 * limitations under the License.
14 14
 */
15 15
 
  16
+var should = require('should');
  17
+var url = require('url');
  18
+
  19
+var testutil = require('../../util/util');
  20
+var azure = testutil.libRequire('azure');
  21
+var Constants = azure.Constants;
  22
+var ConnectionStringKeys = Constants.ConnectionStringKeys;
  23
+var ServiceBusSettings = azure.ServiceBusSettings;
  24
+
  25
+suite('storageservicesettings-tests', function () {
  26
+  test('testCreateFromConnectionStringWithServiceBusAutomaticCase', function () {
  27
+    // Setup
  28
+    var expectedNamespace = 'mynamespace';
  29
+    var expectedServiceBusEndpoint = 'https://' + expectedNamespace + '.servicebus.windows.net';
  30
+    var expectedWrapName = 'myname';
  31
+    var expectedWrapPassword = 'mypassword';
  32
+    var expectedWrapEndpointUri = 'https://' + expectedNamespace + '-sb.accesscontrol.windows.net/WRAPv0.9';
  33
+    var connectionString = 'Endpoint=' + expectedServiceBusEndpoint + ';SharedSecretIssuer=' + expectedWrapName + ';SharedSecretValue=' + expectedWrapPassword;
  34
+
  35
+    // Test
  36
+    var actual = ServiceBusSettings.createFromConnectionString(connectionString);
  37
+
  38
+    // Assert
  39
+    actual._namespace.should.equal(expectedNamespace);
  40
+    actual._serviceBusEndpointUri.should.equal(expectedServiceBusEndpoint);
  41
+    actual._wrapName.should.equal(expectedWrapName);
  42
+    actual._wrapPassword.should.equal(expectedWrapPassword);
  43
+    actual._wrapEndpointUri.should.equal(expectedWrapEndpointUri);
  44
+  });
  45
+
  46
+  test('testCreateFromConnectionStringWithMissingServiceBusEndpointFail', function () {
  47
+    // Setup
  48
+    var connectionString = 'SharedSecretIssuer=name;SharedSecretValue=password';
  49
+
  50
+    // Test
  51
+    (function() {
  52
+      ServiceBusSettings.createFromConnectionString(connectionString);
  53
+    }).should.throw('The provided connection string ' + connectionString + ' does not have complete configuration settings.');
  54
+  });
  55
+
  56
+  test('testCreateFromConnectionStringWithInvalidServiceBusKeyFail', function () {
  57
+    // Setup
  58
+    var invalidKey = 'InvalidKey';
  59
+    var connectionString = invalidKey + '=value;SharedSecretIssuer=name;SharedSecretValue=password';
  60
+
  61
+    // Test
  62
+    (function() {
  63
+      ServiceBusSettings.createFromConnectionString(connectionString);
  64
+    }).should.throw('Invalid connection string setting key ' + invalidKey.toLowerCase());
  65
+  });
  66
+
  67
+  test('testCreateFromConnectionStringWithCaseInvesitive', function () {
  68
+    // Setup
  69
+    var expectedNamespace = 'mynamespace';
  70
+    var expectedServiceBusEndpoint = 'https://' + expectedNamespace + '.servicebus.windows.net';
  71
+    var expectedWrapName = 'myname';
  72
+    var expectedWrapPassword = 'mypassword';
  73
+    var expectedWrapEndpointUri = 'https://' + expectedNamespace + '-sb.accesscontrol.windows.net/WRAPv0.9';
  74
+    var connectionString = 'eNdPoinT=' + expectedServiceBusEndpoint + ';sHarEdsecRetiSsuer=' + expectedWrapName + ';shArEdsecrEtvAluE=' + expectedWrapPassword;
  75
+        
  76
+    // Test
  77
+    var actual = ServiceBusSettings.createFromConnectionString(connectionString);
  78
+
  79
+    // Assert
  80
+    actual._namespace.should.equal(expectedNamespace);
  81
+    actual._serviceBusEndpointUri.should.equal(expectedServiceBusEndpoint);
  82
+    actual._wrapName.should.equal(expectedWrapName);
  83
+    actual._wrapPassword.should.equal(expectedWrapPassword);
  84
+    actual._wrapEndpointUri.should.equal(expectedWrapEndpointUri);
  85
+  });
  86
+});
1  test/testlist.txt
@@ -12,6 +12,7 @@ services/core/serviceclient-tests.js
12 12
 services/core/exponentialretrypolicyfilter-tests.js
13 13
 services/core/linearretrypolicyfilter-tests.js
14 14
 services/core/servicesettings-tests.js
  15
+services/core/servicebussettings-tests.js
15 16
 services/core/storageservicesettings-tests.js
16 17
 services/queue/queueservice-tests.js
17 18
 services/table/batchserviceclient-tests.js

0 notes on commit fc16eff

Please sign in to comment.
Something went wrong with that request. Please try again.