Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 465e8b6

Browse files
author
Josh Friedman
committed
Qualified URI changes/bug fix
1 parent b21330d commit 465e8b6

File tree

14 files changed

+393
-62
lines changed

14 files changed

+393
-62
lines changed

BreakingChanges.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
Changes in 5.0.0
22

3+
BLOB
4+
* getQualifiedUri() has been deprecated. Please use getSnapshotQualifiedUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
5+
* getQualifiedStorageUri() has been deprecated. Please use getSnapshotQualifiedStorageUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
6+
* Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token.
7+
8+
FILE
9+
* Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token.
10+
311
QUEUE
412
* For addMessage() the CloudQueueMessage message passed in will be populated with the pop receipt, insertion/expiration time, and message ID.
513

ChangeLog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* Added support in Page Blob for incremental copy.
88
* Added large BlockBlob upload support. Blocks can now support sizes up to 100 MB.
99
* Added a new, memory-optimized upload strategy for the upload* APIs. This algorithm only applies for blocks greater than 4MB and when storeBlobContentMD5 and Client-Side Encryption are disabled.
10+
* getQualifiedUri() has been deprecated for Blobs. Please use getSnapshotQualifiedUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
11+
* getQualifiedStorageUri() has been deprecated for Blobs. Please use getSnapshotQualifiedStorageUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
12+
* Fixed a bug where copying from a blob that included a SAS token and a snapshot ommitted the SAS token.
1013

1114
2016.08.30 Version 4.4.0
1215
* Fixed a bug in client-side encryption for tables that was preventing the Java client from decrypting entities encrypted with the .NET client, and vice versa.

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/BlobTestHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public static void assertAreEqual(CloudBlob blob1, CloudBlob blob2) throws URISy
388388
assertEquals(blob1.getUri(), blob2.getUri());
389389
assertEquals(blob1.getSnapshotID(), blob2.getSnapshotID());
390390
assertEquals(blob1.isSnapshot(), blob2.isSnapshot());
391-
assertEquals(blob1.getQualifiedStorageUri(), blob2.getQualifiedStorageUri());
391+
assertEquals(blob1.getSnapshotQualifiedStorageUri(), blob2.getSnapshotQualifiedStorageUri());
392392
assertAreEqual(blob1.getProperties(), blob2.getProperties());
393393
assertAreEqual(blob1.getCopyState(), blob2.getCopyState());
394394
}

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudAppendBlobTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ public void testAppendBlobCopyTest() throws URISyntaxException,
767767
BlobTestHelper.waitForCopy(copy);
768768

769769
assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus());
770-
assertEquals(source.getQualifiedUri().getPath(), copy.getCopyState()
770+
assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState()
771771
.getSource().getPath());
772772
assertEquals(buffer.length, copy.getCopyState().getTotalBytes()
773773
.intValue());
@@ -834,7 +834,7 @@ public void testAppendBlobCopyWithMetadataOverride()
834834
BlobTestHelper.waitForCopy(copy);
835835

836836
assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus());
837-
assertEquals(source.getQualifiedUri().getPath(), copy.getCopyState()
837+
assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState()
838838
.getSource().getPath());
839839
assertEquals(buffer.length, copy.getCopyState().getTotalBytes()
840840
.intValue());

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobContainerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ private static void assertCreatedAndListedBlobsEquivalent(CloudBlockBlob created
864864
assertEquals(createdBlob.getContainer().getName(), listedBlob.getContainer().getName());
865865
assertEquals(createdBlob.getMetadata(), listedBlob.getMetadata());
866866
assertEquals(createdBlob.getName(), listedBlob.getName());
867-
assertEquals(createdBlob.getQualifiedUri(), listedBlob.getQualifiedUri());
867+
assertEquals(createdBlob.getSnapshotQualifiedUri(), listedBlob.getSnapshotQualifiedUri());
868868
assertEquals(createdBlob.getSnapshotID(), listedBlob.getSnapshotID());
869869
assertEquals(createdBlob.getUri(), listedBlob.getUri());
870870

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public void testCopyBlockBlobWithMetadataOverride() throws URISyntaxException, S
320320
BlobTestHelper.waitForCopy(copy);
321321

322322
assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus());
323-
assertEquals(source.getQualifiedUri().getPath(), copy.getCopyState().getSource().getPath());
323+
assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState().getSource().getPath());
324324
assertEquals(data.length(), copy.getCopyState().getTotalBytes().intValue());
325325
assertEquals(data.length(), copy.getCopyState().getBytesCopied().intValue());
326326
assertEquals(copyId, copy.getCopyState().getCopyId());
@@ -1829,7 +1829,7 @@ private void doCloudBlockBlobCopy(boolean sourceIsSas, boolean destinationIsSas)
18291829

