Skip to content

Commit cf0f770

Browse files
committed
Support cloudinary credentials URL that has an API_KEY but no API_SECRET
This is required for mobile applications that are not supposed to use the API_SECRET.
1 parent 2b19b5e commit cf0f770

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

cloudinary-core/src/main/java/com/cloudinary/Cloudinary.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ protected Map parseConfigUrl(String cloudinaryUrl) {
246246
if (cloudinaryUri.getUserInfo() != null) {
247247
String[] creds = cloudinaryUri.getUserInfo().split(":");
248248
params.put("api_key", creds[0]);
249-
params.put("api_secret", creds[1]);
249+
if (creds.length > 1) {
250+
params.put("api_secret", creds[1]);
251+
}
250252
}
251253
params.put("private_cdn", !StringUtils.isEmpty(cloudinaryUri.getPath()));
252254
params.put("secure_distribution", cloudinaryUri.getPath());

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@
1818
import java.util.zip.ZipInputStream;
1919
import java.net.*;
2020

21+
import com.cloudinary.*;
22+
import org.cloudinary.json.JSONArray;
2123
import org.junit.Before;
2224
import org.junit.BeforeClass;
2325
import org.junit.AfterClass;
2426
import org.junit.Rule;
2527
import org.junit.Test;
2628
import org.junit.rules.TestName;
2729

28-
import com.cloudinary.ArchiveParams;
29-
import com.cloudinary.Cloudinary;
30-
import com.cloudinary.Coordinates;
31-
import com.cloudinary.ResponsiveBreakpoints;
32-
import com.cloudinary.Transformation;
30+
import com.cloudinary.ResponsiveBreakpoint;
3331
import com.cloudinary.utils.ObjectUtils;
3432
import com.cloudinary.utils.Rectangle;
3533

@@ -438,12 +436,32 @@ public void testFilenameOption() throws Exception {
438436

439437
@Test
440438
public void testResponsiveBreakpoints() throws Exception {
441-
Map result = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("responsive_breakpoints",
442-
new ResponsiveBreakpoints().maxImages(2).createDerived(false)
439+
ResponsiveBreakpoint breakpoint = new ResponsiveBreakpoint().maxImages(2).createDerived(false);
440+
441+
// A single breakpoint
442+
Map result = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("responsive_breakpoints",
443+
breakpoint
443444
));
444445
java.util.ArrayList breakpointsResponse = (java.util.ArrayList) result.get("responsive_breakpoints");
445446
java.util.ArrayList breakpoints = (java.util.ArrayList)((Map) breakpointsResponse.get(0)).get("breakpoints");
446447
assertEquals(2, breakpoints.size());
448+
449+
// an array of breakpoints
450+
result = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("responsive_breakpoints",
451+
new ResponsiveBreakpoint [] {breakpoint}
452+
));
453+
breakpointsResponse = (java.util.ArrayList) result.get("responsive_breakpoints");
454+
breakpoints = (java.util.ArrayList)((Map) breakpointsResponse.get(0)).get("breakpoints");
455+
assertEquals(2, breakpoints.size());
456+
457+
// a JSONArray of breakpoints
458+
JSONArray array = new JSONArray();
459+
array.put(breakpoint);
460+
result = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("responsive_breakpoints", array
461+
));
462+
breakpointsResponse = (java.util.ArrayList) result.get("responsive_breakpoints");
463+
breakpoints = (java.util.ArrayList)((Map) breakpointsResponse.get(0)).get("breakpoints");
464+
assertEquals(2, breakpoints.size());
447465
}
448466

449467
@Test

0 commit comments

Comments
 (0)