tAdd some test cases for damlib. - tordam - A library for peer discovery inside the Tor network
 (HTM) git clone https://git.parazyd.org/tordam
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 77feb15fd76bea2b9b1f1814e85b5279954c992e
 (DIR) parent 827494327cebf6a3bd3c266f8735a91e82d08c1b
 (HTM) Author: parazyd <parazyd@dyne.org>
       Date:   Mon, 12 Mar 2018 12:28:16 +0100
       
       Add some test cases for damlib.
       
       Diffstat:
         A pkg/damlib/config_test.go           |      31 +++++++++++++++++++++++++++++++
         A pkg/damlib/crypto_25519_test.go     |      82 +++++++++++++++++++++++++++++++
         A pkg/damlib/crypto_common_test.go    |      38 +++++++++++++++++++++++++++++++
         A pkg/damlib/net_test.go              |      51 +++++++++++++++++++++++++++++++
         A pkg/damlib/tor_test.go              |      36 +++++++++++++++++++++++++++++++
       
       5 files changed, 238 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/pkg/damlib/config_test.go b/pkg/damlib/config_test.go
       t@@ -0,0 +1,31 @@
       +package damlib
       +
       +/*
       + * Copyright (c) 2017-2018 Dyne.org Foundation
       + * tor-dam is written and maintained by Ivan J. <parazyd@dyne.org>
       + *
       + * This file is part of tor-dam
       + *
       + * This source code 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 software 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 source code. If not, see <http://www.gnu.org/licenses/>.
       + */
       +
       +import (
       +        "os"
       +        "testing"
       +)
       +
       +func TestMain(m *testing.M) {
       +        ex := m.Run()
       +        os.Exit(ex)
       +}
 (DIR) diff --git a/pkg/damlib/crypto_25519_test.go b/pkg/damlib/crypto_25519_test.go
       t@@ -0,0 +1,82 @@
       +package damlib
       +
       +/*
       + * Copyright (c) 2017-2018 Dyne.org Foundation
       + * tor-dam is written and maintained by Ivan J. <parazyd@dyne.org>
       + *
       + * This file is part of tor-dam
       + *
       + * This source code 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 software 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 source code. If not, see <http://www.gnu.org/licenses/>.
       + */
       +
       +import (
       +        "os"
       +        "testing"
       +)
       +
       +func TestGenEd25519(t *testing.T) {
       +        _, _, err := GenEd25519()
       +        if err != nil {
       +                t.Fatal("Failed generating ed25519 key:", err.Error())
       +        }
       +
       +        t.Log("Successfully generated ed25519 keypair.")
       +}
       +
       +func TestSavePubEd25519(t *testing.T) {
       +        pk, _, err := GenEd25519()
       +        if err != nil {
       +                t.Fatal("Failed generating ed25519 key:", err.Error())
       +        }
       +
       +        err = SavePubEd25519("/tmp/ed25519pub.test", pk)
       +        if err != nil {
       +                t.Fatal("Failed saving pubkey:", err.Error())
       +        }
       +
       +        os.Remove("/tmp/ed25519pub.test")
       +        t.Log("Success saving ed25519 pubkey")
       +}
       +
       +func TestSavePrivEd25519(t *testing.T) {
       +        _, sk, err := GenEd25519()
       +        if err != nil {
       +                t.Fatal("Failed generating ed25519 key:", err.Error())
       +        }
       +
       +        err = SavePrivEd25519("/tmp/ed25519priv.test", sk)
       +        if err != nil {
       +                t.Fatal("Failed saving privkey:", err.Error())
       +        }
       +
       +        os.Remove("/tmp/ed25519priv.test")
       +        t.Log("Success saving ed25519 privkey")
       +}
       +
       +func TestOnionFromPubkeyEd25519(t *testing.T) {
       +        pk, _, err := GenEd25519()
       +        if err != nil {
       +                t.Fatal("Failed generating ed25519 key:", err.Error())
       +        }
       +
       +        res := OnionFromPubkeyEd25519(pk)
       +        valid := ValidateOnionAddress(string(res))
       +
       +        t.Log("Got:", string(res))
       +
       +        if !valid {
       +                t.Fatal("Address is invalid.")
       +        }
       +        t.Log("Address is valid")
       +}
 (DIR) diff --git a/pkg/damlib/crypto_common_test.go b/pkg/damlib/crypto_common_test.go
       t@@ -0,0 +1,38 @@
       +package damlib
       +
       +/*
       + * Copyright (c) 2017-2018 Dyne.org Foundation
       + * tor-dam is written and maintained by Ivan J. <parazyd@dyne.org>
       + *
       + * This file is part of tor-dam
       + *
       + * This source code 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 software 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 source code. If not, see <http://www.gnu.org/licenses/>.
       + */
       +
       +import (
       +        "testing"
       +)
       +
       +func TestGenRandomASCII(t *testing.T) {
       +        res, err := GenRandomASCII(18)
       +        if err != nil {
       +                t.Fatal("Failed making random string:", err.Error())
       +        }
       +
       +        if len(res) != 18 {
       +                t.Fatal("String is of incorrect length: 18 !=", len(res))
       +        }
       +
       +        t.Log("Got:", res)
       +}
 (DIR) diff --git a/pkg/damlib/net_test.go b/pkg/damlib/net_test.go
       t@@ -0,0 +1,51 @@
       +package damlib
       +
       +/*
       + * Copyright (c) 2017-2018 Dyne.org Foundation
       + * tor-dam is written and maintained by Ivan J. <parazyd@dyne.org>
       + *
       + * This file is part of tor-dam
       + *
       + * This source code 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 software 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 source code. If not, see <http://www.gnu.org/licenses/>.
       + */
       +
       +import (
       +        "io/ioutil"
       +        "testing"
       +)
       +
       +func TestHTTPPost(t *testing.T) {
       +        data := []byte("foobar")
       +
       +        resp, err := HTTPPost("https://requestb.in/ykdug2yk", data)
       +        if err != nil {
       +                t.Fatal("Unable to HTTPPost:", err.Error())
       +        }
       +
       +        res, err := ioutil.ReadAll(resp.Body)
       +        if err != nil {
       +                t.Fatal("Unable to read response:", err.Error())
       +        }
       +
       +        t.Log("Got:", string(res))
       +}
       +
       +func TestHTTPDownload(t *testing.T) {
       +        data, err := HTTPDownload("https://requestb.in/ykdug2yk")
       +        if err != nil {
       +                t.Fatal("Unable to HTTPDownload:", err.Error())
       +        }
       +
       +        t.Log("Got:", string(data))
       +}
 (DIR) diff --git a/pkg/damlib/tor_test.go b/pkg/damlib/tor_test.go
       t@@ -0,0 +1,36 @@
       +package damlib
       +
       +/*
       + * Copyright (c) 2017-2018 Dyne.org Foundation
       + * tor-dam is written and maintained by Ivan J. <parazyd@dyne.org>
       + *
       + * This file is part of tor-dam
       + *
       + * This source code 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 software 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 source code. If not, see <http://www.gnu.org/licenses/>.
       + */
       +
       +import (
       +        "strings"
       +        "testing"
       +)
       +
       +func TestFetchHSPubkey(t *testing.T) {
       +        pubkey := FetchHSPubkey("szpvqtyw3vbgzb3s.onion")
       +
       +        if !strings.HasPrefix(pubkey, "-----BEGIN") {
       +                t.Fatal("Did not get a public key.")
       +        }
       +
       +        t.Log("Got:", pubkey)
       +}