18301830
// Check original blob references for equality
18311831
assertEquals(CopyStatus.SUCCESS, destination.getCopyState().getStatus());
1832-
assertEquals(source.getQualifiedUri().getPath(), destination.getCopyState().getSource().getPath());
1832+
assertEquals(source.getSnapshotQualifiedUri().getPath(), destination.getCopyState().getSource().getPath());
18331833
assertEquals(data.length(), destination.getCopyState().getTotalBytes().intValue());
18341834
assertEquals(data.length(), destination.getCopyState().getBytesCopied().intValue());
18351835
assertEquals(copyId, destination.getProperties().getCopyState().getCopyId());

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudPageBlobTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import com.microsoft.azure.storage.SharedAccessAccountPolicy;
5353
import com.microsoft.azure.storage.SharedAccessAccountResourceType;
5454
import com.microsoft.azure.storage.SharedAccessAccountService;
55-
import com.microsoft.azure.storage.StorageCredentials;
5655
import com.microsoft.azure.storage.StorageEvent;
5756
import com.microsoft.azure.storage.StorageException;
5857
import com.microsoft.azure.storage.TestHelper;
@@ -509,7 +508,7 @@ public void testPageBlobCopyTest() throws URISyntaxException, StorageException,
509508
BlobTestHelper.waitForCopy(copy);
510509

511510
assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus());
512-
assertEquals(source.getQualifiedUri().getPath(), copy.getCopyState().getSource().getPath());
511+
assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState().getSource().getPath());
513512
assertEquals(buffer.length, copy.getCopyState().getTotalBytes().intValue());
514513
assertEquals(buffer.length, copy.getCopyState().getBytesCopied().intValue());
515514
assertEquals(copyId, copy.getCopyState().getCopyId());
@@ -567,7 +566,7 @@ public void testPageBlobCopyWithMetadataOverride() throws URISyntaxException, St
567566
BlobTestHelper.waitForCopy(copy);
568567

569568
assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus());
570-
assertEquals(source.getQualifiedUri().getPath(), copy.getCopyState().getSource().getPath());
569+
assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState().getSource().getPath());
571570
assertEquals(buffer.length, copy.getCopyState().getTotalBytes().intValue());
572571
assertEquals(buffer.length, copy.getCopyState().getBytesCopied().intValue());
573572
assertEquals(copyId, copy.getCopyState().getCopyId());

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/SasTests.java

Lines changed: 199 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,9 @@
1515

1616
package com.microsoft.azure.storage.blob;
1717

18-
import com.microsoft.azure.storage.Constants;
19-
import com.microsoft.azure.storage.core.PathUtility;
20-
import com.microsoft.azure.storage.core.SR;
21-
import com.microsoft.azure.storage.IPRange;
22-
import com.microsoft.azure.storage.OperationContext;
23-
import com.microsoft.azure.storage.ResponseReceivedEvent;
24-
import com.microsoft.azure.storage.SecondaryTests;
25-
import com.microsoft.azure.storage.SendingRequestEvent;
26-
import com.microsoft.azure.storage.SharedAccessProtocols;
27-
import com.microsoft.azure.storage.StorageCredentials;
28-
import com.microsoft.azure.storage.StorageCredentialsAnonymous;
29-
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
30-
import com.microsoft.azure.storage.StorageEvent;
31-
import com.microsoft.azure.storage.StorageException;
32-
import com.microsoft.azure.storage.TestRunners;
33-
3418
import junit.framework.Assert;
3519

