Skip to content
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

fix ISession.CreateTime #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Nakama: `ISession.CreateTime` now accurately represents Unix time in seconds since the `ISession` object was created.

## [3.12.0] - 2024-04-08
### Added
Expand Down
1 change: 1 addition & 0 deletions Nakama.Tests/AuthenticateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public async Task ShouldAuthenticateCustomId()
Assert.NotNull(session.UserId);
Assert.NotNull(session.Username);
Assert.False(session.IsExpired);
Assert.Equal(DateTimeOffset.UtcNow.ToUnixTimeSeconds(), session.CreateTime);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may fail if the auth takes 1s to return, shouldn't happen but I wonder if there's a better way of testing time related assertions?

Copy link
Contributor Author

@lugehorsam lugehorsam Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sesposito session.CreateTime is actually not returned by the JWT from the server (unless you understand differently?); it's actually set on the session on the client after the server returns. So the chance of the values being unequal would be approx. 1 in a billion on most devs CPUs. That being said, could take a "before authentication" timestamp and "after authentication" timestamp and just ensure that the session.CreateTime falls within the range?

}

[Fact(Timeout = TestsUtil.TIMEOUT_MILLISECONDS)]
Expand Down
3 changes: 1 addition & 2 deletions Nakama/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public override string ToString()
internal Session(string authToken, string refreshToken, bool created)
{
Created = created;
var span = DateTime.UtcNow - Epoch;
CreateTime = span.Seconds;
CreateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
RefreshExpireTime = 0L;
Vars = new Dictionary<string, string>();

Expand Down
Loading