From 8c38cdfa5439192662c1d9b316114909738b0aa1 Mon Sep 17 00:00:00 2001 From: Joachim Bauch <bauch@struktur.de> Date: Wed, 15 Jan 2025 16:19:58 +0100 Subject: [PATCH] Add test for hello v2 token that was created not too far in the future. --- hub_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hub_test.go b/hub_test.go index 3af0cde..0d4bf48 100644 --- a/hub_test.go +++ b/hub_test.go @@ -933,6 +933,32 @@ func TestClientHelloV2(t *testing.T) { } func TestClientHelloV2_IssuedInFuture(t *testing.T) { + CatchLogForTest(t) + for _, algo := range testHelloV2Algorithms { + t.Run(algo, func(t *testing.T) { + require := require.New(t) + assert := assert.New(t) + hub, _, _, server := CreateHubForTest(t) + + client := NewTestClient(t, server, hub) + defer client.CloseWithBye() + + issuedAt := time.Now().Add(tokenLeeway / 2) + expiresAt := issuedAt.Add(time.Second) + require.NoError(client.SendHelloV2WithTimes(testDefaultUserId, issuedAt, expiresAt)) + + ctx, cancel := context.WithTimeout(context.Background(), testTimeout) + defer cancel() + + hello, err := client.RunUntilHello(ctx) + require.NoError(err) + assert.Equal(testDefaultUserId, hello.Hello.UserId, "%+v", hello.Hello) + assert.NotEmpty(hello.Hello.SessionId, "%+v", hello.Hello) + }) + } +} + +func TestClientHelloV2_IssuedFarInFuture(t *testing.T) { CatchLogForTest(t) for _, algo := range testHelloV2Algorithms { t.Run(algo, func(t *testing.T) {