-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: fix post policy escape bug, update conformance tests #924
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ | |
import com.google.cloud.conformance.storage.v1.UrlStyle; | ||
import com.google.cloud.storage.testing.RemoteStorageHelper; | ||
import com.google.common.base.Charsets; | ||
import com.google.common.base.Strings; | ||
import com.google.common.io.BaseEncoding; | ||
import com.google.protobuf.Timestamp; | ||
import com.google.protobuf.util.JsonFormat; | ||
|
@@ -117,17 +116,6 @@ public void test() { | |
|
||
PolicyConditions conditions = policyInput.getConditions(); | ||
|
||
if (!Strings.isNullOrEmpty(fields.get("success_action_redirect"))) { | ||
builder.addSuccessActionRedirectUrlCondition( | ||
PostPolicyV4.ConditionV4Type.MATCHES, fields.get("success_action_redirect")); | ||
} | ||
|
||
if (!Strings.isNullOrEmpty(fields.get("success_action_status"))) { | ||
builder.addSuccessActionStatusCondition( | ||
PostPolicyV4.ConditionV4Type.MATCHES, | ||
Integer.parseInt(fields.get("success_action_status"))); | ||
} | ||
|
||
if (conditions != null) { | ||
if (!conditions.getStartsWithList().isEmpty()) { | ||
builder.addCustomCondition( | ||
|
@@ -166,17 +154,25 @@ public void test() { | |
style); | ||
|
||
String expectedPolicy = testData.getPolicyOutput().getExpectedDecodedPolicy(); | ||
|
||
StringBuilder escapedPolicy = new StringBuilder(); | ||
|
||
// Java automatically unescapes the unicode escapes in the conformance tests, so we need to | ||
// manually re-escape them | ||
for (char c : expectedPolicy.toCharArray()) { | ||
char[] expectedPolicyArray = expectedPolicy.toCharArray(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to be reproducing the algorithm in the test. That risks copying bugs from one place to another, and verifying the buggy behavior. Can you make the expected output a literal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, they both happen to need to do the same thing (escaping certain characters). Sorry, I'm unsure what you mean by "make it a literal," can you elaborate? |
||
for (int i = 0; i < expectedPolicyArray.length; i++) { | ||
char c = expectedPolicyArray[i]; | ||
if (c >= 128) { | ||
escapedPolicy.append(String.format("\\u%04x", (int) c)); | ||
} else { | ||
switch (c) { | ||
case '\\': | ||
escapedPolicy.append("\\\\"); | ||
// quotes aren't unescaped, so leave any "\"" found alone | ||
if (expectedPolicyArray[i + 1] == '"') { | ||
escapedPolicy.append("\\"); | ||
} else { | ||
escapedPolicy.append("\\\\"); | ||
} | ||
break; | ||
case '\b': | ||
escapedPolicy.append("\\b"); | ||
|
@@ -202,6 +198,7 @@ public void test() { | |
} | ||
} | ||
assertEquals(testData.getPolicyOutput().getFieldsMap(), policy.getFields()); | ||
|
||
assertEquals( | ||
escapedPolicy.toString(), | ||
new String(BaseEncoding.base64().decode(policy.getFields().get("policy")))); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ | |
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-conformance-tests</artifactId> | ||
<version>0.0.11</version> | ||
<version>0.1.1</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this verify the change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, in fact the failures caused by it is what brought the bug to my attention (#510) |
||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is forward slash meant here? Looks like it should be a backslash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be, will fix