File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
test/java/com/cloudinary/test Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,9 @@ public static Configuration from(String cloudinaryUrl) {
186
186
static protected Map parseConfigUrl (String cloudinaryUrl ) {
187
187
Map params = new HashMap ();
188
188
URI cloudinaryUri = URI .create (cloudinaryUrl );
189
+ if (cloudinaryUri .getScheme () == null || !cloudinaryUri .getScheme ().equalsIgnoreCase ("cloudinary" )){
190
+ throw new IllegalArgumentException ("Invalid CLOUDINARY_URL scheme. Expecting to start with 'cloudinary://'" );
191
+ }
189
192
params .put ("cloud_name" , cloudinaryUri .getHost ());
190
193
if (cloudinaryUri .getUserInfo () != null ) {
191
194
String [] creds = cloudinaryUri .getUserInfo ().split (":" );
@@ -427,4 +430,4 @@ public Builder from(Configuration other) {
427
430
return this ;
428
431
}
429
432
}
430
- }
433
+ }
Original file line number Diff line number Diff line change @@ -1230,6 +1230,24 @@ public void testConfiguration() throws IllegalAccessException {
1230
1230
assertFieldsEqual (config , copy );
1231
1231
}
1232
1232
1233
+ @ Test
1234
+ public void testCloudinaryUrlValidScheme () {
1235
+ String cloudinaryUrl = "cloudinary://123456789012345:ALKJdjklLJAjhkKJ45hBK92baj3@test" ;
1236
+ Configuration .from (cloudinaryUrl );
1237
+ }
1238
+
1239
+ @ Test (expected = IllegalArgumentException .class )
1240
+ public void testCloudinaryUrlInvalidScheme () {
1241
+ String cloudinaryUrl = "https://123456789012345:ALKJdjklLJAjhkKJ45hBK92baj3@test" ;
1242
+ Configuration .from (cloudinaryUrl );
1243
+ }
1244
+
1245
+ @ Test (expected = IllegalArgumentException .class )
1246
+ public void testCloudinaryUrlEmptyScheme () {
1247
+ String cloudinaryUrl = " " ;
1248
+ Configuration .from (cloudinaryUrl );
1249
+ }
1250
+
1233
1251
private void assertFieldsEqual (Object a , Object b ) throws IllegalAccessException {
1234
1252
assertEquals ("Two objects must be the same class" , a .getClass (), b .getClass ());
1235
1253
Field [] fields = a .getClass ().getFields ();
You can’t perform that action at this time.
0 commit comments