-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support AM/PM in MSI token #7356
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
694695e
Support AM/PM in MSI token
jianghaolu 3200005
Fix tests
jianghaolu 39be9f3
Use SerializerAdapter
jianghaolu 5b72fcc
opens implementation to jackson
jianghaolu 0363620
Remove deserialization in msi token test
jianghaolu 257ed68
Revert back to default locale
jianghaolu 568ca94
Remove unused import
jianghaolu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 48 additions & 0 deletions
48
...dentity/azure-identity/src/test/java/com/azure/identity/implementation/MSITokenTests.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,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.identity.implementation; | ||
|
||
import com.azure.core.util.serializer.JacksonAdapter; | ||
import com.azure.core.util.serializer.SerializerEncoding; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
|
||
public class MSITokenTests { | ||
private JacksonAdapter serializer = new JacksonAdapter(); | ||
private OffsetDateTime expected = OffsetDateTime.of(2020, 1, 10, 15, 1, 28, 0, ZoneOffset.UTC); | ||
|
||
@Test | ||
public void canParseLong() throws Exception { | ||
String json = "{\"access_token\":\"fake_token\",\"expires_on\":\"1578668608\"}"; | ||
MSIToken token = serializer.deserialize(json, MSIToken.class, SerializerEncoding.JSON); | ||
Assert.assertEquals(expected.toEpochSecond(), token.getExpiresAt().toEpochSecond()); | ||
} | ||
|
||
@Test | ||
public void canParseDateTime24Hr() throws Exception { | ||
String json = "{\"access_token\":\"fake_token\",\"expires_on\":\"01/10/2020 15:03:28 +00:00\"}"; | ||
MSIToken token = serializer.deserialize(json, MSIToken.class, SerializerEncoding.JSON); | ||
Assert.assertEquals(expected.toEpochSecond(), token.getExpiresAt().toEpochSecond()); | ||
} | ||
|
||
@Test | ||
public void canParseDateTime12Hr() throws Exception { | ||
String json = "{\"access_token\":\"fake_token\",\"expires_on\":\"1/10/2020 3:03:28 PM +00:00\"}"; | ||
MSIToken token = serializer.deserialize(json, MSIToken.class, SerializerEncoding.JSON); | ||
Assert.assertEquals(expected.toEpochSecond(), token.getExpiresAt().toEpochSecond()); | ||
|
||
json = "{\"access_token\":\"fake_token\",\"expires_on\":\"12/20/2019 4:58:20 AM +00:00\"}"; | ||
token = serializer.deserialize(json, MSIToken.class, SerializerEncoding.JSON); | ||
expected = OffsetDateTime.of(2019, 12, 20, 4, 56, 20, 0, ZoneOffset.UTC); | ||
Assert.assertEquals(expected.toEpochSecond(), token.getExpiresAt().toEpochSecond()); | ||
|
||
json = "{\"access_token\":\"fake_token\",\"expires_on\":\"1/1/2020 0:00:00 PM +00:00\"}"; | ||
token = serializer.deserialize(json, MSIToken.class, SerializerEncoding.JSON); | ||
expected = OffsetDateTime.of(2020, 1, 1, 11, 58, 0, 0, ZoneOffset.UTC); | ||
Assert.assertEquals(expected.toEpochSecond(), token.getExpiresAt().toEpochSecond()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a Breaking change ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in the implmentation package so we should be fine