File: azure_test.go

package info (click to toggle)
golang-github-pires-go-proxyproto 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: makefile: 3
file content (111 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package tlvparse

import (
	"testing"

	"github.com/pires/go-proxyproto"
)

func TestFindAzurePrivateEndpointLinkID(t *testing.T) {
	tests := []struct {
		name       string
		tlvs       []proxyproto.TLV
		wantLinkID uint32
		wantFound  bool
	}{
		{
			name:       "nil TLVs",
			tlvs:       nil,
			wantLinkID: 0,
			wantFound:  false,
		},
		{
			name:       "empty TLVs",
			tlvs:       []proxyproto.TLV{},
			wantLinkID: 0,
			wantFound:  false,
		},
		{
			name: "AWS VPC endpoint ID",
			tlvs: []proxyproto.TLV{
				{
					Type:  0xEA,
					Value: []byte{0x01, 0x76, 0x70, 0x63, 0x65, 0x2d, 0x61, 0x62, 0x63, 0x31, 0x32, 0x33},
				},
			},
			wantLinkID: 0,
			wantFound:  false,
		},
		{
			name: "Azure but wrong subtype",
			tlvs: []proxyproto.TLV{
				{
					Type:  0xEE,
					Value: []byte{0x02, 0x01, 0x01, 0x01, 0x01},
				},
			},
			wantLinkID: 0,
			wantFound:  false,
		},
		{
			name: "Azure but wrong length",
			tlvs: []proxyproto.TLV{
				{
					Type:  0xEE,
					Value: []byte{0x02, 0x01, 0x01},
				},
			},
			wantLinkID: 0,
			wantFound:  false,
		},
		{
			name: "Azure link ID",
			tlvs: []proxyproto.TLV{
				{
					Type:  0xEE,
					Value: []byte{0x1, 0xc1, 0x45, 0x0, 0x21},
				},
			},
			wantLinkID: 0x210045c1,
			wantFound:  true,
		},
		{
			name: "Multiple TLVs",
			tlvs: []proxyproto.TLV{
				{ // AWS
					Type:  0xEA,
					Value: []byte{0x01, 0x76, 0x70, 0x63, 0x65, 0x2d, 0x61, 0x62, 0x63, 0x31, 0x32, 0x33},
				},
				{ // Azure but wrong subtype
					Type:  0xEE,
					Value: []byte{0x02, 0x01, 0x01, 0x01, 0x01},
				},
				{ // Azure but wrong length
					Type:  0xEE,
					Value: []byte{0x02, 0x01, 0x01},
				},
				{ // Correct
					Type:  0xEE,
					Value: []byte{0x1, 0xc1, 0x45, 0x0, 0x21},
				},
				{ // Also correct, but second in line
					Type:  0xEE,
					Value: []byte{0x1, 0xc1, 0x45, 0x0, 0x22},
				},
			},
			wantLinkID: 0x210045c1,
			wantFound:  true,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			gotLinkID, gotFound := FindAzurePrivateEndpointLinkID(tt.tlvs)
			if gotFound != tt.wantFound {
				t.Errorf("FindAzurePrivateEndpointLinkID() got1 = %v, want %v", gotFound, tt.wantFound)
			}
			if gotLinkID != tt.wantLinkID {
				t.Errorf("FindAzurePrivateEndpointLinkID() got = %v, want %v", gotLinkID, tt.wantLinkID)
			}
		})
	}
}