Skip to content

Commit

Permalink
fix: Remove post policy v4 client side validation (#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseLovelace committed Jan 25, 2022
1 parent 136fab8 commit 631741d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
Expand Up @@ -21,11 +21,9 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -54,7 +52,6 @@ private PostPolicyV4(String url, Map<String, String> fields) {
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
PostFieldsV4.validateFields(fields);

this.url = url;
this.fields = Collections.unmodifiableMap(fields);
Expand Down Expand Up @@ -93,40 +90,12 @@ public Map<String, String> getFields() {
*/
public static final class PostFieldsV4 {
private final Map<String, String> fieldsMap;
private static final List<String> VALID_FIELDS =
Arrays.asList(
"acl",
"bucket",
"cache-control",
"content-disposition",
"content-encoding",
"content-type",
"expires",
"file",
"key",
"policy",
"success_action_redirect",
"success_action_status",
"x-goog-algorithm",
"x-goog-credential",
"x-goog-date",
"x-goog-signature");

private static void validateFields(Map<String, String> fields) {
for (String key : fields.keySet()) {
if (!VALID_FIELDS.contains(key.toLowerCase())
&& !key.startsWith(Builder.CUSTOM_FIELD_PREFIX)) {
throw new IllegalArgumentException("Invalid key: " + key);
}
}
}

private PostFieldsV4(Builder builder) {
this(builder.fieldsMap);
}

private PostFieldsV4(Map<String, String> fields) {
validateFields(fields);
this.fieldsMap = Collections.unmodifiableMap(fields);
}

Expand Down
Expand Up @@ -98,36 +98,12 @@ public void testPostPolicyV4_ofMalformedURL() {
}
}

@Test
public void testPostPolicyV4_ofInvalidField() {
Map<String, String> fields = new HashMap<>(ALL_FIELDS);
fields.put("$file", "file.txt");
try {
PostPolicyV4.of("http://google.com", fields);
fail();
} catch (IllegalArgumentException e) {
assertEquals("Invalid key: $file", e.getMessage());
}
}

@Test
public void testPostFieldsV4_of() {
PostPolicyV4.PostFieldsV4 fields = PostPolicyV4.PostFieldsV4.of(ALL_FIELDS);
assertMapsEquals(ALL_FIELDS, fields.getFieldsMap());
}

@Test
public void testPostFieldsV4_ofInvalidField() {
Map<String, String> map = new HashMap<>();
map.put("$file", "file.txt");
try {
PostPolicyV4.PostFieldsV4.of(map);
fail();
} catch (IllegalArgumentException e) {
assertEquals("Invalid key: $file", e.getMessage());
}
}

@Test
public void testPostPolicyV4_builder() {
PostPolicyV4.PostFieldsV4.Builder builder = PostPolicyV4.PostFieldsV4.newBuilder();
Expand Down

0 comments on commit 631741d

Please sign in to comment.