-
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 #1072 from microsoft/fix/https-localhost
Allow https on localhost URLs
- Loading branch information
Showing
5 changed files
with
62 additions
and
2 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
44 changes: 44 additions & 0 deletions
44
...rc/test/java/com/microsoft/kiota/authentication/AzureIdentityAccessTokenProviderTest.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,44 @@ | ||
package com.microsoft.kiota.authentication; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
import com.azure.core.credential.AccessToken; | ||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.core.credential.TokenRequestContext; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.HashMap; | ||
|
||
public class AzureIdentityAccessTokenProviderTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource( | ||
strings = {"http://localhost:80/me", "http://127.0.0.1/me", "http://[::1]:8080/me"}) | ||
void testLocalhostHttpUrlIsValid(String urlString) throws URISyntaxException { | ||
var tokenCredential = mock(TokenCredential.class); | ||
when(tokenCredential.getTokenSync(any(TokenRequestContext.class))) | ||
.thenReturn(new AccessToken("token", null)); | ||
var accessTokenProvider = new AzureIdentityAccessTokenProvider(tokenCredential, null, ""); | ||
assertEquals( | ||
"token", | ||
accessTokenProvider.getAuthorizationToken(new URI(urlString), new HashMap<>())); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"http://graph.microsoft.com/me"}) | ||
void testNonLocalhostHttpUrlIsInvalid(String urlString) { | ||
var tokenCredential = mock(TokenCredential.class); | ||
var accessTokenProvider = new AzureIdentityAccessTokenProvider(tokenCredential, null, ""); | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> | ||
accessTokenProvider.getAuthorizationToken( | ||
new URI(urlString), new HashMap<>())); | ||
} | ||
} |
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