36-
import org.junit.After;
37-
import org.junit.Before;
38-
import org.junit.Test;
39-
import org.junit.experimental.categories.Category;
40-
20+
import java.io.ByteArrayInputStream;
4121
import java.io.ByteArrayOutputStream;
4222
import java.io.IOException;
4323
import java.net.HttpURLConnection;
@@ -54,7 +34,32 @@
5434
import java.util.NoSuchElementException;
5535
import java.util.TimeZone;
5636

37+
import org.junit.After;
38+
import org.junit.Before;
39+
import org.junit.Test;
40+
import org.junit.experimental.categories.Category;
41+
42+
import com.microsoft.azure.storage.Constants;
43+
import com.microsoft.azure.storage.core.PathUtility;
44+
import com.microsoft.azure.storage.core.SR;
45+
import com.microsoft.azure.storage.IPRange;
46+
import com.microsoft.azure.storage.OperationContext;
47+
import com.microsoft.azure.storage.ResponseReceivedEvent;
48+
import com.microsoft.azure.storage.SecondaryTests;
49+
import com.microsoft.azure.storage.SendingRequestEvent;
50+
import com.microsoft.azure.storage.SharedAccessProtocols;
51+
import com.microsoft.azure.storage.SharedAccessAccountPermissions;
52+
import com.microsoft.azure.storage.SharedAccessAccountPolicy;
53+
import com.microsoft.azure.storage.SharedAccessAccountResourceType;
54+
import com.microsoft.azure.storage.SharedAccessAccountService;
55+
import com.microsoft.azure.storage.SharedAccessProtocols;
56+
import com.microsoft.azure.storage.StorageCredentials;
57+
import com.microsoft.azure.storage.StorageCredentialsAnonymous;
58+
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
59+
import com.microsoft.azure.storage.StorageEvent;
60+
import com.microsoft.azure.storage.StorageException;
5761
import com.microsoft.azure.storage.TestHelper;
62+
import com.microsoft.azure.storage.TestRunners;
5863
import com.microsoft.azure.storage.TestRunners.CloudTests;
5964
import com.microsoft.azure.storage.TestRunners.DevFabricTests;
6065
import com.microsoft.azure.storage.TestRunners.DevStoreTests;
@@ -487,6 +492,179 @@ public void eventOccurred(SendingRequestEvent eventArg) {
487492
sasBlob.download(new ByteArrayOutputStream(), null, null, context);
488493
}
489494

