Skip to content

Commit

Permalink
Merge pull request #1501 from microsoftgraph/dev
Browse files Browse the repository at this point in the history
V3.1.2 release
  • Loading branch information
baywet authored Feb 13, 2024
2 parents 9ab7cb2 + 3400523 commit a401657
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [3.1.2] - 2024-02-12

### Changed

- Fixes bug where 'Authorization' header was being added leading to long delays in writing BatchRequests. [#1483](https://github.com/microsoftgraph/msgraph-sdk-java-core/issues/1483)

## [3.1.1] - 2024-02-09

### Changed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph
mavenArtifactId = microsoft-graph-core
mavenMajorVersion = 3
mavenMinorVersion = 1
mavenPatchVersion = 1
mavenPatchVersion = 2
mavenArtifactSuffix =

#These values are used to run functional tests
Expand Down
20 changes: 10 additions & 10 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'
testImplementation 'org.mockito:mockito-inline:5.2.0'
testImplementation 'io.opentelemetry:opentelemetry-api:1.34.1'
testImplementation 'io.opentelemetry:opentelemetry-context:1.34.1'
testImplementation 'io.opentelemetry:opentelemetry-api:1.35.0'
testImplementation 'io.opentelemetry:opentelemetry-context:1.35.0'
testImplementation 'io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha'
testImplementation 'io.github.std-uritemplate:std-uritemplate:0.0.50'
testImplementation 'io.github.std-uritemplate:std-uritemplate:0.0.52'

implementation 'com.google.code.gson:gson:2.10.1'

Expand All @@ -16,11 +16,11 @@ dependencies {
api 'com.squareup.okhttp3:okhttp:4.12.0'
api 'com.azure:azure-core:1.46.0'

api 'com.microsoft.kiota:microsoft-kiota-abstractions:1.0.0'
implementation 'com.microsoft.kiota:microsoft-kiota-authentication-azure:1.0.0'
implementation 'com.microsoft.kiota:microsoft-kiota-http-okHttp:1.0.0'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-json:1.0.0'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-text:1.0.0'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-form:1.0.0'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-multipart:1.0.0'
api 'com.microsoft.kiota:microsoft-kiota-abstractions:1.0.1'
implementation 'com.microsoft.kiota:microsoft-kiota-authentication-azure:1.0.1'
implementation 'com.microsoft.kiota:microsoft-kiota-http-okHttp:1.0.1'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-json:1.0.1'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-text:1.0.1'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-form:1.0.1'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-multipart:1.0.1'
}
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/graph/core/CoreConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private CoreConstants() {}
private static class VersionValues {
private static final int MAJOR = 3;
private static final int MINOR = 1;
private static final int PATCH = 0;
private static final int PATCH = 2;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public InputStream getBatchRequestContent() throws IOException {
return in;
}
}
private static final String AUTHORIZATION_HEADER_KEY = "authorization";
private void writeBatchRequestStep(BatchRequestStep requestStep, JsonWriter writer) throws IOException {
Request request = requestStep.getRequest();
writer.beginObject();
Expand Down Expand Up @@ -208,10 +209,13 @@ private void writeBatchRequestStep(BatchRequestStep requestStep, JsonWriter writ
writer.value(rawBodyContent);
}
}
//Remove the header if it is some version of 'authorization'
//RemoveAll utilizes ignoreCase natively
headers = headers.newBuilder().removeAll(AUTHORIZATION_HEADER_KEY).build();
if(headers.size() != 0 || requestBody != null) {
writer.name(CoreConstants.BatchRequest.HEADERS);
writer.beginObject();
for(int i = 0; i < headers.size(); i++) {
for (int i = 0; i < headers.size(); i++) {
writer.name(headers.name(i)).value(headers.value(i));
}
writer.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.microsoft.kiota.RequestInformation;
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;

import com.microsoft.kiota.authentication.AuthenticationProvider;
import com.microsoft.kiota.http.OkHttpRequestAdapter;
import com.microsoft.kiota.http.middleware.UrlReplaceHandler;
import okhttp3.*;
import org.junit.jupiter.api.Assertions;
Expand All @@ -25,6 +27,7 @@

import static com.microsoft.graph.core.CoreConstants.ReplacementConstants.USERS_ENDPOINT_WITH_REPLACE_TOKEN;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

class BatchRequestContentTest {
static final String requestUrl = "https://graph.microsoft.com/v1.0"+USERS_ENDPOINT_WITH_REPLACE_TOKEN;
Expand Down Expand Up @@ -234,6 +237,61 @@ void BatchRequestContent_GetBatchRequestContentFromStepDoesNotModifyDateTimes()
assertEquals(expectedJson, requestContentString);
}
@Test
void BatchRequestContent_DoNotAddAuthorizationHeader() throws Exception {
OkHttpRequestAdapter adapter = new OkHttpRequestAdapter(mock(AuthenticationProvider.class));

String expectedJson = "{\n" +
" \"requests\": [\n" +
" {\n" +
" \"id\": \"1\",\n" +
" \"url\": \"/me\",\n" +
" \"method\": \"GET\",\n" +
" \"headers\": {\n" +
" \"accept\": \"application/json\"\n" +
" }\n" +
" },\n" +
" {\n" +
" \"id\": \"2\",\n" +
" \"url\": \"/me\",\n" +
" \"method\": \"GET\"\n" +
" }\n" +
" ]\n" +
"}";
//The following string is the same size as a token
String longBearerString = "bbcbbbcbccbbabbacbccccbccabbcacacaaabccbccbbbbaabbabcccccbcbcacbbccbcbcaaacaacccacccbabacccabbccbccacccabcbbbbbacaacccabaaacaabcbacbaabcacabcbaaaccaccbbaaaabbbabbcaabbacccccaabbcabbbbbbbaaababaaabbbbcbbbcacbaaccaccabbcbabbabacbcccacbaccacaacaaacbacbaaaacbcbbacbcaaaaabcababbbcaabaaaabaaccbaccaababcbccbbacbaaabcbcbcbaaabcccabcacbbcbbabcccaccbacaaccaaaabcaacaccababbcbcabbccbaaaaaacccbcbccbaaccabbacbaaaacaccabcbbbcaabccccbbabbccaaaccbbbabbabcbcabcbccabbaabaacaaabbacaaccbcabaaaabcaabbabccabbcabcabbbaaaacccbcbcbbaacbbbbbcbbabcbabcbbcbbbaacccaababaccbaabcccccabbcabcababacbcaacbbaabaaacaabbacabcbcabcaabcccccacbaaacccbcabacbcbbbcccaaabacccaabcbcaababaabbacacabcbccacbbcacbbcaaccbbbcccbaaaacbcacabbcaaaacbcaacaccccbbaaabcccaacbabbbcbbccbacabccabaabacbbbbbcbaaaaaccabcbccabcccbcccabababbbbcbbcbbcbcabaabaabccbabcbbbabaaacaaaabcbcabaccaaaaacbaaabcbaccbaccbabacbcabbcbcbbaabbbbccaacccaabacacbabbcacabcbaccbcacbccaabcbbacbacbacbbaaccaaaaccacbcababccccccbbcbacacaaabaaaccbaabaacccbaaabcbcaabaaaaabcabacbabcbbccccbacbaabccaaabcccbbacbbacacaccabbcaacbbbbcbcbbcaabaacbbbcbbcbaaacccbacbaabacacbbabcaaaacaabacbaacaaaabbcacbacbcccacbcabcccacacaaccbbbcaacabcccaaacbabaaccbcbaacacbacaababcabcbccabcabcccaacabacabccaacbbcabbcaacbccaababacccaccabacbbbaabaccbcabcaabbcccacccbcbcabbccabbabaaaccacccbcbacabcaabcaccbbcbaaacbaabbbbcbccbbcccaababababaabacccbbbcabbaaacbcaaabccbbbccabbbcccbcacacaaabbabcacbacaacbbbcbbbbbccabbbabcabbcbacccaaabaaacbaabbacabbabcbcbcacbbaabbabcbcaacbabbcccbabaaccabbacbcaaacabbbbcaacbccbbbbacbcabbbaabcacaaabaabbaaccabbcabcabbacaaaacacabbabccacbbabbbbcabbaaccabcccaabbaaaacaabcbacabbaacaccbbbbaaaaacbcbacbbaaaabbabcaacaaacbbaabcccbbcbaacabbbbcaccaaaabcacbcbaaabbbcabcabcbbbbacbaccaacbccaacbbcaccaaaaacbabbbcbcbacbacbaccaacbcbcbbcaaaabaaabaabccaaaabbcabaaabcbcccbbcbaacacbbacacbabbcbaccabacbabcbcaabbbaabccccccaaccbcbccccbbbbcabaaacbbbaacbbaccaabcbcaacaacaacacaababcccbacbbccccbcacbcbcaacaaaacccccccaccaababaacbaabbcbbbccaacbabbcbcaaabbccacbbaabbbbcbbccbcccbbcacabaaacbacacbcaaabcbccacacccbbaacbacbbcbabbcbbbbcaccbaaccbcbcaabcababcbbbcccbcbaababcacbacbbbacacacabbccabbbaaaaacaccbbccbccbabaababcbbccabcaaacaccacabbaabacacabaccabacbacabbccbabaccbabcccbbcbbbaaabbccabbcbbbacacbbbabbcbbacbcabacaccabbbcbabbcbcacbcbbabbbbcabcbbabbbcaaccbaaaaccbababbbaabcbbbaacabbbbcabcabbcabbacabbccccaabaaaaabbcbabacbacbabcabcccabbbccbbcccaacacaabbcbabcbabaaaababbbacabaacbabbabcbbbcbccbacbcbccbbbccccbacaccbaccaaabbaacbbaaabbbcaccbabbcccbbbbccacbbaaacabbbbaabbabcccabcbcbbccccbacccabbbaaabcacccaabbabaccccbbbcccccaacbbbccbcabbbcccababbbcacccccccabccbbcaabccbbbaaccabbcaabcacabbcbbabcccaccccaaacbbbccaaabcbacabbbacbaccaabcbabababbcbcacaabcaabcbcbbcaaacaacabaaababbbacaccababaccbacacacacacbcccbabcbabcabccbaabcccababcbacbccccccacacbbacccccbaccbacaacbacacbcccccaaaacbaaaaccbacbbcacccbbbaabaaaccaccbcabcccccacaaaabcbabbacbbbcaaababcbacccbabcbaaabbcbaaacaabbcaaccaaccbacbaaaaaaabbaacaaabacbbcaacaacabbcabaccaaacbaccccbcccbcbcaaacbacaacccaccaacabacaaaabbbbbbbcacacbabccacacabbbababbbbcbabaaacaaacbacbcabbccacaacccbbbcbbacaccbbbaaabababbcbaacbcabcabaaccbcaaacbbbaacacccbbcaabcbacabbccbcbbbabbbaabacacaccaabbcbbaccbaaabcabbababaccca";
RequestInformation requestInfo = new RequestInformation();
requestInfo.urlTemplate = "{+baseurl}/users/{user%2Did}{?%24expand,%24select}";
HashMap<String, Object> pathParameters = new HashMap<>();
pathParameters.put("baseurl", "https://graph.microsoft.com/v1.0");
pathParameters.put("user%2Did", "TokenToReplace");
requestInfo.pathParameters = pathParameters;
requestInfo.httpMethod = HttpMethod.GET;
// Only one header should be present in the headers object of the Json Body
requestInfo.headers.add("accept", "application/json");
requestInfo.headers.add("authorization", longBearerString);
RequestInformation requestInfo2 = new RequestInformation();
requestInfo2.urlTemplate = "{+baseurl}/users/{user%2Did}{?%24expand,%24select}";
HashMap<String, Object> pathParameters2 = new HashMap<>();
pathParameters2.put("baseurl", "https://graph.microsoft.com/v1.0");
pathParameters2.put("user%2Did", "TokenToReplace");
requestInfo2.pathParameters = pathParameters2;
requestInfo2.httpMethod = HttpMethod.GET;
// No headers object should be present in the Json body
requestInfo2.headers.add("AuthoriZation", longBearerString); // Test with strange casing

BatchRequestContent batchRequestContent = new BatchRequestContent(client);
batchRequestContent.addBatchRequestStep(new BatchRequestStep("1",adapter.convertToNativeRequest(requestInfo)));
batchRequestContent.addBatchRequestStep(new BatchRequestStep("2",adapter.convertToNativeRequest(requestInfo2)));

InputStream stream = batchRequestContent.getBatchRequestContent();
String requestContentString = readInputStream(stream);
requestContentString = requestContentString.replace("\n", "").replaceAll("\\s", "");
expectedJson = expectedJson.replace("\n", "").replaceAll("\\s", "");

assertNotNull(requestContentString);
assertEquals(expectedJson, requestContentString);
}
@Test
void BatchRequestContent_AddBatchRequestStepWithHttpRequestMessage() {
BatchRequestContent batchRequestContent = new BatchRequestContent(client);
assertTrue(batchRequestContent.getBatchRequestSteps().isEmpty());
Expand All @@ -248,6 +306,7 @@ void BatchRequestContent_AddBatchRequestStepWithHttpRequestMessage() {
Assertions.assertEquals(batchRequestContent.getBatchRequestSteps().get(requestId).getRequest().url().uri().toString(), request.url().uri().toString());
Assertions.assertEquals(batchRequestContent.getBatchRequestSteps().get(requestId).getRequest().method(), request.method());
}

@Test
void BatchRequestContent_AddBatchRequestStepWithHttpRequestMessageToBatchRequestContentWithMaxSteps() {
BatchRequestContent batchRequestContent = new BatchRequestContent(client);
Expand Down

0 comments on commit a401657

Please sign in to comment.