Skip to content

Commit

Permalink
Add DeviceID to login opts (#693)
Browse files Browse the repository at this point in the history
Co-authored-by: Kegan Dougal <=>
  • Loading branch information
kegsay authored Nov 22, 2023
1 parent f8f2b2a commit 25a2d5c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions helpers/clientopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type RegistrationOpts struct {

type LoginOpts struct {
Password string // default 'complement_meets_min_password_requirement'
DeviceID string // default '' (generate new)
}
19 changes: 12 additions & 7 deletions internal/docker/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,27 @@ func (d *Deployment) Login(t *testing.T, hsName string, existing *client.CSAPI,
if err != nil {
t.Fatalf("Deployment.Login: existing CSAPI client has invalid user ID '%s', cannot login as this user: %s", existing.UserID, err)
}
client := &client.CSAPI{
c := &client.CSAPI{
BaseURL: dep.BaseURL,
Client: client.NewLoggedClient(t, hsName, nil),
SyncUntilTimeout: 5 * time.Second,
Debug: d.Deployer.debugLogging,
}
// Appending a slice is not thread-safe. Protect the write with a mutex.
dep.CSAPIClientsMutex.Lock()
dep.CSAPIClients = append(dep.CSAPIClients, client)
dep.CSAPIClients = append(dep.CSAPIClients, c)
dep.CSAPIClientsMutex.Unlock()
userID, accessToken, deviceID := client.LoginUser(t, localpart, opts.Password)
var userID, accessToken, deviceID string
if opts.DeviceID == "" {
userID, accessToken, deviceID = c.LoginUser(t, localpart, opts.Password)
} else {
userID, accessToken, deviceID = c.LoginUser(t, localpart, opts.Password, client.WithDeviceID(opts.DeviceID))
}

client.UserID = userID
client.AccessToken = accessToken
client.DeviceID = deviceID
return client
c.UserID = userID
c.AccessToken = accessToken
c.DeviceID = deviceID
return c
}

func (d *Deployment) Network() string {
Expand Down

0 comments on commit 25a2d5c

Please sign in to comment.