satellite/{console,db}: allow passphrasepromt toggling
This change adds the user's passphrase prompt setting to the /account/settings endpoints. Issue: https://github.com/storj/storj/issues/5616 Change-Id: I48d470d49e82096fd090b74da323b279e342546e
This commit is contained in:
parent
d8081169cd
commit
bf05040dd6
@ -973,6 +973,7 @@ func (a *Auth) SetUserSettings(w http.ResponseWriter, r *http.Request) {
|
||||
var updateInfo struct {
|
||||
OnboardingStart *bool `json:"onboardingStart"`
|
||||
OnboardingEnd *bool `json:"onboardingEnd"`
|
||||
PassphrasePrompt *bool `json:"passphrasePrompt"`
|
||||
OnboardingStep *string `json:"onboardingStep"`
|
||||
SessionDuration *int64 `json:"sessionDuration"`
|
||||
}
|
||||
@ -996,6 +997,7 @@ func (a *Auth) SetUserSettings(w http.ResponseWriter, r *http.Request) {
|
||||
OnboardingStart: updateInfo.OnboardingStart,
|
||||
OnboardingEnd: updateInfo.OnboardingEnd,
|
||||
OnboardingStep: updateInfo.OnboardingStep,
|
||||
PassphrasePrompt: updateInfo.PassphrasePrompt,
|
||||
SessionDuration: newDuration,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -103,37 +103,37 @@ func TestAuth(t *testing.T) {
|
||||
}
|
||||
|
||||
{ // Test_UserSettings
|
||||
testGetSettings := func(expected struct {
|
||||
type expectedSettings struct {
|
||||
SessionDuration *time.Duration
|
||||
OnboardingStart bool
|
||||
OnboardingEnd bool
|
||||
PassphrasePrompt bool
|
||||
OnboardingStep *string
|
||||
}) {
|
||||
}
|
||||
testGetSettings := func(expected expectedSettings) {
|
||||
resp, body := test.request(http.MethodGet, "/auth/account/settings", nil)
|
||||
|
||||
var settings struct {
|
||||
SessionDuration *time.Duration
|
||||
OnboardingStart bool
|
||||
OnboardingEnd bool
|
||||
PassphrasePrompt bool
|
||||
OnboardingStep *string
|
||||
}
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
require.NoError(test.t, json.Unmarshal([]byte(body), &settings))
|
||||
require.Equal(test.t, expected.OnboardingStart, settings.OnboardingStart)
|
||||
require.Equal(test.t, expected.OnboardingEnd, settings.OnboardingEnd)
|
||||
require.Equal(test.t, expected.PassphrasePrompt, settings.PassphrasePrompt)
|
||||
require.Equal(test.t, expected.OnboardingStep, settings.OnboardingStep)
|
||||
require.Equal(test.t, expected.SessionDuration, settings.SessionDuration)
|
||||
}
|
||||
|
||||
testGetSettings(struct {
|
||||
SessionDuration *time.Duration
|
||||
OnboardingStart bool
|
||||
OnboardingEnd bool
|
||||
OnboardingStep *string
|
||||
}{
|
||||
testGetSettings(expectedSettings{
|
||||
SessionDuration: nil,
|
||||
OnboardingStart: true,
|
||||
OnboardingEnd: true,
|
||||
PassphrasePrompt: true,
|
||||
OnboardingStep: nil,
|
||||
})
|
||||
|
||||
@ -144,19 +144,16 @@ func TestAuth(t *testing.T) {
|
||||
"sessionDuration": duration,
|
||||
"onboardingStart": true,
|
||||
"onboardingEnd": false,
|
||||
"passphrasePrompt": false,
|
||||
"onboardingStep": step,
|
||||
}))
|
||||
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
testGetSettings(struct {
|
||||
SessionDuration *time.Duration
|
||||
OnboardingStart bool
|
||||
OnboardingEnd bool
|
||||
OnboardingStep *string
|
||||
}{
|
||||
testGetSettings(expectedSettings{
|
||||
SessionDuration: &duration,
|
||||
OnboardingStart: true,
|
||||
OnboardingEnd: false,
|
||||
PassphrasePrompt: false,
|
||||
OnboardingStep: &step,
|
||||
})
|
||||
|
||||
@ -170,15 +167,11 @@ func TestAuth(t *testing.T) {
|
||||
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
// having passed nil to /auth/account/settings shouldn't have changed existing values.
|
||||
testGetSettings(struct {
|
||||
SessionDuration *time.Duration
|
||||
OnboardingStart bool
|
||||
OnboardingEnd bool
|
||||
OnboardingStep *string
|
||||
}{
|
||||
testGetSettings(expectedSettings{
|
||||
SessionDuration: &duration,
|
||||
OnboardingStart: true,
|
||||
OnboardingEnd: false,
|
||||
PassphrasePrompt: false,
|
||||
OnboardingStep: &step,
|
||||
})
|
||||
|
||||
@ -189,12 +182,7 @@ func TestAuth(t *testing.T) {
|
||||
}))
|
||||
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
testGetSettings(struct {
|
||||
SessionDuration *time.Duration
|
||||
OnboardingStart bool
|
||||
OnboardingEnd bool
|
||||
OnboardingStep *string
|
||||
}{
|
||||
testGetSettings(expectedSettings{
|
||||
SessionDuration: nil,
|
||||
OnboardingStart: true,
|
||||
OnboardingEnd: false,
|
||||
|
@ -254,6 +254,7 @@ type UserSettings struct {
|
||||
SessionDuration *time.Duration `json:"sessionDuration"`
|
||||
OnboardingStart bool `json:"onboardingStart"`
|
||||
OnboardingEnd bool `json:"onboardingEnd"`
|
||||
PassphrasePrompt bool `json:"passphrasePrompt"`
|
||||
OnboardingStep *string `json:"onboardingStep"`
|
||||
}
|
||||
|
||||
@ -263,5 +264,6 @@ type UpsertUserSettingsRequest struct {
|
||||
SessionDuration **time.Duration
|
||||
OnboardingStart *bool
|
||||
OnboardingEnd *bool
|
||||
PassphrasePrompt *bool
|
||||
OnboardingStep *string
|
||||
}
|
||||
|
@ -302,6 +302,10 @@ func (users *users) GetSettings(ctx context.Context, userID uuid.UUID) (settings
|
||||
settings.OnboardingStart = row.OnboardingStart
|
||||
settings.OnboardingEnd = row.OnboardingEnd
|
||||
settings.OnboardingStep = row.OnboardingStep
|
||||
settings.PassphrasePrompt = true
|
||||
if row.PassphrasePrompt != nil {
|
||||
settings.PassphrasePrompt = *row.PassphrasePrompt
|
||||
}
|
||||
if row.SessionMinutes != nil {
|
||||
dur := time.Duration(*row.SessionMinutes) * time.Minute
|
||||
settings.SessionDuration = &dur
|
||||
@ -334,6 +338,10 @@ func (users *users) UpsertSettings(ctx context.Context, userID uuid.UUID, settin
|
||||
update.OnboardingEnd = dbx.UserSettings_OnboardingEnd(*settings.OnboardingEnd)
|
||||
fieldCount++
|
||||
}
|
||||
if settings.PassphrasePrompt != nil {
|
||||
update.PassphrasePrompt = dbx.UserSettings_PassphrasePrompt(*settings.PassphrasePrompt)
|
||||
fieldCount++
|
||||
}
|
||||
if settings.OnboardingStep != nil {
|
||||
update.OnboardingStep = dbx.UserSettings_OnboardingStep(*settings.OnboardingStep)
|
||||
fieldCount++
|
||||
|
@ -363,5 +363,26 @@ func TestUserSettings(t *testing.T) {
|
||||
require.Equal(t, newBool, settings.OnboardingEnd)
|
||||
require.Equal(t, &newStep, settings.OnboardingStep)
|
||||
})
|
||||
|
||||
t.Run("test passphrase prompt", func(t *testing.T) {
|
||||
id = testrand.UUID()
|
||||
require.NoError(t, users.UpsertSettings(ctx, id, console.UpsertUserSettingsRequest{}))
|
||||
settings, err := users.GetSettings(ctx, id)
|
||||
require.NoError(t, err)
|
||||
require.True(t, settings.PassphrasePrompt)
|
||||
|
||||
newBool := false
|
||||
require.NoError(t, users.UpsertSettings(ctx, id, console.UpsertUserSettingsRequest{
|
||||
PassphrasePrompt: &newBool,
|
||||
}))
|
||||
settings, err = users.GetSettings(ctx, id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newBool, settings.PassphrasePrompt)
|
||||
|
||||
require.NoError(t, users.UpsertSettings(ctx, id, console.UpsertUserSettingsRequest{}))
|
||||
settings, err = users.GetSettings(ctx, id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newBool, settings.PassphrasePrompt)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user