-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1051 from microsoft/fix/allowed-hosts-validator
Validate allowed hosts for http and https prefixes
Showing
5 changed files
with
58 additions
and
6 deletions.
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
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
37 changes: 37 additions & 0 deletions
37
...stractions/src/test/java/com/microsoft/kiota/authentication/AllowedHostValidatorTest.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,37 @@ | ||
package com.microsoft.kiota.authentication; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
class AllowedHostValidatorTest { | ||
|
||
@Test | ||
void throwsExceptionForHttpOrHttpsHosts() { | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> | ||
new AllowedHostsValidator( | ||
"graph.microsoft.com", "https://graph.microsoft.com")); | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> | ||
new AllowedHostsValidator( | ||
"http://graph.microsoft.com", "graph.microsoft.com")); | ||
} | ||
|
||
@Test | ||
void initialisesAllowedHostsSuccessfully() throws URISyntaxException { | ||
final AllowedHostsValidator validator = | ||
new AllowedHostsValidator( | ||
"graph.microsoft.com", "graph.MICROSOFT.US ", "canary.graph.microsoft.com"); | ||
assertEquals(3, validator.getAllowedHosts().size()); | ||
assertTrue(validator.getAllowedHosts().contains("graph.microsoft.us")); | ||
assertTrue(validator.isUrlHostValid(new URI("https://graph.microsoft.com/v1/me"))); | ||
} | ||
} |
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