announce_test.go (1768B)
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 "os" 26 "testing" 27 ) 28 29 func TestAnnounce(t *testing.T) { 30 pk, sk, err := ed25519.GenerateKey(rand.Reader) 31 if err != nil { 32 t.Fatal(err) 33 } 34 35 Cfg.Datadir = os.TempDir() 36 LogInit(os.Stdout) 37 38 vals := []string{ 39 "p7qaewjgnvnaeihhyybmoofd5avh665kr3awoxlh5rt6ox743kjdr6qd.onion:666", 40 base64.StdEncoding.EncodeToString(pk), 41 "12345:54321,666:3521", 42 } 43 44 ret, err := Ann.Init(Ann{}, context.Background(), vals) 45 if err != nil { 46 t.Fatal(err) 47 } 48 for _, i := range ret { 49 if _, err := base64.StdEncoding.DecodeString(i); err != nil { 50 t.Fatal(err) 51 } 52 } 53 54 vals = []string{ 55 "p7qaewjgnvnaeihhyybmoofd5avh665kr3awoxlh5rt6ox743kjdr6qd.onion:666", 56 base64.StdEncoding.EncodeToString(ed25519.Sign(sk, []byte(ret[0]))), 57 } 58 59 ret, err = Ann.Validate(Ann{}, context.Background(), vals) 60 if err != nil { 61 t.Fatal(err) 62 } 63 for _, i := range ret { 64 if err := ValidateOnionInternal(i); err != nil { 65 t.Fatal(err) 66 } 67 } 68 }