]> Cypherpunks.ru repositories - govpn.git/commitdiff
Simple handshake passing tests
authorSergey Matveev <stargrave@stargrave.org>
Tue, 5 Jan 2016 20:12:40 +0000 (23:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 5 Jan 2016 20:30:01 +0000 (23:30 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
src/govpn/handshake_test.go [new file with mode: 0644]
src/govpn/peer_test.go

diff --git a/src/govpn/handshake_test.go b/src/govpn/handshake_test.go
new file mode 100644 (file)
index 0000000..02c592b
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+GoVPN -- simple secure free software virtual private network daemon
+Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package govpn
+
+import (
+       "testing"
+)
+
+func TestHandshakeSymmetric(t *testing.T) {
+       // initial values are taken from peer_test.go's init()
+       v := VerifierNew(DefaultM, DefaultT, DefaultP, &peerId)
+       conf.Verifier = v
+       conf.DSAPriv = v.PasswordApply("does not matter")
+       hsS := NewHandshake("server", Dummy{&ciphertext}, conf)
+       hsC := HandshakeStart("client", Dummy{&ciphertext}, conf)
+       hsS.Server(ciphertext)
+       hsC.Client(ciphertext)
+       if hsS.Server(ciphertext) == nil {
+               t.Fail()
+       }
+       if hsC.Client(ciphertext) == nil {
+               t.Fail()
+       }
+}
+
+func TestHandshakeNoiseSymmetric(t *testing.T) {
+       // initial values are taken from peer_test.go's init()
+       v := VerifierNew(DefaultM, DefaultT, DefaultP, &peerId)
+       conf.Verifier = v
+       conf.DSAPriv = v.PasswordApply("does not matter")
+       conf.Noise = true
+       hsS := NewHandshake("server", Dummy{&ciphertext}, conf)
+       hsC := HandshakeStart("client", Dummy{&ciphertext}, conf)
+       hsS.Server(ciphertext)
+       hsC.Client(ciphertext)
+       if hsS.Server(ciphertext) == nil {
+               t.Fail()
+       }
+       if hsC.Client(ciphertext) == nil {
+               t.Fail()
+       }
+       conf.Noise = false
+}
+func TestHandshakeEnclessSymmetric(t *testing.T) {
+       // initial values are taken from peer_test.go's init()
+       v := VerifierNew(DefaultM, DefaultT, DefaultP, &peerId)
+       conf.Verifier = v
+       conf.DSAPriv = v.PasswordApply("does not matter")
+       conf.EncLess = true
+       conf.Noise = true
+       hsS := NewHandshake("server", Dummy{&ciphertext}, conf)
+       hsC := HandshakeStart("client", Dummy{&ciphertext}, conf)
+       hsS.Server(ciphertext)
+       hsC.Client(ciphertext)
+       if hsS.Server(ciphertext) == nil {
+               t.Fail()
+       }
+       if hsC.Client(ciphertext) == nil {
+               t.Fail()
+       }
+       conf.EncLess = false
+       conf.Noise = false
+}
index d0526085fa809884d0a11815530418ae6e532279..09a0465445c7ca5e88ecfe1598e5a6b2efcba9da 100644 (file)
@@ -28,7 +28,7 @@ var (
        peer       *Peer
        plaintext  []byte
        ciphertext []byte
-       peerId     *PeerId
+       peerId     PeerId
        conf       *PeerConf
 )
 
@@ -45,7 +45,7 @@ func (d Dummy) Write(b []byte) (int, error) {
 
 func init() {
        id := new([IDSize]byte)
-       peerId := PeerId(*id)
+       peerId = PeerId(*id)
        conf = &PeerConf{
                Id:      &peerId,
                MTU:     MTUDefault,
@@ -55,7 +55,7 @@ func init() {
        plaintext = make([]byte, 789)
 }
 
-func TestSymmetric(t *testing.T) {
+func TestTransportSymmetric(t *testing.T) {
        peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
        f := func(payload []byte) bool {
                if len(payload) == 0 {
@@ -69,7 +69,7 @@ func TestSymmetric(t *testing.T) {
        }
 }
 
-func TestSymmetricNoise(t *testing.T) {
+func TestTransportSymmetricNoise(t *testing.T) {
        peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
        peer.NoiseEnable = true
        peerd.NoiseEnable = true
@@ -86,7 +86,7 @@ func TestSymmetricNoise(t *testing.T) {
        peer.NoiseEnable = true
 }
 
-func TestSymmetricEncLess(t *testing.T) {
+func TestTransportSymmetricEncLess(t *testing.T) {
        peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
        peer.EncLess = true
        peer.NoiseEnable = true