forked from Silverfish/proton-bridge
GODT-2041: Crash after factory reset
I forgot to remove the user from the users map during factory reset. This meant the (deleted) would attempt to be closed during teardown.
This commit is contained in:
@ -421,6 +421,27 @@ func TestBridge_AddressWithoutKeys(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBridge_FactoryReset(t *testing.T) {
|
||||||
|
withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) {
|
||||||
|
withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) {
|
||||||
|
// Login the user.
|
||||||
|
userID, err := bridge.LoginFull(ctx, username, password, nil, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// The user is now connected.
|
||||||
|
require.Equal(t, []string{userID}, bridge.GetUserIDs())
|
||||||
|
require.Equal(t, []string{userID}, getConnectedUserIDs(t, bridge))
|
||||||
|
|
||||||
|
// Perform a factory reset.
|
||||||
|
bridge.FactoryReset(ctx)
|
||||||
|
|
||||||
|
// The user is gone.
|
||||||
|
require.Equal(t, []string{}, bridge.GetUserIDs())
|
||||||
|
require.Equal(t, []string{}, getConnectedUserIDs(t, bridge))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// withEnv creates the full test environment and runs the tests.
|
// withEnv creates the full test environment and runs the tests.
|
||||||
func withEnv(t *testing.T, tests func(context.Context, *server.Server, *proton.NetCtl, bridge.Locator, []byte), opts ...server.Option) {
|
func withEnv(t *testing.T, tests func(context.Context, *server.Server, *proton.NetCtl, bridge.Locator, []byte), opts ...server.Option) {
|
||||||
server := server.New(opts...)
|
server := server.New(opts...)
|
||||||
|
|||||||
@ -223,8 +223,6 @@ func (bridge *Bridge) LogoutUser(ctx context.Context, userID string) error {
|
|||||||
return ErrNoSuchUser
|
return ErrNoSuchUser
|
||||||
}
|
}
|
||||||
|
|
||||||
defer delete(bridge.users, user.ID())
|
|
||||||
|
|
||||||
bridge.logoutUser(ctx, user, true, false)
|
bridge.logoutUser(ctx, user, true, false)
|
||||||
|
|
||||||
bridge.publish(events.UserLoggedOut{
|
bridge.publish(events.UserLoggedOut{
|
||||||
@ -245,7 +243,6 @@ func (bridge *Bridge) DeleteUser(ctx context.Context, userID string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if user, ok := bridge.users[userID]; ok {
|
if user, ok := bridge.users[userID]; ok {
|
||||||
defer delete(bridge.users, user.ID())
|
|
||||||
bridge.logoutUser(ctx, user, true, true)
|
bridge.logoutUser(ctx, user, true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,6 +525,8 @@ func (bridge *Bridge) newVaultUser(
|
|||||||
|
|
||||||
// logout logs out the given user, optionally logging them out from the API too.
|
// logout logs out the given user, optionally logging them out from the API too.
|
||||||
func (bridge *Bridge) logoutUser(ctx context.Context, user *user.User, withAPI, withData bool) {
|
func (bridge *Bridge) logoutUser(ctx context.Context, user *user.User, withAPI, withData bool) {
|
||||||
|
defer delete(bridge.users, user.ID())
|
||||||
|
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"userID": user.ID(),
|
"userID": user.ID(),
|
||||||
"withAPI": withAPI,
|
"withAPI": withAPI,
|
||||||
|
|||||||
@ -119,7 +119,6 @@ func (bridge *Bridge) handleUserRefreshed(ctx context.Context, user *user.User)
|
|||||||
|
|
||||||
func (bridge *Bridge) handleUserDeauth(ctx context.Context, user *user.User) {
|
func (bridge *Bridge) handleUserDeauth(ctx context.Context, user *user.User) {
|
||||||
safe.Lock(func() {
|
safe.Lock(func() {
|
||||||
defer delete(bridge.users, user.ID())
|
|
||||||
bridge.logoutUser(ctx, user, false, false)
|
bridge.logoutUser(ctx, user, false, false)
|
||||||
}, bridge.usersLock)
|
}, bridge.usersLock)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user