Skip to content

Commit

Permalink
Serialize timestamps as seconds since Unix epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
heaths committed Aug 28, 2019
1 parent 0e7ec14 commit b3fd4ae
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ internal void ReadProperties(JsonElement json)

if (json.TryGetProperty("nbf", out JsonElement nbf))
{
NotBefore = DateTimeOffset.FromUnixTimeMilliseconds(nbf.GetInt64());
NotBefore = DateTimeOffset.FromUnixTimeSeconds(nbf.GetInt64());
}

if (json.TryGetProperty("exp", out JsonElement exp))
{
Expires = DateTimeOffset.FromUnixTimeMilliseconds(exp.GetInt64());
Expires = DateTimeOffset.FromUnixTimeSeconds(exp.GetInt64());
}

if (json.TryGetProperty("created", out JsonElement created))
{
Created = DateTimeOffset.FromUnixTimeMilliseconds(created.GetInt64());
Created = DateTimeOffset.FromUnixTimeSeconds(created.GetInt64());
}

if (json.TryGetProperty("updated", out JsonElement updated))
{
Updated = DateTimeOffset.FromUnixTimeMilliseconds(updated.GetInt64());
Updated = DateTimeOffset.FromUnixTimeSeconds(updated.GetInt64());
}

if (json.TryGetProperty("recoveryLevel", out JsonElement recoveryLevel))
Expand All @@ -87,12 +87,12 @@ internal void WriteProperties(ref Utf8JsonWriter json)

if (NotBefore.HasValue)
{
json.WriteNumber("nbf", NotBefore.Value.ToUnixTimeMilliseconds());
json.WriteNumber("nbf", NotBefore.Value.ToUnixTimeSeconds());
}

if (Expires.HasValue)
{
json.WriteNumber("exp", Expires.Value.ToUnixTimeMilliseconds());
json.WriteNumber("exp", Expires.Value.ToUnixTimeSeconds());
}

// Created is read-only don't serialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Azure.Security.KeyVault.Secrets;
using Azure.Core.Testing;
using System.Text;
using NUnit.Framework.Constraints;

