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) {
186186 static protected Map parseConfigUrl (String cloudinaryUrl ) {
187187 Map params = new HashMap ();
188188 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+ }
189192 params .put ("cloud_name" , cloudinaryUri .getHost ());
190193 if (cloudinaryUri .getUserInfo () != null ) {
191194 String [] creds = cloudinaryUri .getUserInfo ().split (":" );
@@ -427,4 +430,4 @@ public Builder from(Configuration other) {
427430 return this ;
428431 }
429432 }
430- }
433+ }
Original file line number Diff line number Diff line change @@ -1230,6 +1230,24 @@ public void testConfiguration() throws IllegalAccessException {
12301230 assertFieldsEqual (config , copy );
12311231 }
12321232
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+
12331251 private void assertFieldsEqual (Object a , Object b ) throws IllegalAccessException {
12341252 assertEquals ("Two objects must be the same class" , a .getClass (), b .getClass ());
12351253 Field [] fields = a .getClass ().getFields ();
You can’t perform that action at this time.
0 commit comments