Skip to content

Commit 14b6c6c

Browse files
authored
Merge pull request #1546 from LiZhenCheng9527/refactor-kmeshctl-secret
fix error of ipsec handler unit test
2 parents d0fe176 + 6d531a8 commit 14b6c6c

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pkg/controller/encryption/ipsec/ipsec_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"kmesh.net/kmesh/daemon/options"
4545
"kmesh.net/kmesh/pkg/bpf"
4646
"kmesh.net/kmesh/pkg/constants"
47+
"kmesh.net/kmesh/pkg/controller/encryption"
4748
"kmesh.net/kmesh/pkg/kube"
4849
v1alpha1 "kmesh.net/kmesh/pkg/kube/apis/kmeshnodeinfo/v1alpha1"
4950
fakeKmeshClientset "kmesh.net/kmesh/pkg/kube/nodeinfo/clientset/versioned/fake"
@@ -96,7 +97,7 @@ var (
9697
},
9798
}
9899

99-
testKey = IpSecKey{
100+
testKey = encryption.IpSecKey{
100101
Spi: 1,
101102
AeadKeyName: "rfc4106(gcm(aes))",
102103
AeadKey: DecodeHex("abc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161"),

pkg/controller/encryption/ipsec/ipsec_handler_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/vishvananda/netlink"
3333

3434
"kmesh.net/kmesh/pkg/constants"
35+
"kmesh.net/kmesh/pkg/controller/encryption"
3536
)
3637

3738
// DecodeHex is a utility function to decode a hex string into bytes.
@@ -48,13 +49,13 @@ func TestLoadIPSecKey(t *testing.T) {
4849
aeadKey := DecodeHex("2dc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161")
4950
tests := []struct {
5051
name string
51-
keyData IpSecKey
52+
keyData encryption.IpSecKey
5253
expectError bool
5354
errorMsg string
5455
}{
5556
{ // Valid
5657
name: "valid_rfc4106_key",
57-
keyData: IpSecKey{
58+
keyData: encryption.IpSecKey{
5859
Spi: 1,
5960
AeadKeyName: "rfc4106(gcm(aes))",
6061
AeadKey: aeadKey,
@@ -64,7 +65,7 @@ func TestLoadIPSecKey(t *testing.T) {
6465
},
6566
{
6667
name: "invalid_algo_name",
67-
keyData: IpSecKey{
68+
keyData: encryption.IpSecKey{
6869
Spi: 3,
6970
AeadKeyName: "aes-gcm", // should start with "rfc"
7071
AeadKey: aeadKey,
@@ -75,7 +76,7 @@ func TestLoadIPSecKey(t *testing.T) {
7576
},
7677
{
7778
name: "empty_algo_name",
78-
keyData: IpSecKey{
79+
keyData: encryption.IpSecKey{
7980
Spi: 4,
8081
AeadKeyName: "",
8182
AeadKey: aeadKey,
@@ -161,13 +162,13 @@ func TestLoadIPSecKey(t *testing.T) {
161162
// Test multiple key loading (should update history)
162163
tests = []struct {
163164
name string
164-
keyData IpSecKey
165+
keyData encryption.IpSecKey
165166
expectError bool
166167
errorMsg string
167168
}{
168169
{
169170
name: "first_key",
170-
keyData: IpSecKey{
171+
keyData: encryption.IpSecKey{
171172
Spi: 1,
172173
AeadKeyName: "rfc4106(gcm(aes))",
173174
AeadKey: aeadKey,
@@ -177,7 +178,7 @@ func TestLoadIPSecKey(t *testing.T) {
177178
},
178179
{
179180
name: "second_key",
180-
keyData: IpSecKey{
181+
keyData: encryption.IpSecKey{
181182
Spi: 2,
182183
AeadKeyName: "rfc4106(gcm(aes))",
183184
AeadKey: DecodeHex("abc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161"),
@@ -334,7 +335,7 @@ func hasStateRule(state *netlink.XfrmState) (bool, error) {
334335
func TestCreateStateRule(t *testing.T) {
335336
handler := NewIpSecHandler()
336337
testKey := DecodeHex("2dc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161")
337-
ipsecKey := IpSecKey{
338+
ipsecKey := encryption.IpSecKey{
338339
Spi: 1001,
339340
AeadKeyName: "rfc4106(gcm(aes))",
340341
AeadKey: testKey,
@@ -536,7 +537,7 @@ func TestFlush(t *testing.T) {
536537

537538
// create state rule
538539
testKey := DecodeHex("2dc9410d7cd6b324461bf16db518646594276c5362c30fc476ebca3f1a394b6ed4462161")
539-
ipsecKey := IpSecKey{
540+
ipsecKey := encryption.IpSecKey{
540541
Spi: 1001,
541542
AeadKeyName: "rfc4106(gcm(aes))",
542543
AeadKey: testKey,

0 commit comments

Comments
 (0)