tor-dam

tor distributed announce mechanism (not a dht)
git clone https://git.parazyd.org/tor-dam
Log | Files | Refs | README | LICENSE

announce_test.go (1713B)


      1 // Copyright (c) 2017-2021 Ivan Jelincic <parazyd@dyne.org>
      2 //
      3 // This file is part of tordam
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program. If not, see <https://www.gnu.org/licenses/>.
     17 
     18 package tordam
     19 
     20 import (
     21 	"context"
     22 	"crypto/ed25519"
     23 	"crypto/rand"
     24 	"encoding/base64"
     25 	"testing"
     26 )
     27 
     28 func TestAnnounce(t *testing.T) {
     29 	pk, sk, err := ed25519.GenerateKey(rand.Reader)
     30 	if err != nil {
     31 		t.Fatal(err)
     32 	}
     33 
     34 	vals := []string{
     35 		"p7qaewjgnvnaeihhyybmoofd5avh665kr3awoxlh5rt6ox743kjdr6qd.onion:666",
     36 		base64.StdEncoding.EncodeToString(pk),
     37 		"12345:54321,666:3521",
     38 	}
     39 
     40 	ret, err := Ann.Init(Ann{}, context.Background(), vals)
     41 	if err != nil {
     42 		t.Fatal(err)
     43 	}
     44 	for _, i := range ret {
     45 		if _, err := base64.StdEncoding.DecodeString(i); err != nil {
     46 			t.Fatal(err)
     47 		}
     48 	}
     49 
     50 	vals = []string{
     51 		"p7qaewjgnvnaeihhyybmoofd5avh665kr3awoxlh5rt6ox743kjdr6qd.onion:666",
     52 		base64.StdEncoding.EncodeToString(ed25519.Sign(sk, []byte(ret[0]))),
     53 	}
     54 
     55 	ret, err = Ann.Validate(Ann{}, context.Background(), vals)
     56 	if err != nil {
     57 		t.Fatal(err)
     58 	}
     59 	for _, i := range ret {
     60 		if err := ValidateOnionInternal(i); err != nil {
     61 			t.Fatal(err)
     62 		}
     63 	}
     64 }