forked from mtusi2026/mtusi2026lab7
This commit is contained in:
@@ -16,7 +16,7 @@ func TestPasswordSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (s *PasswordSuite) SetupTest() {
|
||||
hasher, err := New(testConfig())
|
||||
hasher, err := New(testConfig(), 2)
|
||||
s.Require().NoError(err)
|
||||
s.hasher = hasher
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (s *PasswordSuite) TestNeedsRehashDetectsChangedParameters() {
|
||||
|
||||
legacyConfig := testConfig()
|
||||
legacyConfig.KeyLength = 16
|
||||
legacy, err := New(legacyConfig)
|
||||
legacy, err := New(legacyConfig, 2)
|
||||
s.Require().NoError(err)
|
||||
legacyHash, err := legacy.Hash("T3st-password-123")
|
||||
s.Require().NoError(err)
|
||||
@@ -57,12 +57,34 @@ func (s *PasswordSuite) TestNeedsRehashDetectsChangedParameters() {
|
||||
s.True(needsRehash)
|
||||
}
|
||||
|
||||
func (s *PasswordSuite) TestBusyOperationsRecoverAfterCapacityIsReleased() {
|
||||
s.hasher.operations <- struct{}{}
|
||||
s.hasher.operations <- struct{}{}
|
||||
defer func() { <-s.hasher.operations }()
|
||||
_, err := s.hasher.Hash("T3st-password-123")
|
||||
s.ErrorIs(err, ErrBusy)
|
||||
_, err = s.hasher.Verify("T3st-password-123", s.hasher.DummyHash())
|
||||
s.ErrorIs(err, ErrBusy)
|
||||
|
||||
<-s.hasher.operations
|
||||
hash, err := s.hasher.Hash("T3st-password-123")
|
||||
s.Require().NoError(err)
|
||||
verified, err := s.hasher.Verify("T3st-password-123", hash)
|
||||
s.Require().NoError(err)
|
||||
s.True(verified)
|
||||
}
|
||||
|
||||
func (s *PasswordSuite) TestNewRejectsInvalidOperationLimit() {
|
||||
_, err := New(testConfig(), 0)
|
||||
s.ErrorIs(err, ErrInvalidConfig)
|
||||
}
|
||||
|
||||
func testConfig() Config {
|
||||
return Config{MemoryKiB: 8 * 1024, Iterations: 1, Parallelism: 1, SaltLength: 16, KeyLength: 32}
|
||||
}
|
||||
|
||||
func BenchmarkArgon2idHash(b *testing.B) {
|
||||
hasher, err := New(productionConfig())
|
||||
hasher, err := New(productionConfig(), 2)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
@@ -76,7 +98,7 @@ func BenchmarkArgon2idHash(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkArgon2idVerify(b *testing.B) {
|
||||
hasher, err := New(productionConfig())
|
||||
hasher, err := New(productionConfig(), 2)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user