Skip to content

Commit

Permalink
Add support for replay_protection for Magic transit IPsec tunnels (#1710
Browse files Browse the repository at this point in the history
)

* added attribute to struct

* updated tests

* added changelog entry

* swap ReplayProtection to be a *bool

* Update 1710.txt

---------

Co-authored-by: Jacob Bednarz <jacob.bednarz@gmail.com>
Co-authored-by: Jacob Bednarz <jacob.bednarz@hey.com>
  • Loading branch information
3 people committed Apr 10, 2024
1 parent c6a36a2 commit a8a9c9f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/1710.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
magic_transit_ipsec_tunnel: Adds support for replay_protection boolean flag
```
1 change: 1 addition & 0 deletions magic_transit_ipsec_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type MagicTransitIPsecTunnel struct {
PskMetadata *MagicTransitIPsecTunnelPskMetadata `json:"psk_metadata,omitempty"`
RemoteIdentities *RemoteIdentities `json:"remote_identities,omitempty"`
AllowNullCipher bool `json:"allow_null_cipher"`
ReplayProtection *bool `json:"replay_protection,omitempty"`
}

// ListMagicTransitIPsecTunnelsResponse contains a response including IPsec tunnels.
Expand Down
60 changes: 58 additions & 2 deletions magic_transit_ipsec_tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func TestListMagicTransitIPsecTunnels(t *testing.T) {
"customer_endpoint": "203.0.113.1",
"cloudflare_endpoint": "203.0.113.2",
"interface_address": "192.0.2.0/31",
"description": "Tunnel for ISP X"
"description": "Tunnel for ISP X",
"replay_protection": true
}
]
}
Expand All @@ -53,6 +54,7 @@ func TestListMagicTransitIPsecTunnels(t *testing.T) {
CloudflareEndpoint: "203.0.113.2",
InterfaceAddress: "192.0.2.0/31",
Description: "Tunnel for ISP X",
ReplayProtection: BoolPtr(true),
},
}

Expand Down Expand Up @@ -83,7 +85,8 @@ func TestGetMagicTransitIPsecTunnel(t *testing.T) {
"cloudflare_endpoint": "203.0.113.2",
"interface_address": "192.0.2.0/31",
"description": "Tunnel for ISP X",
"allow_null_cipher": true
"allow_null_cipher": true,
"replay_protection": true
}
}
}`)
Expand All @@ -104,6 +107,7 @@ func TestGetMagicTransitIPsecTunnel(t *testing.T) {
InterfaceAddress: "192.0.2.0/31",
Description: "Tunnel for ISP X",
AllowNullCipher: true,
ReplayProtection: BoolPtr(true),
}

actual, err := client.GetMagicTransitIPsecTunnel(context.Background(), testAccountID, "c4a7362d577a6c3019a474fd6f485821")
Expand Down Expand Up @@ -224,6 +228,58 @@ func TestCreateMagicTransitIPsecTunnelsWithHealthcheck(t *testing.T) {
}
}

func TestCreateMagicTransitIPsecTunnelsWithReplayProtection(t *testing.T) {
setup()
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprint(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"ipsec_tunnels": [
{
"id": "c4a7362d577a6c3019a474fd6f485821",
"created_on": "2017-06-14T00:00:00Z",
"modified_on": "2017-06-14T05:20:00Z",
"name": "IPsec_1",
"customer_endpoint": "203.0.113.1",
"cloudflare_endpoint": "203.0.113.2",
"interface_address": "192.0.2.0/31",
"description": "Tunnel for ISP X",
"replay_protection": true
}
]
}
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/magic/ipsec_tunnels", handler)

createdOn, _ := time.Parse(time.RFC3339, "2017-06-14T00:00:00Z")
modifiedOn, _ := time.Parse(time.RFC3339, "2017-06-14T05:20:00Z")

want := []MagicTransitIPsecTunnel{{
ID: "c4a7362d577a6c3019a474fd6f485821",
CreatedOn: &createdOn,
ModifiedOn: &modifiedOn,
Name: "IPsec_1",
CustomerEndpoint: "203.0.113.1",
CloudflareEndpoint: "203.0.113.2",
InterfaceAddress: "192.0.2.0/31",
Description: "Tunnel for ISP X",
ReplayProtection: BoolPtr(true),
}}

actual, err := client.CreateMagicTransitIPsecTunnels(context.Background(), testAccountID, want)
if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
}

func TestUpdateMagicTransitIPsecTunnel(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit a8a9c9f

Please sign in to comment.