mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* Replace hardcoded test passwords with model.NewTestPassword() Add model.NewTestPassword() utility that generates 14+ character passwords meeting complexity requirements for FIPS compliance. Replace all short hardcoded test passwords across the test suite with calls to this function. * Enforce FIPS compliance for passwords and HMAC keys FIPS OpenSSL requires HMAC keys to be at least 14 bytes. PBKDF2 uses the password as the HMAC key internally, so short passwords cause PKCS5_PBKDF2_HMAC to fail. - Add FIPSEnabled and PasswordFIPSMinimumLength build-tag constants - Raise the password minimum length floor to 14 when compiled with requirefips, applied in SetDefaults only when unset and validated independently in IsValid - Return ErrMismatchedHashAndPassword for too-short passwords in PBKDF2 CompareHashAndPassword rather than a cryptic OpenSSL error - Validate atmos/camo HMAC key length under FIPS and lengthen test keys accordingly - Adjust password validation tests to use PasswordFIPSMinimumLength so they work under both FIPS and non-FIPS builds * CI: shard FIPS test suite and extract merge template Run FIPS tests on PRs that touch go.mod or have 'fips' in the branch name. Shard FIPS tests across 4 runners matching the normal Postgres suite. Extract the test result merge logic into a reusable workflow template to deduplicate the normal and FIPS merge jobs. * more * Fix email test helper to respect FIPS minimum password length * Fix test helpers to respect FIPS minimum password length * Remove unnecessary "disable strict password requirements" blocks from test helpers * Fix CodeRabbit review comments on PR #35905 - Add server-test-merge-template.yml to server-ci.yml pull_request.paths so changes to the reusable merge workflow trigger Server CI validation - Skip merge-postgres-fips-test-results job when test-postgres-normal-fips was skipped, preventing failures due to missing artifacts - Set guest.Password on returned guest in CreateGuestAndClient helper to keep contract consistent with CreateUserWithClient - Use shared LowercaseLetters/UppercaseLetters/NUMBERS/PasswordFIPSMinimumLength constants in NewTestPassword() to avoid drift if FIPS floor changes * Rename FIPS test artifact to match server-ci-report pattern The server-ci-report job searches for artifacts matching "*-test-logs", so rename from postgres-server-test-logs-fips to postgres-server-fips-test-logs to be included in the report. --------- Co-authored-by: Hanzo Dev <[email protected]>
88 lines
2.4 KiB
Go
88 lines
2.4 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
//go:build !production
|
|
|
|
package hashers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSetTestHasher(t *testing.T) {
|
|
// Ensure testHasher starts as nil
|
|
SetTestHasher(nil)
|
|
|
|
// Hash should work with nil testHasher (uses latestHasher)
|
|
hash1, err := Hash("T3stP@ssw0rd!xYz")
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, hash1)
|
|
|
|
// Set a fast test hasher
|
|
fastHasher := FastTestHasher()
|
|
SetTestHasher(fastHasher)
|
|
defer SetTestHasher(nil)
|
|
|
|
// Hash should now use the fast test hasher
|
|
hash2, err := Hash("T3stP@ssw0rd!xYz")
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, hash2)
|
|
|
|
// Verify the hash was generated with different parameters
|
|
// The fast hasher uses the FIPS-minimum work factor.
|
|
require.Contains(t, hash2, ",w=1000,")
|
|
|
|
// Verify the password can be verified against the hash
|
|
hasher, phc, err := GetHasherFromPHCString(hash2)
|
|
require.NoError(t, err)
|
|
require.NoError(t, hasher.CompareHashAndPassword(phc, "T3stP@ssw0rd!xYz"))
|
|
require.Error(t, hasher.CompareHashAndPassword(phc, "Wr0ngP@ssw0rd!!"))
|
|
}
|
|
|
|
func TestFastTestHasher(t *testing.T) {
|
|
hasher := FastTestHasher()
|
|
require.NotNil(t, hasher)
|
|
|
|
// Verify it's a PBKDF2 hasher with the FIPS-minimum work factor.
|
|
pbkdf2Hasher, ok := hasher.(PBKDF2)
|
|
require.True(t, ok, "FastTestHasher should return a PBKDF2 hasher")
|
|
require.Equal(t, fastTestHasherWorkFactor, pbkdf2Hasher.workFactor)
|
|
|
|
// Test that it produces valid hashes
|
|
testPassword := "T3stP@ssw0rd!xYz"
|
|
hash, err := hasher.Hash(testPassword)
|
|
require.NoError(t, err)
|
|
require.Contains(t, hash, ",w=1000,")
|
|
|
|
// Verify the hash can be validated
|
|
parsedHasher, phc, err := GetHasherFromPHCString(hash)
|
|
require.NoError(t, err)
|
|
require.NoError(t, parsedHasher.CompareHashAndPassword(phc, testPassword))
|
|
}
|
|
|
|
func TestGetLatestHasher(t *testing.T) {
|
|
// Ensure testHasher starts as nil
|
|
SetTestHasher(nil)
|
|
|
|
// Without test hasher, should return latestHasher
|
|
require.Equal(t, latestHasher, GetLatestHasher())
|
|
|
|
// Set a fast test hasher
|
|
fastHasher := FastTestHasher()
|
|
SetTestHasher(fastHasher)
|
|
defer SetTestHasher(nil)
|
|
|
|
// With test hasher set, should return the test hasher
|
|
require.Equal(t, fastHasher, GetLatestHasher())
|
|
require.NotEqual(t, latestHasher, GetLatestHasher())
|
|
}
|
|
|
|
func BenchmarkFastTestHasher(b *testing.B) {
|
|
hasher := FastTestHasher()
|
|
for b.Loop() {
|
|
_, _ = hasher.Hash("password")
|
|
}
|
|
}
|