mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-10-26 11:27:18 +00:00
home: add tests
This commit is contained in:
parent
586b714daf
commit
4633c8991c
52
internal/home/auth_internal_test.go
Normal file
52
internal/home/auth_internal_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package home
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghuser"
|
||||
"github.com/AdguardTeam/golibs/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func TestAuth_UsersList(t *testing.T) {
|
||||
const (
|
||||
userName = "name"
|
||||
userPassword = "password"
|
||||
)
|
||||
|
||||
passwordHash, err := bcrypt.GenerateFromPassword([]byte(userPassword), bcrypt.DefaultCost)
|
||||
require.NoError(t, err)
|
||||
|
||||
sessionsDB := filepath.Join(t.TempDir(), "sessions.db")
|
||||
|
||||
user := webUser{
|
||||
Name: userName,
|
||||
PasswordHash: string(passwordHash),
|
||||
UserID: aghuser.MustNewUserID(),
|
||||
}
|
||||
|
||||
auth, err := newAuth(testutil.ContextWithTimeout(t, testTimeout), &authConfig{
|
||||
baseLogger: testLogger,
|
||||
rateLimiter: emptyRateLimiter{},
|
||||
trustedProxies: nil,
|
||||
dbFilename: sessionsDB,
|
||||
users: nil,
|
||||
sessionTTL: testTimeout,
|
||||
isGLiNet: false,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() { auth.close(testutil.ContextWithTimeout(t, testTimeout)) })
|
||||
|
||||
ctx := testutil.ContextWithTimeout(t, testTimeout)
|
||||
|
||||
assert.Empty(t, auth.usersList(ctx))
|
||||
|
||||
err = auth.addUser(ctx, &user, userPassword)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []webUser{user}, auth.usersList(ctx))
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user