-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the problem of being able to configure invalid external URL
Signed-off-by: JohnNiang <[email protected]>
- Loading branch information
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
application/src/test/java/run/halo/app/infra/properties/HaloPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package run.halo.app.infra.properties; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.validation.SimpleErrors; | ||
|
||
class HaloPropertiesTest { | ||
|
||
static Stream<Arguments> validateTest() throws MalformedURLException { | ||
return Stream.of( | ||
Arguments.of(true, new URL("http://localhost:8080"), true), | ||
Arguments.of(false, new URL("http://localhost:8080"), true), | ||
Arguments.of(true, new URL("https://localhost:8080"), true), | ||
Arguments.of(false, new URL("https://localhost:8080"), true), | ||
Arguments.of(true, new URL("ftp://localhost:8080"), false), | ||
Arguments.of(false, new URL("ftp://localhost:8080"), false), | ||
Arguments.of(true, new URL("http:www/halo/run"), false), | ||
Arguments.of(false, new URL("http:www/halo.run"), false), | ||
Arguments.of(true, new URL("https:www/halo/run"), false), | ||
Arguments.of(false, new URL("https:www/halo/run"), false), | ||
Arguments.of(true, new URL("https:///path"), false), | ||
Arguments.of(false, new URL("https:///path"), false), | ||
Arguments.of(true, new URL("http:///path"), false), | ||
Arguments.of(false, new URL("http:///path"), false), | ||
Arguments.of(true, null, false), | ||
Arguments.of(false, null, true) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void validateTest(boolean useAbsolutePermalink, URL externalUrl, boolean valid) { | ||
var properties = new HaloProperties(); | ||
properties.setUseAbsolutePermalink(useAbsolutePermalink); | ||
properties.setExternalUrl(externalUrl); | ||
var errors = new SimpleErrors(properties); | ||
properties.validate(properties, errors); | ||
Assertions.assertEquals(valid, !errors.hasErrors()); | ||
} | ||
} |