From e0541dec15526074aa8865ac56de06081ab1c591 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 25 May 2018 15:37:44 -0700 Subject: [PATCH] adding tests.sh script; fixing connections tests broken by removing private_key with pk generation --- model/profile_test | 1 - peer/connections/peerpeerconnection_test.go | 20 +++++++++++------- peer/connections/peerserverconnection_test.go | 20 +++++++++++------- peer/test_profile | 1 - testing/tests.sh | 21 +++++++++++++++++++ 5 files changed, 47 insertions(+), 16 deletions(-) delete mode 100644 model/profile_test delete mode 100644 peer/test_profile create mode 100755 testing/tests.sh diff --git a/model/profile_test b/model/profile_test deleted file mode 100644 index f188365..0000000 --- a/model/profile_test +++ /dev/null @@ -1 +0,0 @@ -{"Name":"Sarah","Ed25519PublicKey":"/2xUC3+EcM69CnYrYSKW499gXtH65DQ65R6UGRmbpHM=","Trusted":false,"Blocked":false,"Onion":"4g3rdfpq4fryjyg2","Contacts":{"4g3rdfpq4fryjyg2":{"Name":"Sarah","Ed25519PublicKey":"/2xUC3+EcM69CnYrYSKW499gXtH65DQ65R6UGRmbpHM=","Trusted":false,"Blocked":false,"Onion":"4g3rdfpq4fryjyg2"}},"Ed25519PrivateKey":"RJ8K69ZZG5B4ufBDVUvXprYpGsDM8iFiQMEdc1MCDh7/bFQLf4Rwzr0KdithIpbj32Be0frkNDrlHpQZGZukcw==","OnionPrivateKey":{"N":137900602813611213189041103405418371044707088095490122917581331230896621428290390270991677482016645829512106617167800422226984565513726430820993290694895580565153249656392070078179688609933325529529966437840233160619179283162861419376169773461376606874165643290168384848468920199602266115187846439397770310477,"E":65537,"D":32650314385138245495740586257257379243796937393803809104965279410254098825133618960815689755229142214879218737180413493930087118773768909578548802839811012970470413974184929457770929480883399498950171683167037292603270431438053986057858898333372137069087346537018540254886839274994781698804912229336225943149,"Primes":[13089226577015106801916990672183383260292068983897361545720483543242420102790612098089034534068816127751017739419172149354346726789445970796490590388209763,10535427895775514969658003258523047110222786921729773130757443070837085109335455191190769936580263568766152909466244437192612859171443040757316597016718479],"Precomputed":{"Dp":12060255227628015079020362264671767065516221151298383767006902951900354576910922250684443144174213984073808782746032168679711111237632100134978474763752483,"Dq":8251736413294062268756808600687345029751832941381372119183214218977652558818655880174762525208683785469816973554050280078947932833809034974347593595452587,"Qinv":11288899754516920495714102707684244008755697053785965771187317487773161282452886307082370168337103639984386063085142036280484558810305271619464191907337467,"CRTValues":[]}},"Groups":{}} \ No newline at end of file diff --git a/peer/connections/peerpeerconnection_test.go b/peer/connections/peerpeerconnection_test.go index d43609d..8a03ef9 100644 --- a/peer/connections/peerpeerconnection_test.go +++ b/peer/connections/peerpeerconnection_test.go @@ -19,14 +19,11 @@ func PeerAuthValid(string, rsa.PublicKey) (allowed, known bool) { return true, true } -func runtestpeer(t *testing.T, tp *TestPeer) { +func runtestpeer(t *testing.T, tp *TestPeer, privateKey *rsa.PrivateKey) { ln, _ := net.Listen("tcp", "127.0.0.1:5452") conn, _ := ln.Accept() defer conn.Close() - privateKey, err := utils.LoadPrivateKeyFromFile("../../testing/private_key") - if err != nil { - t.Errorf("Private Key Error %v", err) - } + rc, err := goricochet.NegotiateVersionInbound(conn) if err != nil { t.Errorf("Negotiate Version Error: %v", err) @@ -79,12 +76,21 @@ func (tp *TestPeer) GetClientIdentityPacket() []byte { } func TestPeerPeerConnection(t *testing.T) { + privateKey, err := utils.GeneratePrivateKey() + if err != nil { + t.Errorf("Private Key Error %v", err) + } + onionAddr, err := utils.GetOnionAddress(privateKey) + if err != nil { + t.Errorf("Onion address error %v", err) + } + profile := model.GenerateNewProfile("sarah") - ppc := NewPeerPeerConnection("127.0.0.1:5452|kwke2hntvyfqm7dr", profile) + ppc := NewPeerPeerConnection("127.0.0.1:5452|" + onionAddr, profile) //numcalls := 0 tp := new(TestPeer) tp.Init() - go runtestpeer(t, tp) + go runtestpeer(t, tp, privateKey) state := ppc.GetState() if state != DISCONNECTED { t.Errorf("new connections should start in disconnected state") diff --git a/peer/connections/peerserverconnection_test.go b/peer/connections/peerserverconnection_test.go index bfd6fe5..3c28c20 100644 --- a/peer/connections/peerserverconnection_test.go +++ b/peer/connections/peerserverconnection_test.go @@ -32,14 +32,11 @@ func (ts *TestServer) HandleFetchRequest() []*protocol.GroupMessage { return []*protocol.GroupMessage{{Ciphertext: []byte("hello"), Spamguard: []byte{}}, {Ciphertext: []byte("hello"), Spamguard: []byte{}}} } -func runtestserver(t *testing.T, ts *TestServer) { +func runtestserver(t *testing.T, ts *TestServer, privateKey *rsa.PrivateKey) { ln, _ := net.Listen("tcp", "127.0.0.1:5451") conn, _ := ln.Accept() defer conn.Close() - privateKey, err := utils.LoadPrivateKeyFromFile("../../testing/private_key") - if err != nil { - t.Errorf("Private Key Error %v", err) - } + rc, err := goricochet.NegotiateVersionInbound(conn) if err != nil { t.Errorf("Negotiate Version Error: %v", err) @@ -66,10 +63,19 @@ func runtestserver(t *testing.T, ts *TestServer) { } func TestPeerServerConnection(t *testing.T) { + privateKey, err := utils.GeneratePrivateKey() + if err != nil { + t.Errorf("Private Key Error %v", err) + } + ts := new(TestServer) ts.Init() - go runtestserver(t, ts) - psc := NewPeerServerConnection("127.0.0.1:5451|kwke2hntvyfqm7dr") + go runtestserver(t, ts, privateKey) + onionAddr, err := utils.GetOnionAddress(privateKey) + if err != nil { + t.Errorf("Error getting onion address: %v", err) + } + psc := NewPeerServerConnection("127.0.0.1:5451|" + onionAddr) numcalls := 0 psc.GroupMessageHandler = func(s string, gm *protocol.GroupMessage) { numcalls++ diff --git a/peer/test_profile b/peer/test_profile deleted file mode 100644 index 0d0aea0..0000000 --- a/peer/test_profile +++ /dev/null @@ -1 +0,0 @@ -{"Profile":{"Name":"alice","Ed25519PublicKey":"gWXfzP4wvMJ5j8yv5lkCmntRou/Z3zH3rs7MMthqKTQ=","Trusted":false,"Blocked":false,"Onion":"am6gwjcyctstzlc2","Contacts":{"am6gwjcyctstzlc2":{"Name":"alice","Ed25519PublicKey":"gWXfzP4wvMJ5j8yv5lkCmntRou/Z3zH3rs7MMthqKTQ=","Trusted":false,"Blocked":false,"Onion":"am6gwjcyctstzlc2"}},"Ed25519PrivateKey":"10jFOuAYO4Viw6nfe6Yetjh+oP7apVx7QpKIqRKKGwmBZd/M/jC8wnmPzK/mWQKae1Gi79nfMfeuzswy2GopNA==","OnionPrivateKey":{"N":147880432621871504779615857957362407431209846743533559661945830611220249199723115899614573127370139919927611627709018139426557086534947242067702251560319171966667134304630051790361962997647653664951649912943924083112173778189617381049272838770430351966281298194239296841527739740024573326387864819562137420269,"E":65537,"D":130999990788338985328675072853085004285004178747006795241373989379510853220915287801822232593536488444562879299605944078956134675311242459762920516907790842355984733809116227992469235130987810703943533032505458827231110955929966815957481967581612489200794929349103575491967289603043965454693951743019350429921,"Primes":[11947866823745435455892039576265035645775668999529461749065887228195684195954622809692270909464429145942026225362289090834468485547124190883870378071630407,12377141024703330426235540654219528982015913018918150249718199085745128023134821710912287791906815892120589396719673405276176963231038832685865432874369067],"Precomputed":{"Dp":11122744446397191854973972360460596148502667826270534061251794340287881478849924351772817499387129203702778003808209404167138513690214596487721678388211891,"Dq":5067041422292603496283008922482108771953048603042158951431089025596865661545497451878735393088787561005163701634021048622302331865797517142404589224702413,"Qinv":6439679233885062453326040666151092713878681619523464587705315223851862036675549289934062975420544339668044885799082649238658464851991671641282282423293532,"CRTValues":[]}},"Groups":{}}} \ No newline at end of file diff --git a/testing/tests.sh b/testing/tests.sh new file mode 100755 index 0000000..88d4e41 --- /dev/null +++ b/testing/tests.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e +pwd +go test ${1} -coverprofile=model.cover.out -v ./model +go test ${1} -coverprofile=protocol.spam.cover.out -v ./protocol/spam +go test ${1} -coverprofile=storage.cover.out -v ./storage +go test ${1} -coverprofile=peer.connections.cover.out -v ./peer/connections +go test ${1} -coverprofile=peer.fetch.cover.out -v ./peer/fetch +go test ${1} -coverprofile=peer.listen.cover.out -v ./peer/listen +go test ${1} -coverprofile=peer.peer.cover.out -v ./peer/peer +go test ${1} -coverprofile=peer.send.cover.out -v ./peer/send +go test ${1} -coverprofile=peer.cover.out -v ./peer +go test ${1} -coverprofile=server.fetch.cover.out -v ./server/fetch +go test ${1} -coverprofile=server.listen.cover.out -v ./server/listen +go test ${1} -coverprofile=server.send.cover.out -v ./server/send +go test ${1} -coverprofile=server.cover.out -v ./server +go test ${1} -coverprofile=testing.cover.out -v ./testing +echo "mode: set" > coverage.out && cat *.cover.out | grep -v mode: | sort -r | \ +awk '{if($1 != last) {print $0;last=$1}}' >> coverage.out +rm -rf *.cover.out