Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b0f1552
Ensure authorization header is not added to BatchRequests
ramsessanchez Feb 8, 2024
09a6431
Merge branch 'dev' into rsh/batchHotFix
baywet Feb 9, 2024
f2023fd
remove authorization header
ramsessanchez Feb 9, 2024
16ce583
formating
ramsessanchez Feb 9, 2024
c0d3fb2
chore(deps): bump the kiota-dependencies group with 7 updates
dependabot[bot] Feb 12, 2024
01c7950
Merge pull request #1488 from microsoftgraph/dependabot/gradle/kiota-…
baywet Feb 12, 2024
7fa1383
chore(deps): bump io.github.std-uritemplate:std-uritemplate
dependabot[bot] Feb 12, 2024
6f8ec1f
Merge pull request #1490 from microsoftgraph/dependabot/gradle/io.git…
andrueastman Feb 12, 2024
d11a65a
chore(deps): bump io.opentelemetry:opentelemetry-api
dependabot[bot] Feb 12, 2024
237ddb5
Merge pull request #1491 from microsoftgraph/dependabot/gradle/io.ope…
andrueastman Feb 12, 2024
1be2c3b
chore(deps): bump io.opentelemetry:opentelemetry-context
dependabot[bot] Feb 12, 2024
10c1351
chore(deps): bump io.opentelemetry:opentelemetry-context in /android
dependabot[bot] Feb 12, 2024
7317ce8
Merge pull request #1489 from microsoftgraph/dependabot/gradle/io.ope…
andrueastman Feb 12, 2024
9249ecc
Merge pull request #1496 from microsoftgraph/dependabot/gradle/androi…
andrueastman Feb 12, 2024
5d2caa5
Merge branch 'dev' into rsh/batchHotFix
ramsessanchez Feb 12, 2024
aa7e6f7
Merge pull request #1484 from microsoftgraph/rsh/batchHotFix
ramsessanchez Feb 12, 2024
849b963
bump to 3.1.2
ramsessanchez Feb 12, 2024
3400523
Merge pull request #1499 from microsoftgraph/rsh/3.1.2vBump
ramsessanchez Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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