diff --git a/util/secret/secret_test.go b/util/secret/secret_test.go index 24ca5d3d..84362f3a 100644 --- a/util/secret/secret_test.go +++ b/util/secret/secret_test.go @@ -5,17 +5,17 @@ import ( "strconv" "testing" - "github.com/R-a-dio/valkyrie/util/daypass" + "github.com/R-a-dio/valkyrie/util/secret" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestSecretKeyGeneration(t *testing.T) { - s1, err := daypass.NewSecret(16) + s1, err := secret.NewSecret(16) require.NoError(t, err) require.True(t, s1.Equal(s1.Get(nil), nil), "s1 should equal itself") - s2, err := daypass.NewSecret(16) + s2, err := secret.NewSecret(16) require.NoError(t, err) require.True(t, s2.Equal(s2.Get(nil), nil), "s2 should equal itself") @@ -27,7 +27,7 @@ func TestSecretKeyGeneration(t *testing.T) { func TestSecretSaltComparison(t *testing.T) { for i := 1; i < sha256.Size*2; i++ { t.Run(strconv.Itoa(i), func(t *testing.T) { - s, err := daypass.NewSecret(i) + s, err := secret.NewSecret(i) require.NoError(t, err) salt := []byte("testing world") diff --git a/website/admin/home.go b/website/admin/home.go index 13a91707..4675b4fe 100644 --- a/website/admin/home.go +++ b/website/admin/home.go @@ -3,19 +3,19 @@ package admin import ( "net/http" - "github.com/R-a-dio/valkyrie/util/daypass" + "github.com/R-a-dio/valkyrie/util/secret" "github.com/R-a-dio/valkyrie/website/middleware" ) type HomeInput struct { middleware.Input - Daypass daypass.DaypassInfo + Daypass string } -func NewHomeInput(r *http.Request, dp *daypass.Daypass) HomeInput { +func NewHomeInput(r *http.Request, dp secret.Secret) HomeInput { return HomeInput{ Input: middleware.InputFromRequest(r), - Daypass: dp.Info(), + Daypass: dp.Get(nil), } } diff --git a/website/admin/router.go b/website/admin/router.go index 1e6a0b67..e2789e29 100644 --- a/website/admin/router.go +++ b/website/admin/router.go @@ -9,7 +9,7 @@ import ( radio "github.com/R-a-dio/valkyrie" "github.com/R-a-dio/valkyrie/config" "github.com/R-a-dio/valkyrie/templates" - "github.com/R-a-dio/valkyrie/util/daypass" + "github.com/R-a-dio/valkyrie/util/secret" vmiddleware "github.com/R-a-dio/valkyrie/website/middleware" "github.com/R-a-dio/valkyrie/website/shared" "github.com/spf13/afero" @@ -21,7 +21,7 @@ import ( func NewState( _ context.Context, cfg config.Config, - dp *daypass.Daypass, + dp secret.Secret, newsCache *shared.NewsCache, storage radio.StorageService, search radio.SearchService, @@ -48,7 +48,7 @@ func NewState( type State struct { config.Config - Daypass *daypass.Daypass + Daypass secret.Secret News *shared.NewsCache Storage radio.StorageService Search radio.SearchService diff --git a/website/main.go b/website/main.go index b4a05876..69bf27b1 100644 --- a/website/main.go +++ b/website/main.go @@ -15,7 +15,7 @@ import ( "github.com/R-a-dio/valkyrie/storage" "github.com/R-a-dio/valkyrie/templates" "github.com/R-a-dio/valkyrie/util" - "github.com/R-a-dio/valkyrie/util/daypass" + "github.com/R-a-dio/valkyrie/util/secret" "github.com/R-a-dio/valkyrie/website/admin" phpapi "github.com/R-a-dio/valkyrie/website/api/php" v1 "github.com/R-a-dio/valkyrie/website/api/v1" @@ -67,7 +67,10 @@ func Execute(ctx context.Context, cfg config.Config) error { } executor := siteTemplates.Executor() // daypass generation - dpass := daypass.New(ctx) + dpass, err := secret.NewSecret(secret.DaypassLength) + if err != nil { + return errors.E(op, err) + } // search service searchService, err := search.Open(ctx, cfg) if err != nil { diff --git a/website/public/state.go b/website/public/state.go index d1a11231..bf6a1fb8 100644 --- a/website/public/state.go +++ b/website/public/state.go @@ -7,7 +7,7 @@ import ( radio "github.com/R-a-dio/valkyrie" "github.com/R-a-dio/valkyrie/config" "github.com/R-a-dio/valkyrie/templates" - "github.com/R-a-dio/valkyrie/util/daypass" + "github.com/R-a-dio/valkyrie/util/secret" "github.com/R-a-dio/valkyrie/website/shared" "github.com/rs/zerolog/hlog" @@ -17,7 +17,7 @@ import ( func NewState( ctx context.Context, cfg config.Config, - dp *daypass.Daypass, + dp secret.Secret, newsCache *shared.NewsCache, exec templates.Executor, manager radio.ManagerService, @@ -40,7 +40,7 @@ func NewState( type State struct { config.Config - Daypass *daypass.Daypass + Daypass secret.Secret News *shared.NewsCache Templates templates.Executor Manager radio.ManagerService diff --git a/website/public/submit.go b/website/public/submit.go index b57ae38e..f070fbc2 100644 --- a/website/public/submit.go +++ b/website/public/submit.go @@ -15,7 +15,7 @@ import ( "github.com/R-a-dio/valkyrie/errors" "github.com/R-a-dio/valkyrie/streamer/audio" "github.com/R-a-dio/valkyrie/util" - "github.com/R-a-dio/valkyrie/util/daypass" + "github.com/R-a-dio/valkyrie/util/secret" "github.com/R-a-dio/valkyrie/website/middleware" "github.com/rs/zerolog/hlog" ) @@ -89,7 +89,7 @@ func (s State) canSubmitSong(r *http.Request) (time.Duration, error) { } daypass := r.Header.Get(daypassHeader) - if s.Daypass.Is(daypass) { // daypass was used so can submit song + if s.Daypass.Equal(daypass, nil) { // daypass was used so can submit song return 0, nil } @@ -396,7 +396,7 @@ func NewSubmissionForm(tempdir string, mr *multipart.Reader) (*SubmissionForm, e // Validate checks if required fields are filled in the SubmissionForm and // if a daypass was supplied if it was a valid one. Populates sf.Errors with // any errors that occur and what input field caused it. -func (sf *SubmissionForm) Validate(ts radio.TrackStorage, dp *daypass.Daypass) bool { +func (sf *SubmissionForm) Validate(ts radio.TrackStorage, dp secret.Secret) bool { sf.Errors = make(map[string]string) if sf.File == "" { sf.Errors["track"] = "no temporary file" @@ -408,7 +408,7 @@ func (sf *SubmissionForm) Validate(ts radio.TrackStorage, dp *daypass.Daypass) b sf.Errors["comment"] = "no comment supplied" } if sf.Daypass != "" { - sf.IsDaypass = dp.Is(sf.Daypass) + sf.IsDaypass = dp.Equal(sf.Daypass, nil) if !sf.IsDaypass { sf.Errors["daypass"] = "daypass invalid" }