Permalink
Browse files

#469: Making access conditions case insensitive.

  • Loading branch information...
1 parent 49da5aa commit 942bf2758ff6e8289567102e14f0a9c694b2b29c Andre Rodrigues committed Nov 14, 2012
Showing with 95 additions and 22 deletions.
  1. +3 −6 examples/samples/blobuploaddownloadsample.js
  2. +24 −16 lib/http/webresource.js
  3. +67 −0 test/http/webresource-tests.js
  4. +1 −0 test/testlist.txt
@@ -53,8 +53,7 @@ function createContainer() {
blobService.createContainerIfNotExists(container, function (error) {
if (error) {
console.log(error);
- }
- else {
+ } else {
console.log('Created the container ' + container);
uploadSample();
}
@@ -203,8 +202,7 @@ function testAccess(containerName, blobName, etag) {
if (processArguments.length > 5 || processArguments.length < 4) {
console.log('Incorrect number of arguments');
-}
-else if (processArguments.length == 5) {
+} else if (processArguments.length == 5) {
// Adding a third argument on the command line, whatever it is, will delete the container before running the sample.
blobService.deleteContainer(container, function (error) {
if (error) {
@@ -213,8 +211,7 @@ else if (processArguments.length == 5) {
createContainer();
}
});
-}
-else {
+} else {
createContainer();
}
View
@@ -287,40 +287,48 @@ WebResource.prototype.addOptionalMetadataHeaders = function (metadata) {
WebResource.prototype.addOptionalAccessConditionHeader = function (accessConditionHeaders) {
if (accessConditionHeaders) {
- if (accessConditionHeaders[HeaderConstants.IF_MATCH]) {
- this.addOptionalHeader(HeaderConstants.IF_MATCH, accessConditionHeaders[HeaderConstants.IF_MATCH]);
+ var ifMatch = azureutil.tryGetValueInsensitive(HeaderConstants.IF_MATCH, accessConditionHeaders);
+ if (ifMatch) {
+ this.addOptionalHeader(HeaderConstants.IF_MATCH, ifMatch);
}
- if (accessConditionHeaders[HeaderConstants.IF_MODIFIED_SINCE]) {
- this.addOptionalHeader(HeaderConstants.IF_MODIFIED_SINCE, accessConditionHeaders[HeaderConstants.IF_MODIFIED_SINCE]);
+ var ifModifiedSince = azureutil.tryGetValueInsensitive(HeaderConstants.IF_MODIFIED_SINCE, accessConditionHeaders);
+ if (ifModifiedSince) {
+ this.addOptionalHeader(HeaderConstants.IF_MODIFIED_SINCE, ifModifiedSince);
}
- if (accessConditionHeaders[HeaderConstants.IF_NONE_MATCH]) {
- this.addOptionalHeader(HeaderConstants.IF_NONE_MATCH, accessConditionHeaders[HeaderConstants.IF_NONE_MATCH]);
+ var ifNoneMatch = azureutil.tryGetValueInsensitive(HeaderConstants.IF_NONE_MATCH, accessConditionHeaders);
+ if (ifNoneMatch) {
+ this.addOptionalHeader(HeaderConstants.IF_NONE_MATCH, ifNoneMatch);
}
- if (accessConditionHeaders[HeaderConstants.IF_UNMODIFIED_SINCE]) {
- this.addOptionalHeader(HeaderConstants.IF_UNMODIFIED_SINCE, accessConditionHeaders[HeaderConstants.IF_UNMODIFIED_SINCE]);
+ var ifUnmodifiedSince = azureutil.tryGetValueInsensitive(HeaderConstants.IF_UNMODIFIED_SINCE, accessConditionHeaders);
+ if (ifUnmodifiedSince) {
+ this.addOptionalHeader(HeaderConstants.IF_UNMODIFIED_SINCE, ifUnmodifiedSince);
}
}
};
WebResource.prototype.addOptionalSourceAccessConditionHeader = function (accessConditionHeaders) {
if (accessConditionHeaders) {
- if (accessConditionHeaders[HeaderConstants.SOURCE_IF_MATCH_HEADER]) {
- this.addOptionalHeader(HeaderConstants.SOURCE_IF_MATCH_HEADER, accessConditionHeaders[HeaderConstants.SOURCE_IF_MATCH_HEADER]);
+ var sourceIfMatch = azureutil.tryGetValueInsensitive(HeaderConstants.SOURCE_IF_MATCH_HEADER, accessConditionHeaders);
+ if (sourceIfMatch) {
+ this.addOptionalHeader(HeaderConstants.SOURCE_IF_MATCH_HEADER, sourceIfMatch);
}
- if (accessConditionHeaders[HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER]) {
- this.addOptionalHeader(HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER, accessConditionHeaders[HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER]);
+ var sourceIfModifiedSince = azureutil.tryGetValueInsensitive(HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER, accessConditionHeaders);
+ if (sourceIfModifiedSince) {
+ this.addOptionalHeader(HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER, sourceIfModifiedSince);
}
- if (accessConditionHeaders[HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER]) {
- this.addOptionalHeader(HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER, accessConditionHeaders[HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER]);
+ var sourceIfNoneMatch = azureutil.tryGetValueInsensitive(HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER, accessConditionHeaders);
+ if (sourceIfNoneMatch) {
+ this.addOptionalHeader(HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER, sourceIfNoneMatch);
}
- if (accessConditionHeaders[HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER]) {
- this.addOptionalHeader(HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER, accessConditionHeaders[HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER]);
+ var sourceIfUnmodifiedSince = azureutil.tryGetValueInsensitive(HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER, accessConditionHeaders);
+ if (sourceIfUnmodifiedSince) {
+ this.addOptionalHeader(HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER, sourceIfUnmodifiedSince);
}
}
};
@@ -0,0 +1,67 @@
+/**
+* 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 testutil = require('../util/util');
+var WebResource = require('../../lib/http/webresource');
+var azure = testutil.libRequire('azure');
+var Constants = azure.Constants;
+var HeaderConstants = Constants.HeaderConstants;
+
+suite('webresource-tests', function () {
+ test('addOptionalAccessConditionHeader', function () {
+ var ifMatch = 'ifmatch';
+ var ifModifiedSince = 'ifModifiedSince';
+ var ifNoneMatch = 'ifNoneMatch';
+ var ifUnmodifiedSince = 'ifUnmodifiedSince';
+
+ var accessConditions = {
+ 'If-Match': ifMatch,
+ 'If-Modified-Since': ifModifiedSince,
+ 'If-None-Match': ifNoneMatch,
+ 'If-Unmodified-Since': ifUnmodifiedSince
+ };
+
+ var webResource = new WebResource();
+ webResource.addOptionalAccessConditionHeader(accessConditions);
+
+ webResource.headers[HeaderConstants.IF_MATCH].should.equal(ifMatch);
+ webResource.headers[HeaderConstants.IF_MODIFIED_SINCE].should.equal(ifModifiedSince);
+ webResource.headers[HeaderConstants.IF_NONE_MATCH].should.equal(ifNoneMatch);
+ webResource.headers[HeaderConstants.IF_UNMODIFIED_SINCE].should.equal(ifUnmodifiedSince);
+ });
+
+ test('addOptionalSourceAccessConditionHeader', function () {
+ var sourceIfMatch = 'sourceIfmatch';
+ var sourceIfModifiedSince = 'sourceIfModifiedSince';
+ var sourceIfNoneMatch = 'sourceIfNoneMatch';
+ var sourceIfUnmodifiedSince = 'sourceIfUnmodifiedSince';
+
+ var accessConditions = {
+ 'x-ms-source-If-Match': sourceIfMatch,
+ 'x-ms-source-If-Modified-Since': sourceIfModifiedSince,
+ 'x-ms-source-If-None-Match': sourceIfNoneMatch,
+ 'x-ms-source-If-Unmodified-Since': sourceIfUnmodifiedSince
+ };
+
+ var webResource = new WebResource();
+ webResource.addOptionalSourceAccessConditionHeader(accessConditions);
+
+ webResource.headers[HeaderConstants.SOURCE_IF_MATCH_HEADER].should.equal(sourceIfMatch);
+ webResource.headers[HeaderConstants.SOURCE_IF_MODIFIED_SINCE_HEADER].should.equal(sourceIfModifiedSince);
+ webResource.headers[HeaderConstants.SOURCE_IF_NONE_MATCH_HEADER].should.equal(sourceIfNoneMatch);
+ webResource.headers[HeaderConstants.SOURCE_IF_UNMODIFIED_SINCE_HEADER].should.equal(sourceIfUnmodifiedSince);
+ });
+});
View
@@ -1,6 +1,7 @@
serviceruntime/roleenvironment-tests.js
serviceruntime/runtimeversionmanager-tests.js
serviceruntime/runtimeversionprotocolclient-tests.js
+http/webresource-tests.js
services/blob/blobservice-tests.js
services/blob/sharedaccesssignature-tests.js
services/blob/sharedkey-tests.js

0 comments on commit 942bf27

Please sign in to comment.