Files
mtusi2026lab2/internal/platform/password/password_test.go
T
Vladislav Kunetskiy 1e38dbdf35
Application / Lint (pull_request) Canceled after 0s
Application / Unit tests (pull_request) Canceled after 0s
Application / Docker build (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
lab2
2026-10-06 18:58:40 +03:00

34 lines
917 B
Go

package password_test
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
"mtusi-messenger/internal/platform/password"
)
func TestHashVerifyRoundTrip(t *testing.T) {
encoded, err := password.Hash("very-secret-password")
require.NoError(t, err)
require.True(t, password.Verify("very-secret-password", encoded))
require.False(t, password.Verify("wrong-password-value", encoded))
}
func TestHashIsSalted(t *testing.T) {
first, err := password.Hash("very-secret-password")
require.NoError(t, err)
second, err := password.Hash("very-secret-password")
require.NoError(t, err)
require.NotEqual(t, first, second)
}
func TestVerifyRejectsMalformedHash(t *testing.T) {
require.False(t, password.Verify("very-secret-password", ""))
require.False(t, password.Verify("very-secret-password", "plain-text"))
require.False(t, password.Verify("very-secret-password", strings.Repeat("x", 64)))
}