namespace Azure.Security.KeyVault.Test
{
Expand Down Expand Up @@ -54,12 +54,13 @@ public async Task SetSecret()
public async Task SetSecretWithExtendedProps()
{
string secretName = Recording.GenerateId();
IResolveConstraint createdUpdatedConstraint = Is.EqualTo(DateTimeOffset.FromUnixTimeSeconds(1565114301));

Secret setResult = null;

try
{
var exp = new DateTimeOffset(new DateTime(637027248124480000, DateTimeKind.Utc));
var exp = new DateTimeOffset(new DateTime(637027248120000000, DateTimeKind.Utc));
var nbf = exp.AddDays(-30);

var secret = new Secret(secretName, "CrudWithExtendedPropsValue1")
Expand All @@ -75,6 +76,11 @@ public async Task SetSecretWithExtendedProps()
};

setResult = await Client.SetAsync(secret);
if (Mode != RecordedTestMode.Playback)
{
DateTimeOffset now = DateTimeOffset.UtcNow;
createdUpdatedConstraint = Is.InRange(now.AddMinutes(-5), now.AddMinutes(5));
}

RegisterForCleanup(secret, delete: false);

Expand All @@ -89,8 +95,8 @@ public async Task SetSecretWithExtendedProps()
Assert.AreEqual("CrudWithExtendedPropsValue1", setResult.Value);
Assert.AreEqual(VaultUri, setResult.Vault);
Assert.AreEqual("Recoverable+Purgeable", setResult.RecoveryLevel);
Assert.NotNull(setResult.Created);
Assert.NotNull(setResult.Updated);
Assert.That(setResult.Created, createdUpdatedConstraint);
Assert.That(setResult.Updated, createdUpdatedConstraint);

Secret getResult = await Client.GetAsync(secretName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5570,7 +5570,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "1711",
"Content-Length": "1705",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:55:13 GMT",
"Expires": "-1",
Expand Down Expand Up @@ -5618,7 +5618,7 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002fStorageAccountPasswor9ebbe6fa-3561-4517-a621-58b8bc2335b7",
"attributes": {
"enabled": true,
"exp": 1596705801020,
"exp": 1596705801,
"created": 1565083401,
"updated": 1565083401,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand All @@ -5631,7 +5631,7 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002fStorageAccountPassworf3fb75f6-140a-4670-bec9-3730167cfe9e",
"attributes": {
"enabled": true,
"exp": 1596674204723,
"exp": 1596674204,
"created": 1565051805,
"updated": 1565051805,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5570,7 +5570,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "1711",
"Content-Length": "1705",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 18:00:35 GMT",
"Expires": "-1",
Expand Down Expand Up @@ -5618,7 +5618,7 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002fStorageAccountPasswor9ebbe6fa-3561-4517-a621-58b8bc2335b7",
"attributes": {
"enabled": true,
"exp": 1596705801020,
"exp": 1596705801,
"created": 1565083401,
"updated": 1565083401,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand All @@ -5631,7 +5631,7 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002fStorageAccountPassworf3fb75f6-140a-4670-bec9-3730167cfe9e",
"attributes": {
"enabled": true,
"exp": 1596674204723,
"exp": 1596674204,
"created": 1565051805,
"updated": 1565051805,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"RequestHeaders": {
"Accept": "application\u002fjson",
"Authorization": "Sanitized",
"Content-Length": "160",
"Content-Length": "154",
"Content-Type": "application\u002fjson",
"Request-Id": "|42981ca-4c61899ebaa789f5.",
"User-Agent": [
Expand All @@ -61,8 +61,8 @@
"value": "CrudWithExtendedPropsValue1",
"contentType": "password",
"attributes": {
"nbf": 1564536012448,
"exp": 1567128012448
"nbf": 1564536012,
"exp": 1567128012
},
"tags": {
"tag1": "value1",
Expand All @@ -72,7 +72,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "356",
"Content-Length": "350",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:58:21 GMT",
"Expires": "-1",
Expand All @@ -93,8 +93,8 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002f1518274412\u002fc2d12adc8ef047dab96b268a694ea990",
"attributes": {
"enabled": true,
"nbf": 1564536012448,
"exp": 1567128012448,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565114301,
"updated": 1565114301,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand Down Expand Up @@ -124,7 +124,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "356",
"Content-Length": "350",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:58:21 GMT",
"Expires": "-1",
Expand All @@ -145,8 +145,8 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002f1518274412\u002fc2d12adc8ef047dab96b268a694ea990",
"attributes": {
"enabled": true,
"nbf": 1564536012448,
"exp": 1567128012448,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565114301,
"updated": 1565114301,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand Down Expand Up @@ -176,7 +176,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "456",
"Content-Length": "450",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 17:58:21 GMT",
"Expires": "-1",
Expand All @@ -199,8 +199,8 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002f1518274412\u002fc2d12adc8ef047dab96b268a694ea990",
"attributes": {
"enabled": true,
"nbf": 1564536012448,
"exp": 1567128012448,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565114301,
"updated": 1565114301,
"recoveryLevel": "Recoverable\u002bPurgeable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"RequestHeaders": {
"Accept": "application\u002fjson",
"Authorization": "Sanitized",
"Content-Length": "160",
"Content-Length": "154",
"Content-Type": "application\u002fjson",
"Request-Id": "|42984ad-4c61899ebaa789f5.",
"User-Agent": [
Expand All @@ -61,8 +61,8 @@
"value": "CrudWithExtendedPropsValue1",
"contentType": "password",
"attributes": {
"nbf": 1564536012448,
"exp": 1567128012448
"nbf": 1564536012,
"exp": 1567128012
},
"tags": {
"tag1": "value1",
Expand All @@ -72,7 +72,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "356",
"Content-Length": "350",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 18:03:23 GMT",
"Expires": "-1",
Expand All @@ -93,10 +93,10 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002f1963134935\u002f451bdb9ada314902bcef2374b9d44eff",
"attributes": {
"enabled": true,
"nbf": 1564536012448,
"exp": 1567128012448,
"created": 1565114603,
"updated": 1565114603,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565114301,
"updated": 1565114301,
"recoveryLevel": "Recoverable\u002bPurgeable"
},
"tags": {
Expand Down Expand Up @@ -124,7 +124,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "356",
"Content-Length": "350",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 18:03:23 GMT",
"Expires": "-1",
Expand All @@ -145,10 +145,10 @@
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002f1963134935\u002f451bdb9ada314902bcef2374b9d44eff",
"attributes": {
"enabled": true,
"nbf": 1564536012448,
"exp": 1567128012448,
"created": 1565114603,
"updated": 1565114603,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565114301,
"updated": 1565114301,
"recoveryLevel": "Recoverable\u002bPurgeable"
},
"tags": {
Expand Down Expand Up @@ -176,7 +176,7 @@
"StatusCode": 200,
"ResponseHeaders": {
"Cache-Control": "no-cache",
"Content-Length": "456",
"Content-Length": "450",
"Content-Type": "application\u002fjson; charset=utf-8",
"Date": "Tue, 06 Aug 2019 18:03:23 GMT",
"Expires": "-1",
Expand All @@ -193,16 +193,16 @@
},
"ResponseBody": {
"recoveryId": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fdeletedsecrets\u002f1963134935",
"deletedDate": 1565114603,
"deletedDate": 1565114301,
"scheduledPurgeDate": 1572890603,
"contentType": "password",
"id": "https:\u002f\u002fdotnettestvault.vault.azure.net\u002fsecrets\u002f1963134935\u002f451bdb9ada314902bcef2374b9d44eff",
"attributes": {
"enabled": true,
"nbf": 1564536012448,
"exp": 1567128012448,
"created": 1565114603,
"updated": 1565114603,
"nbf": 1564536012,
"exp": 1567128012,
"created": 1565114301,
"updated": 1565114301,
"recoveryLevel": "Recoverable\u002bPurgeable"
},
"tags": {
Expand Down

0 comments on commit b3fd4ae

Please sign in to comment.