Compare commits
2
Commits
6da05c5d6c
..
next
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cf7059d3a | ||
|
|
2a2c52074d |
@@ -27,6 +27,12 @@ regress.
|
|||||||
and `.dockerignore` are always sent. An ignore file that cannot be read, or
|
and `.dockerignore` are always sent. An ignore file that cannot be read, or
|
||||||
holds a pattern Docker rejects, fails the build (#274).
|
holds a pattern Docker rejects, fails the build (#274).
|
||||||
|
|
||||||
|
- 2026-10-03: `make test`, and so `docker build .`, fits a machine with 4 GiB of
|
||||||
|
memory: tests hash passwords with 1 MiB instead of upaasd's 64 MiB, so
|
||||||
|
`GOMAXPROCS=4 make test` peaks at about 1.4 GiB instead of 2.7 GiB. upaasd
|
||||||
|
still hashes with 64 MiB, and one test hashes and verifies a password at that
|
||||||
|
cost (#261).
|
||||||
|
|
||||||
- 2026-10-02: In a window too narrow for the top bar, such as 390 px, the New
|
- 2026-10-02: In a window too narrow for the top bar, such as 390 px, the New
|
||||||
App and Logout buttons move to a second row instead of running into "by
|
App and Logout buttons move to a second row instead of running into "by
|
||||||
@sneak"; the bar keeps a gap between its two sides at every width (#272).
|
@sneak"; the bar keeps a gap between its two sides at every width (#272).
|
||||||
|
|||||||
@@ -60,6 +60,20 @@ func readDockerignore(contextDir, dockerfile string) ([]string, error) {
|
|||||||
|
|
||||||
defer func() { _ = root.Close() }()
|
defer func() { _ = root.Close() }()
|
||||||
|
|
||||||
|
// When a Dockerfile named Dockerfile is missing, Docker builds a
|
||||||
|
// lowercase dockerfile in the same directory instead, and docker build
|
||||||
|
// then reads dockerfile.dockerignore as its ignore file.
|
||||||
|
if filepath.Base(dockerfile) == defaultDockerfileName {
|
||||||
|
lowercase := filepath.Join(filepath.Dir(dockerfile), "dockerfile")
|
||||||
|
|
||||||
|
_, dockerfileErr := root.Lstat(dockerfile)
|
||||||
|
_, lowercaseErr := root.Lstat(lowercase)
|
||||||
|
|
||||||
|
if errors.Is(dockerfileErr, fs.ErrNotExist) && lowercaseErr == nil {
|
||||||
|
dockerfile = lowercase
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
name := dockerfile + defaultDockerignoreName
|
name := dockerfile + defaultDockerignoreName
|
||||||
|
|
||||||
file, err := root.Open(name)
|
file, err := root.Open(name)
|
||||||
|
|||||||
@@ -19,9 +19,10 @@ import (
|
|||||||
// File names used in more than one test build context, as constants to
|
// File names used in more than one test build context, as constants to
|
||||||
// satisfy the goconst linter.
|
// satisfy the goconst linter.
|
||||||
const (
|
const (
|
||||||
testMainGo = "main.go"
|
testMainGo = "main.go"
|
||||||
testSecretFile = "secret.txt"
|
testSecretFile = "secret.txt"
|
||||||
testDeployDockerfile = "deploy/Dockerfile"
|
testDeployDockerfile = "deploy/Dockerfile"
|
||||||
|
testLowercaseDockerfile = "dockerfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestPerformBuildFollowsDockerignore runs builds against a fake Docker API
|
// TestPerformBuildFollowsDockerignore runs builds against a fake Docker API
|
||||||
@@ -105,6 +106,62 @@ func TestPerformBuildFollowsDockerignore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestPerformBuildKeepsLowercaseDockerfile checks that when the Dockerfile
|
||||||
|
// named Dockerfile is missing, the lowercase dockerfile Docker builds instead
|
||||||
|
// stays in the build context, and its own ignore file is read.
|
||||||
|
func TestPerformBuildKeepsLowercaseDockerfile(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
files map[string]string // path in the context: contents
|
||||||
|
want []string // files sent in the build context
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "kept when the ignore file names it",
|
||||||
|
files: map[string]string{
|
||||||
|
defaultDockerignoreName: "*\n",
|
||||||
|
testLowercaseDockerfile: "",
|
||||||
|
},
|
||||||
|
want: []string{defaultDockerignoreName, testLowercaseDockerfile},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "its own ignore file wins over .dockerignore",
|
||||||
|
files: map[string]string{
|
||||||
|
defaultDockerignoreName: "main.go\n",
|
||||||
|
testLowercaseDockerfile: "",
|
||||||
|
"dockerfile.dockerignore": "secret.txt\n",
|
||||||
|
testMainGo: "",
|
||||||
|
testSecretFile: "",
|
||||||
|
},
|
||||||
|
want: []string{
|
||||||
|
defaultDockerignoreName,
|
||||||
|
testLowercaseDockerfile,
|
||||||
|
"dockerfile.dockerignore",
|
||||||
|
testMainGo,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
contextDir := t.TempDir()
|
||||||
|
writeFiles(t, contextDir, tt.files)
|
||||||
|
|
||||||
|
got, err := buildContextFiles(t, contextDir, defaultDockerfileName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !slices.Equal(got, tt.want) {
|
||||||
|
t.Errorf("build context holds %q, want %q", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestPerformBuildReadsDockerfilePathInsideContext checks that ./Dockerfile
|
// TestPerformBuildReadsDockerfilePathInsideContext checks that ./Dockerfile
|
||||||
// and /Dockerfile name the Dockerfile at the root of the context, as Docker
|
// and /Dockerfile name the Dockerfile at the root of the context, as Docker
|
||||||
// reads them, so an ignore file that names the Dockerfile does not leave it
|
// reads them, so an ignore file that names the Dockerfile does not leave it
|
||||||
|
|||||||
@@ -109,6 +109,9 @@ func createAppServices(
|
|||||||
})
|
})
|
||||||
require.NoError(t, authErr)
|
require.NoError(t, authErr)
|
||||||
|
|
||||||
|
// 1 MiB per password hash instead of 64 MiB; see auth.Service.ArgonMemory.
|
||||||
|
authSvc.ArgonMemory = 1024
|
||||||
|
|
||||||
appSvc, appErr := app.New(fx.Lifecycle(nil), app.ServiceParams{
|
appSvc, appErr := app.New(fx.Lifecycle(nil), app.ServiceParams{
|
||||||
Logger: logInstance,
|
Logger: logInstance,
|
||||||
Database: dbInstance,
|
Database: dbInstance,
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ type ServiceParams struct {
|
|||||||
|
|
||||||
// Service provides authentication functionality.
|
// Service provides authentication functionality.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
|
// ArgonMemory is the memory each argon2id hash takes, in KiB. New sets
|
||||||
|
// argonMemory, 64 MiB, and upaasd never changes it. Tests lower it, since
|
||||||
|
// many 64 MiB hashes at once under the race detector need more memory
|
||||||
|
// than a 4 GiB build machine has. A hash verifies only with the value it
|
||||||
|
// was made with.
|
||||||
|
ArgonMemory uint32
|
||||||
|
|
||||||
log *slog.Logger
|
log *slog.Logger
|
||||||
db *database.Database
|
db *database.Database
|
||||||
store *sessions.CookieStore
|
store *sessions.CookieStore
|
||||||
@@ -77,10 +84,11 @@ func New(_ fx.Lifecycle, params ServiceParams) (*Service, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Service{
|
return &Service{
|
||||||
log: params.Logger.Get(),
|
ArgonMemory: argonMemory,
|
||||||
db: params.Database,
|
log: params.Logger.Get(),
|
||||||
store: store,
|
db: params.Database,
|
||||||
params: ¶ms,
|
store: store,
|
||||||
|
params: ¶ms,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +105,7 @@ func (svc *Service) HashPassword(password string) (string, error) {
|
|||||||
[]byte(password),
|
[]byte(password),
|
||||||
salt,
|
salt,
|
||||||
argonTime,
|
argonTime,
|
||||||
argonMemory,
|
svc.ArgonMemory,
|
||||||
argonThreads,
|
argonThreads,
|
||||||
argonKeyLen,
|
argonKeyLen,
|
||||||
)
|
)
|
||||||
@@ -132,7 +140,7 @@ func (svc *Service) VerifyPassword(hashedPassword, password string) bool {
|
|||||||
[]byte(password),
|
[]byte(password),
|
||||||
salt,
|
salt,
|
||||||
argonTime,
|
argonTime,
|
||||||
argonMemory,
|
svc.ArgonMemory,
|
||||||
argonThreads,
|
argonThreads,
|
||||||
argonKeyLen,
|
argonKeyLen,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ func setupTestService(t *testing.T) (*auth.Service, func()) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// 1 MiB per hash instead of 64 MiB; see Service.ArgonMemory. The tests
|
||||||
|
// that use setupAuthService keep 64 MiB.
|
||||||
|
svc.ArgonMemory = 1024
|
||||||
|
|
||||||
// t.TempDir() automatically cleans up after test
|
// t.TempDir() automatically cleans up after test
|
||||||
cleanup := func() {}
|
cleanup := func() {}
|
||||||
|
|
||||||
@@ -237,6 +241,21 @@ func TestVerifyPassword(testingT *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestHashPasswordWithUpaasdMemory hashes and verifies a password with the
|
||||||
|
// memory New sets, which upaasd uses. setupTestService lowers it.
|
||||||
|
func TestHashPasswordWithUpaasdMemory(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
svc := setupAuthService(t, false)
|
||||||
|
require.Equal(t, uint32(64*1024), svc.ArgonMemory)
|
||||||
|
|
||||||
|
hash, err := svc.HashPassword("correctpassword")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.True(t, svc.VerifyPassword(hash, "correctpassword"))
|
||||||
|
assert.False(t, svc.VerifyPassword(hash, "wrongpassword"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestIsSetupRequired(testingT *testing.T) {
|
func TestIsSetupRequired(testingT *testing.T) {
|
||||||
testingT.Parallel()
|
testingT.Parallel()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user