Revert the deliberate break; the password-cost check is an ordinary test (#8298, #8330)
release / web (push) Successful in 1m33s
release / go (push) Successful in 1m57s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 2m53s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 3m32s
release / Build signed APK (push) Canceled after 3m3s
release / web (push) Successful in 1m33s
release / go (push) Successful in 1m57s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 2m53s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 3m32s
release / Build signed APK (push) Canceled after 3m3s
Run 11288 failed every named test it reached. The api TestMain's cost
check exited the test binary, and the integration lane runs each package's
binary once with no tests to warm the build, so it stopped the lane there
before coverart's database tests ran. The check is now a test of its own:
a weakened cost fails one test and the rest of the lane still runs.
This reverts commit e717e4370d.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,23 +1,26 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// serverPasswordCost is the cost the server hashes stored passwords at,
|
||||||
|
// taken before TestMain lowers it.
|
||||||
|
var serverPasswordCost = passwordCost
|
||||||
|
|
||||||
// The tests hash passwords at bcrypt's lowest cost: what they check is which
|
// The tests hash passwords at bcrypt's lowest cost: what they check is which
|
||||||
// password is stored and who is signed out, not how slow a guess is. The
|
// password is stored and who is signed out, not how slow a guess is.
|
||||||
// cost the server uses is checked first, so lowering it here can't hide a
|
|
||||||
// weaker one there.
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
if passwordCost < bcrypt.DefaultCost {
|
|
||||||
fmt.Fprintf(os.Stderr, "passwordCost is %d; stored passwords need at least bcrypt.DefaultCost (%d)\n",
|
|
||||||
passwordCost, bcrypt.DefaultCost)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
passwordCost = bcrypt.MinCost
|
passwordCost = bcrypt.MinCost
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lowering the cost for the tests must not hide a weaker one in the server.
|
||||||
|
func TestPasswordCost_StoredPasswordsUseAtLeastBcryptsDefault(t *testing.T) {
|
||||||
|
if serverPasswordCost < bcrypt.DefaultCost {
|
||||||
|
t.Errorf("passwords are stored at bcrypt cost %d, want at least %d", serverPasswordCost, bcrypt.DefaultCost)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,8 +45,9 @@ func checkNewPassword(w http.ResponseWriter, pw string) bool {
|
|||||||
|
|
||||||
// passwordCost is bcrypt's work factor for stored passwords. The package's
|
// passwordCost is bcrypt's work factor for stored passwords. The package's
|
||||||
// tests lower it, since each hash at the default cost takes most of a second
|
// tests lower it, since each hash at the default cost takes most of a second
|
||||||
// under the race detector; their TestMain refuses a default below bcrypt's.
|
// under the race detector, and check first that this default is at least
|
||||||
var passwordCost = bcrypt.DefaultCost - 2 // DELIBERATE BREAK
|
// bcrypt's.
|
||||||
|
var passwordCost = bcrypt.DefaultCost
|
||||||
|
|
||||||
// hashPassword is the one place a password is hashed for storage.
|
// hashPassword is the one place a password is hashed for storage.
|
||||||
func hashPassword(pw string) ([]byte, error) {
|
func hashPassword(pw string) ([]byte, error) {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func (e *Enricher) EnrichArtist(ctx context.Context, artistID pgtype.UUID, dataD
|
|||||||
case "theaudiodb":
|
case "theaudiodb":
|
||||||
return nil
|
return nil
|
||||||
case "none":
|
case "none":
|
||||||
if row.ArtistArtSourcesVersion <= currentVersion { // DELIBERATE BREAK
|
if row.ArtistArtSourcesVersion == currentVersion {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := q.ClearArtistArtNone(ctx, artistID); err != nil {
|
if err := q.ClearArtistArtNone(ctx, artistID); err != nil {
|
||||||
@@ -127,7 +127,9 @@ func (e *Enricher) recordArtistArt(ctx context.Context, artistID pgtype.UUID, th
|
|||||||
if thumbPath != "" {
|
if thumbPath != "" {
|
||||||
thumbArg = &thumbPath
|
thumbArg = &thumbPath
|
||||||
}
|
}
|
||||||
fanartArg = &fanartPath // DELIBERATE BREAK
|
if fanartPath != "" {
|
||||||
|
fanartArg = &fanartPath
|
||||||
|
}
|
||||||
return pgx.BeginFunc(ctx, e.pool, func(tx pgx.Tx) error {
|
return pgx.BeginFunc(ctx, e.pool, func(tx pgx.Tx) error {
|
||||||
if err := dbq.New(tx).SetArtistArtWithVersion(ctx, dbq.SetArtistArtWithVersionParams{
|
if err := dbq.New(tx).SetArtistArtWithVersion(ctx, dbq.SetArtistArtWithVersionParams{
|
||||||
ID: artistID,
|
ID: artistID,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func init() {
|
|||||||
func (p *deezerProvider) ID() string { return "deezer" }
|
func (p *deezerProvider) ID() string { return "deezer" }
|
||||||
func (p *deezerProvider) DisplayName() string { return "Deezer" }
|
func (p *deezerProvider) DisplayName() string { return "Deezer" }
|
||||||
func (p *deezerProvider) RequiresAPIKey() bool { return false }
|
func (p *deezerProvider) RequiresAPIKey() bool { return false }
|
||||||
func (p *deezerProvider) DefaultEnabled() bool { return false } // DELIBERATE BREAK
|
func (p *deezerProvider) DefaultEnabled() bool { return true }
|
||||||
|
|
||||||
func (p *deezerProvider) Configure(s ProviderSettings) error {
|
func (p *deezerProvider) Configure(s ProviderSettings) error {
|
||||||
p.enabled.Store(s.Enabled)
|
p.enabled.Store(s.Enabled)
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func (p *lastfmProvider) currentKey() string {
|
|||||||
// it as thumb, leave fanart nil.
|
// it as thumb, leave fanart nil.
|
||||||
func (p *lastfmProvider) FetchArtistArt(ctx context.Context, ref ArtistRef) (thumb, fanart []byte, err error) {
|
func (p *lastfmProvider) FetchArtistArt(ctx context.Context, ref ArtistRef) (thumb, fanart []byte, err error) {
|
||||||
if !p.enabled.Load() || p.currentKey() == "" {
|
if !p.enabled.Load() || p.currentKey() == "" {
|
||||||
return nil, nil, ErrTransient // DELIBERATE BREAK
|
return nil, nil, ErrNotFound
|
||||||
}
|
}
|
||||||
if ref.MBID == "" && ref.Name == "" {
|
if ref.MBID == "" && ref.Name == "" {
|
||||||
return nil, nil, ErrNotFound
|
return nil, nil, ErrNotFound
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func Split(genre *string) []string {
|
|||||||
if genre == nil {
|
if genre == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
parts := strings.FieldsFunc(*genre, func(r rune) bool { return r == ';' /* DELIBERATE BREAK: commas no longer split */ })
|
parts := strings.FieldsFunc(*genre, func(r rune) bool { return r == ';' || r == ',' })
|
||||||
out := make([]string, 0, len(parts))
|
out := make([]string, 0, len(parts))
|
||||||
for _, p := range parts {
|
for _, p := range parts {
|
||||||
if p = strings.TrimSpace(p); p != "" {
|
if p = strings.TrimSpace(p); p != "" {
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ func (s *Server) Router() http.Handler {
|
|||||||
spa := web.Handler(s.BrandingCfg)
|
spa := web.Handler(s.BrandingCfg)
|
||||||
r.NotFound(func(w http.ResponseWriter, req *http.Request) {
|
r.NotFound(func(w http.ResponseWriter, req *http.Request) {
|
||||||
p := req.URL.Path
|
p := req.URL.Path
|
||||||
if strings.HasPrefix(p, "/api/") { // DELIBERATE BREAK: /rest/ falls to the web app
|
if strings.HasPrefix(p, "/api/") || strings.HasPrefix(p, "/rest/") {
|
||||||
apierror.Write(w, apierror.ErrNotFound)
|
apierror.Write(w, apierror.ErrNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,6 +164,5 @@ func decodePassword(p string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
_ = b
|
return string(b), nil
|
||||||
return p[4:], nil // DELIBERATE BREAK
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,8 +110,7 @@ func (h *userHandlers) getUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
WriteFail(w, r, ErrGeneric, "Failed to look up user")
|
WriteFail(w, r, ErrGeneric, "Failed to look up user")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Write(w, r, UserResponse{Envelope: NewEnvelope("ok"), User: userPayload(caller)}) // DELIBERATE BREAK; target: %v
|
Write(w, r, UserResponse{Envelope: NewEnvelope("ok"), User: userPayload(target)})
|
||||||
_ = target
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func userPayload(u dbq.User) User { return rolePayload(u.Username, u.IsAdmin) }
|
func userPayload(u dbq.User) User { return rolePayload(u.Username, u.IsAdmin) }
|
||||||
|
|||||||
Reference in New Issue
Block a user