Permalink
Browse files

#470: Fix issue with ACL policy dates - milliseconds padding.

  • Loading branch information...
1 parent 942bf27 commit 76ec049a459a6df39873f16bb37fa668d81f26af Andre Rodrigues committed Nov 14, 2012
@@ -22,6 +22,8 @@ var ISO8061Date = require('../../../util/iso8061date');
// Expose 'ContainerAclResult'.
exports = module.exports = ContainerAclResult;
+var ACL_MILLISECONDS_PADING = 7;
+
function ContainerAclResult(signedIdentifiers) {
if (signedIdentifiers) {
this.signedIdentifiers = signedIdentifiers;
@@ -51,7 +53,7 @@ ContainerAclResult.serialize = function (signedIdentifiersJs) {
var startIsoString = signedIdentifier.AccessPolicy.Start;
if (startIsoString instanceof Date) {
// Convert to expected ISO 8061 date format
- startIsoString = ISO8061Date.format(startIsoString);
+ startIsoString = ISO8061Date.format(startIsoString, ACL_MILLISECONDS_PADING);
}
doc = doc
@@ -64,7 +66,7 @@ ContainerAclResult.serialize = function (signedIdentifiersJs) {
var expiryIsoString = signedIdentifier.AccessPolicy.Expiry;
if (expiryIsoString instanceof Date) {
// Convert to expected ISO 8061 date format
- expiryIsoString = ISO8061Date.format(expiryIsoString);
+ expiryIsoString = ISO8061Date.format(expiryIsoString, ACL_MILLISECONDS_PADING);
}
doc = doc
View
@@ -16,11 +16,12 @@
/**
* Formats a date into an iso 8061 string.
*
-* @param {date} date The date to format.
-* @param {bool} skipMilliseconds Boolean value indicating if the miliseconds part of the date should not be included.
+* @param {date} date The date to format.
+* @param {bool} skipMilliseconds Boolean value indicating if the miliseconds part of the date should not be included.
+* @param {integer} millisecondsPading Number of digits to left pad the miliseconds.
* @return {string} The date formated in the ISO 8061 date format.
*/
-exports.format = function (date, skipMilliseconds) {
+exports.format = function (date, skipMilliseconds, millisecondsPading) {
var components = [
date.getUTCFullYear(),
'-',
@@ -37,7 +38,11 @@ exports.format = function (date, skipMilliseconds) {
if (!skipMilliseconds) {
components.push('.');
- components.push(leftPadThree(date.getUTCMilliseconds()));
+ if (!millisecondsPading) {
+ millisecondsPading = 3;
+ }
+
+ components.push(leftPad(date.getUTCMilliseconds(), millisecondsPading));
}
components.push('Z');
@@ -77,9 +82,9 @@ var leftPadTwo = function (n) {
return (n < 10 ? '0' : '') + n;
};
-var leftPadThree = function (n) {
+var leftPad = function (n, millisecondsPading) {
var currentN = '' + n;
- while (currentN.length < 3) {
+ while (currentN.length < millisecondsPading) {
currentN = '0' + currentN;
}
@@ -420,6 +420,74 @@ suite('blobservice-tests', function () {
});
});
+ test('SetContainerAclWithPolicies', function (done) {
+ var containerName = testutil.generateId(containerNamesPrefix, containerNames, blobtestutil.isMocked);
+
+ var readWriteStartDate = new Date();
+ var readWriteExpiryDate = new Date(readWriteStartDate);
+ readWriteExpiryDate.setMinutes(readWriteStartDate.getMinutes() + 10);
+
+ var readWriteSharedAccessPolicy = {
+ Id: 'readwrite',
+ AccessPolicy: {
+ Start: readWriteStartDate,
+ Expiry: readWriteExpiryDate,
+ Permissions: 'rw'
+ }
+ };
+
+ var readSharedAccessPolicy = {
+ Id: 'read',
+ AccessPolicy: {
+ Expiry: readWriteStartDate,
+ Permissions: 'r'
+ }
+ };
+
+ var options = {};
+ options.signedIdentifiers = [readWriteSharedAccessPolicy, readSharedAccessPolicy];
+
+ blobService.createContainer(containerName, function (createError, container1, createContainerResponse) {
+ assert.equal(createError, null);
+ assert.notEqual(container1, null);
+ assert.ok(createContainerResponse.isSuccessful);
+
+ blobService.setContainerAcl(containerName, BlobConstants.BlobContainerPublicAccessType.BLOB, options, function (setAclError, setAclContainer1, setResponse1) {
+ assert.equal(setAclError, null);
+ assert.notEqual(setAclContainer1, null);
+ assert.ok(setResponse1.isSuccessful);
+
+ blobService.getContainerAcl(containerName, function (getAclError, getAclContainer1, getResponse1) {
+ assert.equal(getAclError, null);
+ assert.notEqual(getAclContainer1, null);
+ if (getAclContainer1) {
+ assert.equal(getAclContainer1.publicAccessLevel, BlobConstants.BlobContainerPublicAccessType.BLOB);
+ }
+
+ assert.ok(getResponse1.isSuccessful);
+
+ blobService.setContainerAcl(containerName, BlobConstants.BlobContainerPublicAccessType.CONTAINER, function (setAclError2, setAclContainer2, setResponse2) {
+ assert.equal(setAclError2, null);
+ assert.notEqual(setAclContainer2, null);
+ assert.ok(setResponse2.isSuccessful);
+
+ blobService.getContainerAcl(containerName, function (getAclError2, getAclContainer2, getResponse3) {
+ assert.equal(getAclError2, null);
+ assert.notEqual(getAclContainer2, null);
+ if (getAclContainer2) {
+ assert.equal(getAclContainer2.publicAccessLevel, BlobConstants.BlobContainerPublicAccessType.CONTAINER);
+ }
+
+ assert.ok(getResponse3.isSuccessful);
+
+ done();
+ });
+ });
+ });
+ });
+ });
+ });
+
test('SetContainerAclSignedIdentifiers', function (done) {
var containerName = testutil.generateId(containerNamesPrefix, containerNames, blobtestutil.isMocked);

0 comments on commit 76ec049

Please sign in to comment.