tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

sanity_test.go (1943B)


      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 "testing"
     21 
     22 func TestValidateOnionAddress(t *testing.T) {
     23 	const val0 = "p7qaewjgnvnaeihhyybmoofd5avh665kr3awoxlh5rt6ox743kjdr6qd.onion"
     24 	const inv0 = "p7qaewjg1vnaeihhyybmoofd5avh665kr3awoxlh5rt6ox743kjdr6qd.onion"
     25 	const inv1 = "p7qaewjgvybmoofd5avh665kr3awoxlh5rt6ox743kjdr6qd.onion"
     26 	const inv2 = "p7qaewjgvybmoofd5avh665kr3awoxl1jdr6qd.onion"
     27 
     28 	if err := ValidateOnionAddress(val0); err != nil {
     29 		t.Fatalf("valid onion address reported invalid: %s", val0)
     30 	}
     31 
     32 	for _, i := range []string{inv0, inv1, inv2} {
     33 		if err := ValidateOnionAddress(i); err == nil {
     34 			t.Fatalf("invalid onion address reported valid: %s", i)
     35 		}
     36 	}
     37 }
     38 
     39 func TestValidatePortmap(t *testing.T) {
     40 	val0 := []string{"1234:3215"}
     41 	val1 := []string{}
     42 	val2 := []string{"31983:35155", "31587:11"}
     43 	inv0 := []string{"1515:315foo"}
     44 	inv1 := []string{"101667:8130", "1305:3191"}
     45 
     46 	for _, i := range [][]string{val0, val1, val2} {
     47 		if err := ValidatePortmap(i); err != nil {
     48 			t.Fatalf("valid portmap reported invalid: %v", i)
     49 		}
     50 	}
     51 
     52 	for _, i := range [][]string{inv0, inv1} {
     53 		if err := ValidatePortmap(i); err == nil {
     54 			t.Fatalf("invalid portmap reported valid: %v", i)
     55 		}
     56 	}
     57 }