Skip to content

Commit

Permalink
Add initial event structure and test for Client VPN
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoul committed Dec 11, 2020
1 parent 451810d commit 4a91aa9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
20 changes: 20 additions & 0 deletions events/clientvpn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package events

type ClientVPNConnectionHandlerRequest struct {
ConnectionID string `json:"connection-id"`
EndpointID string `json:"endpoint-id"`
CommonName string `json:"common-name"`
Username string `json:"username"`
OSPlatform string `json:"platform"`
OSPlatformVersion string `json:"platform-version"`
PublicIP string `json:"public-ip"`
ClientOpenVPNVersion string `json:"client-openvpn-version"`
SchemaVersion string `json:"schema-version"`
}

type ClientVPNConnectionHandlerResponse struct {
Allow bool `json:"allow"`
ErrorMsgOnFailedPostureCompliance string `json:"error-msg-on-failed-posture-compliance"`
PostureComplianceStatuses []string `json:"posture-compliance-statuses"`
SchemaVersion string `json:"schema-version"`
}
36 changes: 36 additions & 0 deletions events/clientvpn_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package events

import (
"encoding/json"
"io/ioutil"
"testing"

"github.com/aws/aws-lambda-go/events/test"
"github.com/stretchr/testify/assert"
)

func TestClientVPNConnectionHandlerRequestMarshaling(t *testing.T) {
// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/clientvpn-connectionhandler-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

// de-serialize into ClientVPNConnectionHandlerRequest
var inputEvent ClientVPNConnectionHandlerRequest
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// serialize to json
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestClientVPNConnectionHandlerRequestMarshalingMalformedJson(t *testing.T) {
test.TestMalformedJson(t, ClientVPNConnectionHandlerRequest{})
}
11 changes: 11 additions & 0 deletions events/testdata/clientvpn-connectionhandler-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"connection-id": "cvpn-connection-04e7e1b2f0daf9460",
"endpoint-id": "cvpn-endpoint-0f13eab7f860433cc",
"common-name": "",
"username": "username",
"platform": "",
"platform-version": "",
"public-ip": "10.11.12.13",
"client-openvpn-version": "",
"schema-version": "v1"
}

0 comments on commit 4a91aa9

Please sign in to comment.