-
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 #602 from Avzel/main
#585 Prevent decoding of parameter values in the ParametersNameDecodingHandler Interceptor & write corresponding test case
- Loading branch information
Showing
4 changed files
with
90 additions
and
8 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
50 changes: 50 additions & 0 deletions
50
...http/okHttp/src/test/java/com/microsoft/kiota/http/ParametersNameDecodingHandlerTest.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,50 @@ | ||
package com.microsoft.kiota.http; | ||
|
||
import com.microsoft.kiota.http.middleware.ParametersNameDecodingHandler; | ||
import com.microsoft.kiota.http.middleware.options.ParametersNameDecodingOption; | ||
|
||
import okhttp3.Interceptor; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
import java.io.IOException; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class ParametersNameDecodingHandlerTest { | ||
|
||
private static Stream<Arguments> originalAndExpectedUrls() { | ||
return Stream.of( | ||
Arguments.of("https://www.google.com/", "https://www.google.com/"), | ||
Arguments.of("https://www.google.com/?q=1%2B2", "https://www.google.com/?q=1%2B2"), | ||
Arguments.of("https://www.google.com/?q=M%26A", "https://www.google.com/?q=M%26A"), | ||
Arguments.of("https://www.google.com/?q%2D1=M%26A", "https://www.google.com/?q-1=M%26A"), | ||
Arguments.of("https://www.google.com/?q%2D1&q=M%26A=M%26A", "https://www.google.com/?q-1&q=M%26A=M%26A") | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("originalAndExpectedUrls") | ||
public void defaultParameterNameDecodingHandlerOnlyDecodesNamesNotValues(String original, String expectedResult) throws IOException { | ||
Interceptor[] interceptors = new Interceptor[] { | ||
new ParametersNameDecodingHandler( new ParametersNameDecodingOption() { | ||
{ | ||
parametersToDecode = new char[] { '$', '.', '-', '~', '+', '&' }; | ||
} | ||
}) | ||
}; | ||
final OkHttpClient client = KiotaClientFactory.create(interceptors).build(); | ||
final Request request = new Request.Builder().url(original).build(); | ||
final Response response = client.newCall(request).execute(); | ||
|
||
assertNotNull(response); | ||
assertEquals(expectedResult, response.request().url().toString()); | ||
} | ||
} |
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