forked from cwtch.im/cwtch
34 lines
822 B
Go
34 lines
822 B
Go
|
package spam
|
||
|
|
||
|
import (
|
||
|
"git.mascherari.press/cwtch/protocol"
|
||
|
"github.com/golang/protobuf/proto"
|
||
|
"github.com/s-rah/go-ricochet/wire/control"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestSpamGuard(t *testing.T) {
|
||
|
var spamGuard SpamGuard
|
||
|
spamGuard.Difficulty = 2
|
||
|
challenge := spamGuard.GenerateChallenge(3)
|
||
|
|
||
|
control := new(Protocol_Data_Control.Packet)
|
||
|
proto.Unmarshal(challenge[:], control)
|
||
|
|
||
|
if control.GetChannelResult() != nil {
|
||
|
ce, _ := proto.GetExtension(control.GetChannelResult(), protocol.E_ServerNonce)
|
||
|
challenge := ce.([]byte)[:]
|
||
|
|
||
|
sgsolve := spamGuard.SolveChallenge(challenge, []byte("Hello"))
|
||
|
t.Logf("Solved: %v %v", challenge, sgsolve)
|
||
|
result := spamGuard.ValidateChallenge([]byte("Hello"), sgsolve)
|
||
|
if result != true {
|
||
|
t.Errorf("Validating SpamGuard Failed")
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
t.Errorf("Failed SpamGaurd")
|
||
|
|
||
|
}
|