From 9ce4e4458794290755c68a180125acc68ab84038 Mon Sep 17 00:00:00 2001 From: Jeroen Wijenbergh Date: Wed, 8 May 2024 11:49:19 +0200 Subject: Server: Add a way to pass OAuth start time --- client/client.go | 10 ++++++---- client/client_test.go | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'client') diff --git a/client/client.go b/client/client.go index 7a6747b..291b190 100644 --- a/client/client.go +++ b/client/client.go @@ -302,9 +302,11 @@ func (c *Client) TrySave() { } // AddServer adds a server with identifier and type -func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes.Type, ni bool) (err error) { +func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes.Type, ot *int64) (err error) { c.mu.Lock() defer c.mu.Unlock() + // we are non-interactive if oauth time is non-nil + ni := ot != nil // If we have failed to add the server, we remove it again // We add the server because we can then obtain it in other callback functions previousState := c.FSM.Current @@ -335,17 +337,17 @@ func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes. switch _type { case srvtypes.TypeInstituteAccess: - err = c.Servers.AddInstitute(ck.Context(), c.cfg.Discovery(), identifier, ni) + err = c.Servers.AddInstitute(ck.Context(), c.cfg.Discovery(), identifier, ot) if err != nil { return i18nerr.Wrapf(err, "The institute access server with URL: '%s' could not be added", identifier) } case srvtypes.TypeSecureInternet: - err = c.Servers.AddSecure(ck.Context(), c.cfg.Discovery(), identifier, ni) + err = c.Servers.AddSecure(ck.Context(), c.cfg.Discovery(), identifier, ot) if err != nil { return i18nerr.Wrapf(err, "The secure internet server with organisation ID: '%s' could not be added", identifier) } case srvtypes.TypeCustom: - err = c.Servers.AddCustom(ck.Context(), identifier, ni) + err = c.Servers.AddCustom(ck.Context(), identifier, ot) if err != nil { return i18nerr.Wrapf(err, "The custom server with URL: '%s' could not be added", identifier) } diff --git a/client/client_test.go b/client/client_test.go index a221c93..4afcff5 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -95,7 +95,7 @@ func TestServer(t *testing.T) { t.Fatalf("Registering error: %v", err) } - addErr := state.AddServer(ck, serverURI, srvtypes.TypeCustom, false) + addErr := state.AddServer(ck, serverURI, srvtypes.TypeCustom, nil) if addErr != nil { t.Fatalf("Add error: %v", addErr) } @@ -143,7 +143,7 @@ func TestTokenExpired(t *testing.T) { t.Fatalf("Registering error: %v", err) } - addErr := state.AddServer(ck, serverURI, srvtypes.TypeCustom, false) + addErr := state.AddServer(ck, serverURI, srvtypes.TypeCustom, nil) if addErr != nil { t.Fatalf("Add error: %v", addErr) } @@ -202,7 +202,7 @@ func TestInvalidProfileCorrected(t *testing.T) { t.Fatalf("Registering error: %v", err) } - addErr := state.AddServer(ck, serverURI, srvtypes.TypeCustom, false) + addErr := state.AddServer(ck, serverURI, srvtypes.TypeCustom, nil) if addErr != nil { t.Fatalf("Add error: %v", addErr) } @@ -259,7 +259,8 @@ func TestConfigStartup(t *testing.T) { t.Fatalf("Failed to register with error: %v", err) } // we set true as last argument here such that no callbacks are ran - err = state.AddServer(ck, serverURI, srvtypes.TypeCustom, true) + var ot int64 = 5 + err = state.AddServer(ck, serverURI, srvtypes.TypeCustom, &ot) if err != nil { t.Fatalf("Failed to add server for trying config startup: %v", err) } @@ -319,7 +320,7 @@ func TestPreferTCP(t *testing.T) { t.Fatalf("Registering error: %v", err) } - addErr := state.AddServer(ck, serverURI, srvtypes.TypeCustom, false) + addErr := state.AddServer(ck, serverURI, srvtypes.TypeCustom, nil) if addErr != nil { t.Fatalf("Add error: %v", addErr) } -- cgit v1.2.3