Skip to content

Validate CLOUDINARY_URL scheme #185

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

Merged
merged 3 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public static Configuration from(String cloudinaryUrl) {
static protected Map parseConfigUrl(String cloudinaryUrl) {
Map params = new HashMap();
URI cloudinaryUri = URI.create(cloudinaryUrl);
if (cloudinaryUri.getScheme() == null || !cloudinaryUri.getScheme().equalsIgnoreCase("cloudinary")){
throw new IllegalArgumentException("Invalid CLOUDINARY_URL scheme. Expecting to start with 'cloudinary://'");
}
params.put("cloud_name", cloudinaryUri.getHost());
if (cloudinaryUri.getUserInfo() != null) {
String[] creds = cloudinaryUri.getUserInfo().split(":");
Expand Down Expand Up @@ -427,4 +430,4 @@ public Builder from(Configuration other) {
return this;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,24 @@ public void testConfiguration() throws IllegalAccessException {
assertFieldsEqual(config, copy);
}

@Test
public void testCloudinaryUrlValidScheme() {
String cloudinaryUrl = "cloudinary://123456789012345:ALKJdjklLJAjhkKJ45hBK92baj3@test";
Configuration.from(cloudinaryUrl);
}

@Test(expected = IllegalArgumentException.class)
public void testCloudinaryUrlInvalidScheme() {
String cloudinaryUrl = "https://123456789012345:ALKJdjklLJAjhkKJ45hBK92baj3@test";
Configuration.from(cloudinaryUrl);
}

@Test(expected = IllegalArgumentException.class)
public void testCloudinaryUrlEmptyScheme() {
String cloudinaryUrl = " ";
Configuration.from(cloudinaryUrl);
}

private void assertFieldsEqual(Object a, Object b) throws IllegalAccessException {
assertEquals("Two objects must be the same class", a.getClass(), b.getClass());
Field[] fields = a.getClass().getFields();
Expand Down