495+
@Test
496+
public void testAppendBlobCopyWithSasAndSnapshot()
497+
throws URISyntaxException, StorageException, InterruptedException, IOException, InvalidKeyException {
498+
String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
499+
CloudAppendBlob source = this.container.getAppendBlobReference(blobName);
500+
source.createOrReplace();
501+
byte[] buffer = BlobTestHelper.getRandomBuffer(512);
502+
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
503+
source.upload(stream, buffer.length);
504+
source.getMetadata().put("Test", "value");
505+
source.uploadMetadata();
506+
507+
SharedAccessBlobPolicy policy = createSharedAccessPolicy(
508+
EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE,
509+
SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE), 5000);
510+
511+
CloudAppendBlob copy = this.container.getAppendBlobReference("copy");
512+
String sasToken = copy.generateSharedAccessSignature(policy, null);
513+
CloudAppendBlob copySas = new CloudAppendBlob(new URI(copy.getUri().toString() + "?" + sasToken));
514+
515+
// Generate account SAS for the source
516+
// Cannot generate a SAS directly on a snapshot and the SAS for the destination is only for the destination
517+
SharedAccessAccountPolicy accountPolicy = new SharedAccessAccountPolicy();
518+
accountPolicy.setPermissions(EnumSet.of(SharedAccessAccountPermissions.READ, SharedAccessAccountPermissions.WRITE));
519+
accountPolicy.setServices(EnumSet.of(SharedAccessAccountService.BLOB));
520+
accountPolicy.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.OBJECT, SharedAccessAccountResourceType.CONTAINER));
521+
accountPolicy.setSharedAccessExpiryTime(policy.getSharedAccessExpiryTime());
522+
final CloudBlobClient sasClient = TestHelper.createCloudBlobClient(accountPolicy, false);
523+
524+
CloudAppendBlob snapshot = (CloudAppendBlob) source.createSnapshot();
525+
CloudAppendBlob sasBlob = (CloudAppendBlob) sasClient.getContainerReference(container.getName())
526+
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null);
527+
sasBlob.exists();
528+
529+
String copyId = copySas.startCopy(BlobTestHelper.defiddler(sasBlob));
530+
BlobTestHelper.waitForCopy(copySas);
531+
532+
copySas.downloadAttributes();
533+
BlobProperties prop1 = copySas.getProperties();
534+
BlobProperties prop2 = sasBlob.getProperties();
535+
536+
assertEquals(prop1.getCacheControl(), prop2.getCacheControl());
537+
assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding());
538+
assertEquals(prop1.getContentDisposition(),
539+
prop2.getContentDisposition());
540+
assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage());
541+
assertEquals(prop1.getContentMD5(), prop2.getContentMD5());
542+
assertEquals(prop1.getContentType(), prop2.getContentType());
543+
544+
assertEquals("value", copySas.getMetadata().get("Test"));
545+
assertEquals(copyId, copySas.getCopyState().getCopyId());
546+
547+
snapshot.delete();
548+
source.delete();
549+
copySas.delete();
550+
}
551+
552+
@Test
553+
public void testBlockBlobCopyWithSasAndSnapshot()
554+
throws URISyntaxException, StorageException, InterruptedException, IOException, InvalidKeyException {
555+
String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
556+
CloudBlockBlob source = this.container.getBlockBlobReference(blobName);
557+
String data = "String data";
558+
source.uploadText(data, Constants.UTF8_CHARSET, null, null, null);
559+
560+
byte[] buffer = BlobTestHelper.getRandomBuffer(512);
561+
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
562+
source.upload(stream, buffer.length);
563+
source.getMetadata().put("Test", "value");
564+
source.uploadMetadata();
565+
566+
SharedAccessBlobPolicy policy = createSharedAccessPolicy(
567+
EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE,
568+
SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE), 5000);
569+
570+
CloudBlockBlob copy = this.container.getBlockBlobReference("copy");
571+
String sasToken = copy.generateSharedAccessSignature(policy, null);
572+
CloudBlockBlob copySas = new CloudBlockBlob(new URI(copy.getUri().toString() + "?" + sasToken));
573+
574+
// Generate account SAS for the source
575+
// Cannot generate a SAS directly on a snapshot and the SAS for the destination is only for the destination
576+
SharedAccessAccountPolicy accountPolicy = new SharedAccessAccountPolicy();
577+
accountPolicy.setPermissions(EnumSet.of(SharedAccessAccountPermissions.READ, SharedAccessAccountPermissions.WRITE));
578+
accountPolicy.setServices(EnumSet.of(SharedAccessAccountService.BLOB));
579+
accountPolicy.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.OBJECT, SharedAccessAccountResourceType.CONTAINER));
580+
accountPolicy.setSharedAccessExpiryTime(policy.getSharedAccessExpiryTime());
581+
final CloudBlobClient sasClient = TestHelper.createCloudBlobClient(accountPolicy, false);
582+
583+
CloudBlockBlob snapshot = (CloudBlockBlob) source.createSnapshot();
584+
CloudBlockBlob sasBlob = (CloudBlockBlob) sasClient.getContainerReference(container.getName())
585+
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null);
586+
sasBlob.exists();
587+
588+
String copyId = copySas.startCopy(BlobTestHelper.defiddler(sasBlob));
589+
BlobTestHelper.waitForCopy(copySas);
590+
591+
copySas.downloadAttributes();
592+
BlobProperties prop1 = copySas.getProperties();
593+
BlobProperties prop2 = sasBlob.getProperties();
594+
595+
assertEquals(prop1.getCacheControl(), prop2.getCacheControl());
596+
assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding());
597+
assertEquals(prop1.getContentDisposition(),
598+
prop2.getContentDisposition());
599+
assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage());
600+
assertEquals(prop1.getContentMD5(), prop2.getContentMD5());
601+
assertEquals(prop1.getContentType(), prop2.getContentType());
602+
603+
assertEquals("value", copySas.getMetadata().get("Test"));
604+
assertEquals(copyId, copySas.getCopyState().getCopyId());
605+
606+
snapshot.delete();
607+
source.delete();
608+
copySas.delete();
609+
}
610+
611+
@Test
612+
public void testPageBlobCopyWithSasAndSnapshot()
613+
throws URISyntaxException, StorageException, InterruptedException, IOException, InvalidKeyException {
614+
String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob");
615+
CloudPageBlob source = this.container.getPageBlobReference(blobName);
616+
source.create(1024);
617+
byte[] buffer = BlobTestHelper.getRandomBuffer(512);
618+
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
619+
source.upload(stream, buffer.length);
620+
source.getMetadata().put("Test", "value");
621+
source.uploadMetadata();
622+
623+
SharedAccessBlobPolicy policy = createSharedAccessPolicy(
624+
EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE,
625+
SharedAccessBlobPermissions.LIST, SharedAccessBlobPermissions.DELETE), 5000);
626+
627+
CloudPageBlob copy = this.container.getPageBlobReference("copy");
628+
String sasToken = copy.generateSharedAccessSignature(policy, null);
629+
CloudPageBlob copySas = new CloudPageBlob(new URI(copy.getUri().toString() + "?" + sasToken));
630+
631+
// Generate account SAS for the source
632+
// Cannot generate a SAS directly on a snapshot and the SAS for the destination is only for the destination
633+
SharedAccessAccountPolicy accountPolicy = new SharedAccessAccountPolicy();
634+
accountPolicy.setPermissions(EnumSet.of(SharedAccessAccountPermissions.READ, SharedAccessAccountPermissions.WRITE));
635+
accountPolicy.setServices(EnumSet.of(SharedAccessAccountService.BLOB));
636+
accountPolicy.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.OBJECT, SharedAccessAccountResourceType.CONTAINER));
637+
accountPolicy.setSharedAccessExpiryTime(policy.getSharedAccessExpiryTime());
638+
final CloudBlobClient sasClient = TestHelper.createCloudBlobClient(accountPolicy, false);
639+
640+
CloudPageBlob snapshot = (CloudPageBlob) source.createSnapshot();
641+
CloudPageBlob sasBlob = (CloudPageBlob) sasClient.getContainerReference(container.getName())
642+
.getBlobReferenceFromServer(snapshot.getName(), snapshot.snapshotID, null, null, null);
643+
sasBlob.exists();
644+
645+
String copyId = copySas.startCopy(BlobTestHelper.defiddler(sasBlob));
646+
BlobTestHelper.waitForCopy(copySas);
647+
648+
copySas.downloadAttributes();
649+
BlobProperties prop1 = copySas.getProperties();
650+
BlobProperties prop2 = sasBlob.getProperties();
651+
652+
assertEquals(prop1.getCacheControl(), prop2.getCacheControl());
653+
assertEquals(prop1.getContentEncoding(), prop2.getContentEncoding());
654+
assertEquals(prop1.getContentDisposition(),
655+
prop2.getContentDisposition());
656+
assertEquals(prop1.getContentLanguage(), prop2.getContentLanguage());
657+
assertEquals(prop1.getContentMD5(), prop2.getContentMD5());
658+
assertEquals(prop1.getContentType(), prop2.getContentType());
659+
660+
assertEquals("value", copySas.getMetadata().get("Test"));
661+
assertEquals(copyId, copySas.getCopyState().getCopyId());
662+
663+
snapshot.delete();
664+
source.delete();
665+
copySas.delete();
666+
}
667+
490668
private final static SharedAccessBlobPolicy createSharedAccessPolicy(EnumSet<SharedAccessBlobPermissions> sap,
491669
int expireTimeInSeconds) {
492670

0 commit comments

Comments
 (0)