github.com/phillinzzz/newBsc@v1.1.6/cmd/devp2p/dns_route53_test.go (about) 1 // Copyright 2020 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "reflect" 21 "testing" 22 23 "github.com/aws/aws-sdk-go-v2/service/route53/types" 24 ) 25 26 // This test checks that computeChanges/splitChanges create DNS changes in 27 // leaf-added -> root-changed -> leaf-deleted order. 28 func TestRoute53ChangeSort(t *testing.T) { 29 testTree0 := map[string]recordSet{ 30 "2kfjogvxdqtxxugbh7gs7naaai.n": {ttl: 3333, values: []string{ 31 `"enr:-HW4QO1ml1DdXLeZLsUxewnthhUy8eROqkDyoMTyavfks9JlYQIlMFEUoM78PovJDPQrAkrb3LRJ-""vtrymDguKCOIAWAgmlkgnY0iXNlY3AyNTZrMaEDffaGfJzgGhUif1JqFruZlYmA31HzathLSWxfbq_QoQ4"`, 32 }}, 33 "fdxn3sn67na5dka4j2gok7bvqi.n": {ttl: treeNodeTTL, values: []string{`"enrtree-branch:"`}}, 34 "n": {ttl: rootTTL, values: []string{`"enrtree-root:v1 e=2KFJOGVXDQTXXUGBH7GS7NAAAI l=FDXN3SN67NA5DKA4J2GOK7BVQI seq=0 sig=v_-J_q_9ICQg5ztExFvLQhDBGMb0lZPJLhe3ts9LAcgqhOhtT3YFJsl8BWNDSwGtamUdR-9xl88_w-X42SVpjwE"`}}, 35 } 36 37 testTree1 := map[string]string{ 38 "n": "enrtree-root:v1 e=JWXYDBPXYWG6FX3GMDIBFA6CJ4 l=C7HRFPF3BLGF3YR4DY5KX3SMBE seq=1 sig=o908WmNp7LibOfPsr4btQwatZJ5URBr2ZAuxvK4UWHlsB9sUOTJQaGAlLPVAhM__XJesCHxLISo94z5Z2a463gA", 39 "C7HRFPF3BLGF3YR4DY5KX3SMBE.n": "enrtree://AM5FCQLWIZX2QFPNJAP7VUERCCRNGRHWZG3YYHIUV7BVDQ5FDPRT2@morenodes.example.org", 40 "JWXYDBPXYWG6FX3GMDIBFA6CJ4.n": "enrtree-branch:2XS2367YHAXJFGLZHVAWLQD4ZY,H4FHT4B454P6UXFD7JCYQ5PWDY,MHTDO6TMUBRIA2XWG5LUDACK24", 41 "2XS2367YHAXJFGLZHVAWLQD4ZY.n": "enr:-HW4QOFzoVLaFJnNhbgMoDXPnOvcdVuj7pDpqRvh6BRDO68aVi5ZcjB3vzQRZH2IcLBGHzo8uUN3snqmgTiE56CH3AMBgmlkgnY0iXNlY3AyNTZrMaECC2_24YYkYHEgdzxlSNKQEnHhuNAbNlMlWJxrJxbAFvA", 42 "H4FHT4B454P6UXFD7JCYQ5PWDY.n": "enr:-HW4QAggRauloj2SDLtIHN1XBkvhFZ1vtf1raYQp9TBW2RD5EEawDzbtSmlXUfnaHcvwOizhVYLtr7e6vw7NAf6mTuoCgmlkgnY0iXNlY3AyNTZrMaECjrXI8TLNXU0f8cthpAMxEshUyQlK-AM0PW2wfrnacNI", 43 "MHTDO6TMUBRIA2XWG5LUDACK24.n": "enr:-HW4QLAYqmrwllBEnzWWs7I5Ev2IAs7x_dZlbYdRdMUx5EyKHDXp7AV5CkuPGUPdvbv1_Ms1CPfhcGCvSElSosZmyoqAgmlkgnY0iXNlY3AyNTZrMaECriawHKWdDRk2xeZkrOXBQ0dfMFLHY4eENZwdufn1S1o", 44 } 45 46 wantChanges := []types.Change{ 47 { 48 Action: "CREATE", 49 ResourceRecordSet: &types.ResourceRecordSet{ 50 Name: sp("2xs2367yhaxjfglzhvawlqd4zy.n"), 51 ResourceRecords: []types.ResourceRecord{{ 52 Value: sp(`"enr:-HW4QOFzoVLaFJnNhbgMoDXPnOvcdVuj7pDpqRvh6BRDO68aVi5ZcjB3vzQRZH2IcLBGHzo8uUN3snqmgTiE56CH3AMBgmlkgnY0iXNlY3AyNTZrMaECC2_24YYkYHEgdzxlSNKQEnHhuNAbNlMlWJxrJxbAFvA"`), 53 }}, 54 TTL: ip(treeNodeTTL), 55 Type: "TXT", 56 }, 57 }, 58 { 59 Action: "CREATE", 60 ResourceRecordSet: &types.ResourceRecordSet{ 61 Name: sp("c7hrfpf3blgf3yr4dy5kx3smbe.n"), 62 ResourceRecords: []types.ResourceRecord{{ 63 Value: sp(`"enrtree://AM5FCQLWIZX2QFPNJAP7VUERCCRNGRHWZG3YYHIUV7BVDQ5FDPRT2@morenodes.example.org"`), 64 }}, 65 TTL: ip(treeNodeTTL), 66 Type: "TXT", 67 }, 68 }, 69 { 70 Action: "CREATE", 71 ResourceRecordSet: &types.ResourceRecordSet{ 72 Name: sp("h4fht4b454p6uxfd7jcyq5pwdy.n"), 73 ResourceRecords: []types.ResourceRecord{{ 74 Value: sp(`"enr:-HW4QAggRauloj2SDLtIHN1XBkvhFZ1vtf1raYQp9TBW2RD5EEawDzbtSmlXUfnaHcvwOizhVYLtr7e6vw7NAf6mTuoCgmlkgnY0iXNlY3AyNTZrMaECjrXI8TLNXU0f8cthpAMxEshUyQlK-AM0PW2wfrnacNI"`), 75 }}, 76 TTL: ip(treeNodeTTL), 77 Type: "TXT", 78 }, 79 }, 80 { 81 Action: "CREATE", 82 ResourceRecordSet: &types.ResourceRecordSet{ 83 Name: sp("jwxydbpxywg6fx3gmdibfa6cj4.n"), 84 ResourceRecords: []types.ResourceRecord{{ 85 Value: sp(`"enrtree-branch:2XS2367YHAXJFGLZHVAWLQD4ZY,H4FHT4B454P6UXFD7JCYQ5PWDY,MHTDO6TMUBRIA2XWG5LUDACK24"`), 86 }}, 87 TTL: ip(treeNodeTTL), 88 Type: "TXT", 89 }, 90 }, 91 { 92 Action: "CREATE", 93 ResourceRecordSet: &types.ResourceRecordSet{ 94 Name: sp("mhtdo6tmubria2xwg5ludack24.n"), 95 ResourceRecords: []types.ResourceRecord{{ 96 Value: sp(`"enr:-HW4QLAYqmrwllBEnzWWs7I5Ev2IAs7x_dZlbYdRdMUx5EyKHDXp7AV5CkuPGUPdvbv1_Ms1CPfhcGCvSElSosZmyoqAgmlkgnY0iXNlY3AyNTZrMaECriawHKWdDRk2xeZkrOXBQ0dfMFLHY4eENZwdufn1S1o"`), 97 }}, 98 TTL: ip(treeNodeTTL), 99 Type: "TXT", 100 }, 101 }, 102 { 103 Action: "UPSERT", 104 ResourceRecordSet: &types.ResourceRecordSet{ 105 Name: sp("n"), 106 ResourceRecords: []types.ResourceRecord{{ 107 Value: sp(`"enrtree-root:v1 e=JWXYDBPXYWG6FX3GMDIBFA6CJ4 l=C7HRFPF3BLGF3YR4DY5KX3SMBE seq=1 sig=o908WmNp7LibOfPsr4btQwatZJ5URBr2ZAuxvK4UWHlsB9sUOTJQaGAlLPVAhM__XJesCHxLISo94z5Z2a463gA"`), 108 }}, 109 TTL: ip(rootTTL), 110 Type: "TXT", 111 }, 112 }, 113 { 114 Action: "DELETE", 115 ResourceRecordSet: &types.ResourceRecordSet{ 116 Name: sp("2kfjogvxdqtxxugbh7gs7naaai.n"), 117 ResourceRecords: []types.ResourceRecord{ 118 {Value: sp(`"enr:-HW4QO1ml1DdXLeZLsUxewnthhUy8eROqkDyoMTyavfks9JlYQIlMFEUoM78PovJDPQrAkrb3LRJ-""vtrymDguKCOIAWAgmlkgnY0iXNlY3AyNTZrMaEDffaGfJzgGhUif1JqFruZlYmA31HzathLSWxfbq_QoQ4"`)}, 119 }, 120 TTL: ip(3333), 121 Type: "TXT", 122 }, 123 }, 124 { 125 Action: "DELETE", 126 ResourceRecordSet: &types.ResourceRecordSet{ 127 Name: sp("fdxn3sn67na5dka4j2gok7bvqi.n"), 128 ResourceRecords: []types.ResourceRecord{{ 129 Value: sp(`"enrtree-branch:"`), 130 }}, 131 TTL: ip(treeNodeTTL), 132 Type: "TXT", 133 }, 134 }, 135 } 136 137 var client route53Client 138 changes := client.computeChanges("n", testTree1, testTree0) 139 if !reflect.DeepEqual(changes, wantChanges) { 140 t.Fatalf("wrong changes (got %d, want %d)", len(changes), len(wantChanges)) 141 } 142 143 // Check splitting according to size. 144 wantSplit := [][]types.Change{ 145 wantChanges[:4], 146 wantChanges[4:6], 147 wantChanges[6:], 148 } 149 split := splitChanges(changes, 600, 4000) 150 if !reflect.DeepEqual(split, wantSplit) { 151 t.Fatalf("wrong split batches: got %d, want %d", len(split), len(wantSplit)) 152 } 153 154 // Check splitting according to count. 155 wantSplit = [][]types.Change{ 156 wantChanges[:5], 157 wantChanges[5:], 158 } 159 split = splitChanges(changes, 10000, 6) 160 if !reflect.DeepEqual(split, wantSplit) { 161 t.Fatalf("wrong split batches: got %d, want %d", len(split), len(wantSplit)) 162 } 163 } 164 165 // This test checks that computeChanges compares the quoted value of the records correctly. 166 func TestRoute53NoChange(t *testing.T) { 167 // Existing record set. 168 testTree0 := map[string]recordSet{ 169 "n": {ttl: rootTTL, values: []string{ 170 `"enrtree-root:v1 e=JWXYDBPXYWG6FX3GMDIBFA6CJ4 l=C7HRFPF3BLGF3YR4DY5KX3SMBE seq=1 sig=o908WmNp7LibOfPsr4btQwatZJ5URBr2ZAuxvK4UWHlsB9sUOTJQaGAlLPVAhM__XJesCHxLISo94z5Z2a463gA"`, 171 }}, 172 "2xs2367yhaxjfglzhvawlqd4zy.n": {ttl: treeNodeTTL, values: []string{ 173 `"enr:-HW4QOFzoVLaFJnNhbgMoDXPnOvcdVuj7pDpqRvh6BRDO68aVi5ZcjB3vzQRZH2IcLBGHzo8uUN3snqmgTiE56CH3AMBgmlkgnY0iXNlY3AyNTZrMaECC2_24YYkYHEgdzxlSNKQEnHhuNAbNlMlWJxrJxbAFvA"`, 174 }}, 175 } 176 // New set. 177 testTree1 := map[string]string{ 178 "n": "enrtree-root:v1 e=JWXYDBPXYWG6FX3GMDIBFA6CJ4 l=C7HRFPF3BLGF3YR4DY5KX3SMBE seq=1 sig=o908WmNp7LibOfPsr4btQwatZJ5URBr2ZAuxvK4UWHlsB9sUOTJQaGAlLPVAhM__XJesCHxLISo94z5Z2a463gA", 179 "2XS2367YHAXJFGLZHVAWLQD4ZY.n": "enr:-HW4QOFzoVLaFJnNhbgMoDXPnOvcdVuj7pDpqRvh6BRDO68aVi5ZcjB3vzQRZH2IcLBGHzo8uUN3snqmgTiE56CH3AMBgmlkgnY0iXNlY3AyNTZrMaECC2_24YYkYHEgdzxlSNKQEnHhuNAbNlMlWJxrJxbAFvA", 180 } 181 182 var client route53Client 183 changes := client.computeChanges("n", testTree1, testTree0) 184 if len(changes) > 0 { 185 t.Fatalf("wrong changes (got %d, want 0)", len(changes)) 186 } 187 } 188 189 func sp(s string) *string { return &s } 190 func ip(i int64) *int64 { return &i }