summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroenwijenbergh@protonmail.com>2024-05-08 11:49:19 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-05-08 13:54:45 +0000
commit9ce4e4458794290755c68a180125acc68ab84038 (patch)
treed4211e55bd77d07938651619733c7b435597d53a /client
parent580f94b4023fba35ab2f58d2e6d7b3b7c40ec139 (diff)
Server: Add a way to pass OAuth start time
Diffstat (limited to 'client')
-rw-r--r--client/client.go10
-rw-r--r--client/client_test.go11
2 files changed, 12 insertions, 9 deletions
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)
}