-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_test.go
31 lines (23 loc) · 945 Bytes
/
auth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package lamport
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOneTimeAuth(t *testing.T) {
t.Run("bob can verify alice, after receiving rounds count and initiate msg", func(t *testing.T) {
rounds := 10_000
alice := NewOneTimeAuthAlice(rounds)
bob := NewOneTimeAuthBob(rounds, alice.InitialPassword())
assert.Error(t, bob.Verify(randHex()), "bob should not accept random password")
for i := 0; i < rounds; i++ {
m_i, err := alice.NextPassword()
assert.NoError(t, err, "alice should not return err when rounds not exceed")
validationErr := bob.Verify(*m_i)
assert.NoError(t, validationErr, "bob should not return err on verify alice's password")
}
m_i, err := alice.NextPassword()
assert.Error(t, err, "alice should return an error if somebody requires next round")
assert.Nil(t, m_i)
assert.Error(t, bob.Verify(randHex()), "bob should return an error if round offset exceeds")
})
}