forked from Silverfish/proton-bridge
GODT-1351: Cache and update of space bytes in user object.
This commit is contained in:
@ -3,27 +3,37 @@
|
||||
"user": {
|
||||
"ID": "1",
|
||||
"Name": "user",
|
||||
"MaxUpload": 26214400
|
||||
"MaxUpload": 26214400,
|
||||
"UsedSpace": 1048576,
|
||||
"MaxSpace": 10485760
|
||||
},
|
||||
"user2fa": {
|
||||
"ID": "2",
|
||||
"Name": "user2fa",
|
||||
"MaxUpload": 26214400
|
||||
"MaxUpload": 26214400,
|
||||
"UsedSpace": 1048576,
|
||||
"MaxSpace": 10485760
|
||||
},
|
||||
"userAddressWithCapitalLetter": {
|
||||
"ID": "3",
|
||||
"Name": "userAddressWithCapitalLetter",
|
||||
"MaxUpload": 26214400
|
||||
"MaxUpload": 26214400,
|
||||
"UsedSpace": 1048576,
|
||||
"MaxSpace": 10485760
|
||||
},
|
||||
"userMoreAddresses": {
|
||||
"ID": "4",
|
||||
"Name": "userMoreAddresses",
|
||||
"MaxUpload": 26214400
|
||||
"MaxUpload": 26214400,
|
||||
"UsedSpace": 1048576,
|
||||
"MaxSpace": 10485760
|
||||
},
|
||||
"userDisabledPrimaryAddress": {
|
||||
"ID": "5",
|
||||
"Name": "userDisabledPrimaryAddress",
|
||||
"MaxUpload": 26214400
|
||||
"MaxUpload": 26214400,
|
||||
"UsedSpace": 1048576,
|
||||
"MaxSpace": 10485760
|
||||
}
|
||||
},
|
||||
"addresses": {
|
||||
|
||||
@ -85,6 +85,14 @@ func (api *FakePMAPI) UpdateUser(context.Context) (*pmapi.User, error) {
|
||||
return api.user, nil
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) GetUser(ctx context.Context) (*pmapi.User, error) {
|
||||
if err := api.checkAndRecordCall(GET, "/users", nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return api.user, nil
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) GetAddresses(context.Context) (pmapi.AddressList, error) {
|
||||
if err := api.checkAndRecordCall(GET, "/addresses", nil); err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -6,6 +6,7 @@ Feature: Start bridge
|
||||
Then "user" is connected
|
||||
And "user" has loaded store
|
||||
And "user" has running event loop
|
||||
And "user" has non-zero space
|
||||
|
||||
Scenario: Start with connected user, database file and no internet connection
|
||||
Given there is user "user" which just logged in
|
||||
@ -15,6 +16,7 @@ Feature: Start bridge
|
||||
Then "user" is connected
|
||||
And "user" has loaded store
|
||||
And "user" has running event loop
|
||||
And "user" has zero space
|
||||
|
||||
Scenario: Start with connected user, no database file and internet connection
|
||||
Given there is user "user" which just logged in
|
||||
@ -23,6 +25,7 @@ Feature: Start bridge
|
||||
Then "user" is connected
|
||||
And "user" has loaded store
|
||||
And "user" has running event loop
|
||||
And "user" has non-zero space
|
||||
|
||||
Scenario: Start with connected user, no database file and no internet connection
|
||||
Given there is user "user" which just logged in
|
||||
@ -37,6 +40,7 @@ Feature: Start bridge
|
||||
Then "user" is connected
|
||||
And "user" has loaded store
|
||||
And "user" has running event loop
|
||||
And "user" has non-zero space
|
||||
|
||||
Scenario: Start with disconnected user, database file and internet connection
|
||||
Given there is disconnected user "user"
|
||||
@ -45,6 +49,7 @@ Feature: Start bridge
|
||||
Then "user" is disconnected
|
||||
And "user" has loaded store
|
||||
And "user" does not have running event loop
|
||||
And "user" has zero space
|
||||
|
||||
Scenario: Start with disconnected user, database file and no internet connection
|
||||
Given there is disconnected user "user"
|
||||
@ -54,6 +59,7 @@ Feature: Start bridge
|
||||
Then "user" is disconnected
|
||||
And "user" has loaded store
|
||||
And "user" does not have running event loop
|
||||
And "user" has zero space
|
||||
|
||||
Scenario: Start with disconnected user, no database file and internet connection
|
||||
Given there is disconnected user "user"
|
||||
@ -62,6 +68,7 @@ Feature: Start bridge
|
||||
Then "user" is disconnected
|
||||
And "user" does not have loaded store
|
||||
And "user" does not have running event loop
|
||||
And "user" has zero space
|
||||
|
||||
Scenario: Start with disconnected user, no database file and no internet connection
|
||||
Given there is disconnected user "user"
|
||||
@ -71,3 +78,4 @@ Feature: Start bridge
|
||||
Then "user" is disconnected
|
||||
And "user" does not have loaded store
|
||||
And "user" does not have running event loop
|
||||
And "user" has zero space
|
||||
|
||||
@ -6,6 +6,7 @@ Feature: Login for the first time
|
||||
And "user" is connected
|
||||
And "user" has database file
|
||||
And "user" has running event loop
|
||||
And "user" has non-zero space
|
||||
|
||||
@ignore-live
|
||||
Scenario: Login with bad username
|
||||
@ -31,6 +32,7 @@ Feature: Login for the first time
|
||||
And "user2fa" is connected
|
||||
And "user2fa" has database file
|
||||
And "user2fa" has running event loop
|
||||
And "user2fa" has non-zero space
|
||||
|
||||
Scenario: Login user with capital letters in address
|
||||
Given there is user "userAddressWithCapitalLetter"
|
||||
@ -39,6 +41,7 @@ Feature: Login for the first time
|
||||
And "userAddressWithCapitalLetter" is connected
|
||||
And "userAddressWithCapitalLetter" has database file
|
||||
And "userAddressWithCapitalLetter" has running event loop
|
||||
And "userAddressWithCapitalLetter" has non-zero space
|
||||
|
||||
Scenario: Login user with more addresses
|
||||
Given there is user "userMoreAddresses"
|
||||
@ -47,6 +50,7 @@ Feature: Login for the first time
|
||||
And "userMoreAddresses" is connected
|
||||
And "userMoreAddresses" has database file
|
||||
And "userMoreAddresses" has running event loop
|
||||
And "userMoreAddresses" has non-zero space
|
||||
|
||||
@ignore-live
|
||||
Scenario: Login user with disabled primary address
|
||||
@ -56,6 +60,7 @@ Feature: Login for the first time
|
||||
And "userDisabledPrimaryAddress" is connected
|
||||
And "userDisabledPrimaryAddress" has database file
|
||||
And "userDisabledPrimaryAddress" has running event loop
|
||||
And "userDisabledPrimaryAddress" has non-zero space
|
||||
|
||||
Scenario: Login two users
|
||||
Given there is user "user"
|
||||
|
||||
@ -6,6 +6,7 @@ Feature: Re-login
|
||||
Then last response is "failed to finish login: user is already connected"
|
||||
And "user" is connected
|
||||
And "user" has running event loop
|
||||
And "user" has non-zero space
|
||||
|
||||
@ignore
|
||||
Scenario: Re-login with connected user and no database file
|
||||
@ -24,6 +25,7 @@ Feature: Re-login
|
||||
Then last response is "OK"
|
||||
And "user" is connected
|
||||
And "user" has running event loop
|
||||
And "user" has non-zero space
|
||||
|
||||
Scenario: Re-login with disconnected user and no database file
|
||||
Given there is disconnected user "user"
|
||||
@ -33,3 +35,4 @@ Feature: Re-login
|
||||
And "user" is connected
|
||||
And "user" has database file
|
||||
And "user" has running event loop
|
||||
And "user" has non-zero space
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/ProtonMail/go-srp"
|
||||
@ -84,7 +83,7 @@ func (pc *persistentClient) GetEvent(ctx context.Context, eventID string) (*pmap
|
||||
}
|
||||
|
||||
func SetupPersistentClients() {
|
||||
app := os.Getenv("TEST_APP")
|
||||
app := "bridge"
|
||||
|
||||
persistentClients.manager = pmapi.New(pmapi.NewConfig(app, constants.Version))
|
||||
persistentClients.manager.SetLogging(logrus.WithField("pkg", "liveapi"), logrus.GetLevel() == logrus.TraceLevel)
|
||||
|
||||
@ -34,6 +34,8 @@ func UsersChecksFeatureContext(s *godog.ScenarioContext) {
|
||||
s.Step(`^"([^"]*)" does not have loaded store$`, userDoesNotHaveLoadedStore)
|
||||
s.Step(`^"([^"]*)" has running event loop$`, userHasRunningEventLoop)
|
||||
s.Step(`^"([^"]*)" does not have running event loop$`, userDoesNotHaveRunningEventLoop)
|
||||
s.Step(`^"([^"]*)" has non-zero space$`, userHasNonZeroSpace)
|
||||
s.Step(`^"([^"]*)" has zero space$`, userHasZeroSpace)
|
||||
}
|
||||
|
||||
func userHasAddressModeInMode(bddUserID, wantAddressMode string) error {
|
||||
@ -162,3 +164,26 @@ func userDoesNotHaveRunningEventLoop(bddUserID string) error {
|
||||
}, 5*time.Second, 10*time.Millisecond)
|
||||
return ctx.GetTestingError()
|
||||
}
|
||||
|
||||
func userHasSpace(bddUserID string, wantNonZero bool) error {
|
||||
account := ctx.GetTestAccount(bddUserID)
|
||||
if account == nil {
|
||||
return godog.ErrPending
|
||||
}
|
||||
|
||||
user, err := ctx.GetUser(account.Username())
|
||||
if err != nil {
|
||||
return internalError(err, "getting user %s", account.Username())
|
||||
}
|
||||
|
||||
// We should only test `user.TotalBytes()>0` and not test
|
||||
// `user.UsedBytes()>0`. The later value can be always zero when
|
||||
// account is empty even when user object had already cached the value
|
||||
// from server.
|
||||
a.Equal(ctx.GetTestingT(), wantNonZero, user.TotalBytes() > 0)
|
||||
|
||||
return ctx.GetTestingError()
|
||||
}
|
||||
|
||||
func userHasNonZeroSpace(bddUserID string) error { return userHasSpace(bddUserID, true) }
|
||||
func userHasZeroSpace(bddUserID string) error { return userHasSpace(bddUserID, false) }
|
||||
|
||||
Reference in New Issue
Block a user