Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 252: Table: Need to support signing when URL contains escapable characters #31

Merged
merged 5 commits into from
Apr 4, 2012
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
2012.01.31. Version 0.1.3
2012.02.28 Version 0.2.0
* Added Support for Azure Table in com.microsoft.windowsazure.services.table
* Added Client Tests for Table
* Added a dependency on apache commons-lang3 3.1
* ResultsSegment exposes an ArrayList instead of an Iterable
* UserAgent updated to v1.1.2

2012.01.31 Version 0.1.3
* Updated User Agent to v0.1.1
* Updated License Headers
* Blob Client Mark bug fix
Expand All @@ -8,7 +15,7 @@
* Date parsing support for various number of fractional decimals
* StorageErrorResponse updated to support lower case xml for tables

2011.12.22. Version 0.1.2
2011.12.22 Version 0.1.2
* Fixed CloudBlob.download to lock to ETag during a resume
* Ensured that Client Side Exceptions are not resumed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Windows Azure Java Developer Center</a></p>
<h3>Option 1: Via Git</h3>
<p>To get the source code of the SDK via git just type:<br/>
<pre>git clone git://github.com/WindowsAzure/azure-sdk-for-java.git
cd ./azure-sdk-for-java
cd ./azure-sdk-for-java/microsoft-azure-api
mvn compile</pre>

<h3>Option 2: Via Maven</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void sign(ClientRequest cr) {
private String getCanonicalizedResource(ClientRequest cr) {
String result = "/" + this.getAccountName();

result += cr.getURI().getPath();
result += cr.getURI().getRawPath();

List<QueryParam> queryParams = SharedKeyUtils.getQueryParams(cr.getURI().getQuery());
for (QueryParam p : queryParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
Expand Down Expand Up @@ -159,7 +161,17 @@ private List<String> encodeODataURIValues(List<String> values) {
}

private String getEntityPath(String table, String partitionKey, String rowKey) {
return table + "(" + "PartitionKey='" + partitionKey + "',RowKey='" + rowKey + "')";
return table + "(" + "PartitionKey='" + safeEncode(partitionKey) + "',RowKey='" + safeEncode(rowKey) + "')";
}

private String safeEncode(String input) {
String fixSingleQuotes = input.replace("'", "''");
try {
return URLEncoder.encode(fixSingleQuotes, "UTF-8").replace("+", "%20");
}
catch (UnsupportedEncodingException e) {
return fixSingleQuotes;
}
}

private WebResource addOptionalQueryParam(WebResource webResource, String key, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,32 @@ public void deleteEntityWorks() throws Exception {
// Assert
}

@Test
public void deleteEntityTroublesomeKeyWorks() throws Exception {
System.out.println("deleteEntityTroublesomeKeyWorks()");

// Arrange
Configuration config = createConfiguration();
TableContract service = TableService.create(config);
Entity entity1 = new Entity().setPartitionKey("001").setRowKey("key with spaces");
Entity entity2 = new Entity().setPartitionKey("001").setRowKey("key'with'quotes");
Entity entity3 = new Entity().setPartitionKey("001").setRowKey("keyWithUnicode \uB2E4");
Entity entity4 = new Entity().setPartitionKey("001").setRowKey("key 'with'' \uB2E4");

// Act
InsertEntityResult result1 = service.insertEntity(TEST_TABLE_2, entity1);
InsertEntityResult result2 = service.insertEntity(TEST_TABLE_2, entity2);
InsertEntityResult result3 = service.insertEntity(TEST_TABLE_2, entity3);
InsertEntityResult result4 = service.insertEntity(TEST_TABLE_2, entity4);

service.deleteEntity(TEST_TABLE_2, result1.getEntity().getPartitionKey(), result1.getEntity().getRowKey());
service.deleteEntity(TEST_TABLE_2, result2.getEntity().getPartitionKey(), result2.getEntity().getRowKey());
service.deleteEntity(TEST_TABLE_2, result3.getEntity().getPartitionKey(), result3.getEntity().getRowKey());
service.deleteEntity(TEST_TABLE_2, result4.getEntity().getPartitionKey(), result4.getEntity().getRowKey());

// Assert
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to assert the success of the deletion by validating the original entities do not exist any more?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll add that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below for the new asserts

}

@Test
public void deleteEntityWithETagWorks() throws Exception {
System.out.println("deleteEntityWithETagWorks()");
Expand Down