From a221f04ba01d4576a4e9e5e624bc1dab9fafb0af Mon Sep 17 00:00:00 2001 From: Ricardo Yaben <32867697+RicYaben@users.noreply.github.com> Date: Wed, 13 Jul 2022 22:39:12 +0200 Subject: [PATCH] Added proxy endpoints and API design [#67 #58 #63] --- README.md | 13 +- api/proxy/proxy.go | 147 +++++++++++++ api/router.go | 136 ++++++++++-- go.mod | 27 ++- go.sum | 109 +++++----- internal/proxy/proxy.go | 32 ++- internal/proxy/tcpproxy.go | 2 +- test/api/api_test.go | 37 ++++ .../configuration/configuration_test.go | 6 +- test/internal/database/database_test.go | 14 +- test/internal/greeting/greeting_test.go | 15 -- test/internal/proxy/proxy_test.go | 193 ++++++++++++++++++ test/internal/terminal/greeting_test.yml | 25 --- test/internal/terminal/terminal_test.go | 36 ---- test/pkg/services/services_test.go | 2 +- 15 files changed, 604 insertions(+), 190 deletions(-) create mode 100644 api/proxy/proxy.go create mode 100644 test/api/api_test.go delete mode 100644 test/internal/greeting/greeting_test.go create mode 100644 test/internal/proxy/proxy_test.go delete mode 100644 test/internal/terminal/greeting_test.yml delete mode 100644 test/internal/terminal/terminal_test.go diff --git a/README.md b/README.md index f5dcf7d..c478e1a 100644 --- a/README.md +++ b/README.md @@ -86,15 +86,10 @@ Note: the list will be updated on support for additional scanning sources. ## 2. Requirements -Make sure that you abide by the following software and platform requirements before running RIoTPot, +Make sure that you abide by the following software and platform requirements before running RIoTPot: -- Ubuntu 18.04 or higher -- gcc 9.3.0 or higher -- GNU make 4.2.1 or higher -- Go version go1.16.4 or higher -- MongoDB v4.4.8 or higher, having a username as `superuser` and password as `password` -- Docker version 20.10.2 or higher -- Docker-compose version 1.29.2 or higher +- Ubuntu +- [Golang ^V1.16](https://go.dev/dl/) ## 3. Installation @@ -114,7 +109,7 @@ Follow the steps to get the RIoTPot project first: $ git clone git@github.com:aau-network-security/riotpot.git # 2. Navigate to the newly created directory with the repository -$ cd RIoTPot +$ cd riotpot ``` ### 3.1 Local Build diff --git a/api/proxy/proxy.go b/api/proxy/proxy.go new file mode 100644 index 0000000..f9ed4a4 --- /dev/null +++ b/api/proxy/proxy.go @@ -0,0 +1,147 @@ +package proxy + +import ( + "log" + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/riotpot/api" + "github.com/riotpot/internal/proxy" + "github.com/riotpot/pkg/services" +) + +// Structures used to serialize data +type Proxy struct { + ID int `json:"id" binding:"required" gorm:"primary_key"` + Port int `json:"port" binding:"required"` + Protocol string `json:"protocol" binding:"required"` + Status bool `json:"status"` + Service *Service `json:"service"` +} + +type Service struct { + ID int `json:"id" binding:"required" gorm:"primary_key"` + Port int `json:"port" binding:"required"` + Name string `json:"name" binding:"required"` + Host string `json:"host" binding:"required"` +} + +// Routes +var ( + // Proxy Routes + proxyRoutes = []api.Route{ + // Get proxies + api.NewRoute("/", "GET", getProxies), + // Get a proxy by port + api.NewRoute("/proxy/:port", "GET", getProxy), + // Post proxy by port + api.NewRoute("/proxy/:port", "POST", postProxy), + // Delete a proxy by port + api.NewRoute("/proxy/:port", "DELETE", delProxy), + // Patch (Not update) a proxy by port + api.NewRoute("/proxy/:port", "PATCH", patchProxy), + } +) + +// Routers +var ( + ProxyRouter = api.NewRouter("/proxies", proxyRoutes, nil) +) + +func newService(serv services.Service) (sv *Service) { + if serv != nil { + sv = &Service{ + Port: serv.GetPort(), + Name: serv.GetName(), + Host: serv.GetName(), + } + } + + return +} + +func newProxy(px proxy.Proxy) *Proxy { + serv := newService(px.Service()) + + return &Proxy{ + Port: px.Port(), + Protocol: px.Protocol(), + Status: px.Alive(), + Service: serv, + } +} + +// GET proxies registered +// Contains a filter to get proxies by port +func getProxies(ctx *gin.Context) { + casted := []Proxy{} + + // Iterate through the proxies registered + for _, px := range proxy.Proxies.Proxies() { + // Serialize the proxy + pr := newProxy(px) + // Append the proxy tot he casted + casted = append(casted, *pr) + } + + // Set the header and transform the struct to JSON format + ctx.JSON(http.StatusOK, casted) + +} + +// GET proxy by port ":port" +func getProxy(ctx *gin.Context) { + port, err := strconv.Atoi(ctx.Param("port")) + if err != nil { + log.Fatal(err) + } + + // Get the proxy + px, err := proxy.Proxies.GetProxy(port) + + // If the proxy could not be found, let the user know + if err != nil { + ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + + // Serialize the proxy and send it as a response + pr := newProxy(px) + ctx.JSON(http.StatusOK, pr) +} + +// POST a proxy by port ":port" +func postProxy(ctx *gin.Context) {} + +// DELETE a proxy by port ":port" +func delProxy(ctx *gin.Context) {} + +// PATCH proxy by port ":port" +// Can update port, protocol, status and service +func patchProxy(ctx *gin.Context) {} + +// Routers +/* +var ( + ProxyRouter = &api.AbstractRouter{ + path: "proxy", + routes: []Route{ + GetProxies, + GetProxy, + }, + } +) +*/ + +/* +func getProxies(ctx *gin.Context) { + // List of proxies + var proxies []Proxy + + // Send the response with the proxies + ctx.Header("Content-Type", "application/json") + ctx.JSON(http.StatusOK, proxies) + +} +*/ diff --git a/api/router.go b/api/router.go index ac80e49..8c687bc 100644 --- a/api/router.go +++ b/api/router.go @@ -1,20 +1,129 @@ package api import ( - "fmt" - "net/http" - "github.com/gin-gonic/gin" ) -// Proxy struct -type Proxy struct { - ID int `json:"id" binding:"required"` - Port int `json:"port" binding:"required"` +// Router interface +type Router interface { + // Returns the list of routes registered in the router + Routes() []Route + // Parent path for the router + Path() string + // Group the registered path + Group(parentGroup *gin.RouterGroup) *gin.RouterGroup +} + +type AbstractRouter struct { + // Inherits the Router + Router + // Routes registered in the router + routes []Route + // Parent path + path string + // Child Routers + // A router may have child routers + // For example: + // - /v1 + // .. - /router1 + // .. .. - /r1 + // .. .. - /r2 + // .. - /router2 + childs []Router +} + +// Returns the parent path +func (r *AbstractRouter) Path() string { + return r.path +} + +// Returns the list of routes registered in the router +func (r *AbstractRouter) Routes() []Route { + return r.routes +} + +// Add the handlers to a router group +func (r *AbstractRouter) addHandlers(parentGroup *gin.RouterGroup) *gin.RouterGroup { + // Iterate the routes and add the handlers registered in the + for _, route := range r.Routes() { + parentGroup.Handle(route.Method(), route.Path(), route.Handlers()...) + } + + return parentGroup +} + +// Add all the child routers to a group +func (r *AbstractRouter) addChilds(parentGroup *gin.RouterGroup) *gin.RouterGroup { + // Iterate through the child routers to add the routes + if len(r.childs) > 0 { + for _, child := range r.childs { + child.Group(parentGroup) + } + } + + return parentGroup +} + +// Create the group routes inside of the router +func (r *AbstractRouter) Group(parentGroup *gin.RouterGroup) *gin.RouterGroup { + // Create a group inside of the parent group for this child + childGroup := parentGroup.Group(r.Path()) + // Add the routes handlers for the current group + childGroup = r.addHandlers(childGroup) + // Add the child groups to the router + childGroup = r.addChilds(childGroup) + + return childGroup +} + +func NewRouter(path string, routes []Route, childs []Router) *AbstractRouter { + return &AbstractRouter{ + path: path, + routes: routes, + childs: childs, + } +} + +// Route that will be handled by the API +type Route interface { + // Raw function to handle the request + Handlers() gin.HandlersChain + // (Sub)Path to the route + Path() string + // Method used for the path + Method() string +} + +type AbstractRoute struct { + Route + path string + method string + handlers gin.HandlersChain +} + +func (ar *AbstractRoute) Path() string { + return ar.path +} + +func (ar *AbstractRoute) Method() string { + return ar.method +} + +func (ar *AbstractRoute) Handlers() gin.HandlersChain { + return ar.handlers +} + +func NewRoute(path string, method string, handlers ...gin.HandlerFunc) *AbstractRoute { + return &AbstractRoute{ + path: path, + method: method, + handlers: handlers, + } } // This function creates a new router that listens for new connections in // the designated port +/* func NewRouter(port int) { // New default Gin router router := gin.Default() @@ -23,19 +132,10 @@ func NewRouter(port int) { api := router.Group("/api") { // Proxies - api.GET("/proxies", getProxies) + api.GET("/proxies", nil) } router.NoRoute(func(ctx *gin.Context) { ctx.JSON(http.StatusNotFound, gin.H{}) }) router.Run(fmt.Sprintf(":%d", port)) } - -func getProxies(ctx *gin.Context) { - // List of proxies - var proxies []Proxy - - // Send the response with the proxies - ctx.Header("Content-Type", "application/json") - ctx.JSON(http.StatusOK, proxies) - -} +*/ diff --git a/go.mod b/go.mod index a03f457..558608a 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,9 @@ module github.com/riotpot go 1.18 require ( - github.com/buger/goterm v1.0.4 - github.com/gobuffalo/packr v1.30.1 github.com/google/uuid v1.3.0 github.com/plgd-dev/go-coap/v2 v2.6.0 + github.com/stretchr/testify v1.7.1 github.com/traetox/pty v0.0.0-20141209045113-df6c8cd2e0e6 github.com/xiegeo/modbusone v0.2.4-0.20200428173500-797d647e237d go.mongodb.org/mongo-driver v1.9.1 @@ -14,13 +13,29 @@ require ( gopkg.in/yaml.v3 v3.0.1 ) +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.0 // indirect + github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-playground/validator/v10 v10.10.0 // indirect + github.com/goccy/go-json v0.9.7 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/leodido/go-urn v1.2.1 // indirect + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.0.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/ugorji/go/codec v1.2.7 // indirect + google.golang.org/protobuf v1.28.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) + require ( github.com/dsnet/golib/memfile v1.0.0 // indirect + github.com/gin-gonic/gin v1.8.1 github.com/go-stack/stack v1.8.1 // indirect - github.com/gobuffalo/envy v1.10.1 // indirect - github.com/gobuffalo/packd v1.0.1 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/joho/godotenv v1.4.0 // indirect github.com/klauspost/compress v1.15.6 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect @@ -30,12 +45,12 @@ require ( github.com/pion/udp v0.1.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90 // indirect - github.com/rogpeppe/go-internal v1.8.1 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.1 // indirect github.com/xdg-go/stringprep v1.0.3 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect go.uber.org/atomic v1.9.0 // indirect + golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect diff --git a/go.sum b/go.sum index 7e9c06e..afbc779 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,11 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY= -github.com/buger/goterm v1.0.4/go.mod h1:HiFWV3xnkolgrBV3mY8m0X0Pumt4zg4QhbdOzQtB8tE= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -27,31 +21,29 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fxamacker/cbor/v2 v2.2.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= +github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/go-acme/lego v2.7.2+incompatible/go.mod h1:yzMNe9CasVUhkquNvti5nAtPmG94USbYxYrZfTkIn0M= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-ocf/go-coap/v2 v2.0.4-0.20200728125043-f38b86f047a7/go.mod h1:X9wVKcaOSx7wBxKcvrWgMQq1R2DNeA7NBLW2osIb8TM= github.com/go-ocf/kit v0.0.0-20200728130040-4aebdb6982bc/go.mod h1:TIsoMT/iB7t9P6ahkcOnsmvS83SIJsv9qXRfz/yLf6M= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= +github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= +github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= +github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= +github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= +github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= -github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= -github.com/gobuffalo/envy v1.8.1 h1:RUr68liRvs0TS1D5qdW3mQv2SjAsu1QWMCx1tG4kDjs= -github.com/gobuffalo/envy v1.8.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w= -github.com/gobuffalo/envy v1.10.1 h1:ppDLoXv2feQ5nus4IcgtyMdHQkKng2lhJCIm33cblM0= -github.com/gobuffalo/envy v1.10.1/go.mod h1:AWx4++KnNOW3JOeEvhSaq+mvgAvnMYOY1XSIin4Mago= -github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs= -github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4= -github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q= -github.com/gobuffalo/packd v1.0.1 h1:U2wXfRr4E9DH8IdsDLlRFwTZTK7hLfq9qT/QHXGVe/0= -github.com/gobuffalo/packd v1.0.1/go.mod h1:PP2POP3p3RXGz7Jh6eYEf93S7vA2za6xM7QT85L4+VY= -github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg= -github.com/gobuffalo/packr v1.30.1/go.mod h1:ljMyFO2EcrnzsHsN99cvbq055Y9OhRrIaviy289eRuk= -github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw= +github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= +github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= @@ -66,7 +58,7 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -74,42 +66,41 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9GbyCZHuPgZsrbyIbyKhSzOpg6s= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= -github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= -github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= -github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.6 h1:6D9PcO8QWu0JyaQ2zUMmu16T1T+zjjEpP91guRsvDfY= github.com/klauspost/compress v1.15.6/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/lestrrat-go/iter v0.0.0-20200422075355-fc1769541911/go.mod h1:zIdgO1mRKhn8l9vrZJZz9TUMMFbQbLeTsbqPDrJ/OJc= github.com/lestrrat-go/jwx v1.0.2/go.mod h1:TPF17WiSFegZo+c20fdpw49QD+/7n4/IsGvEmCSWwT0= github.com/lestrrat-go/pdebug v0.0.0-20200204225717-4d6bd78da58d/go.mod h1:B06CSso/AWxiPejj+fheUINGeBKeeEZNt8w+EoU7+L8= -github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= @@ -120,13 +111,16 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/panjf2000/ants/v2 v2.4.3/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU= +github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pion/dtls/v2 v2.0.1-0.20200503085337-8e86b3a7d585/go.mod h1:/GahSOC8ZY/+17zkaGJIG4OUkSGAcZu/N/g3roBOCkM= github.com/pion/dtls/v2 v2.0.10-0.20210502094952-3dc563b9aede/go.mod h1:86wv5dgx2J/z871nUR+5fTTY9tISLUlo+C5Gm86r1Hs= github.com/pion/dtls/v2 v2.1.5 h1:jlh2vtIyUBShchoTDqpCCqiYCyRFJ/lvf/gQ8TALs+c= @@ -154,22 +148,10 @@ github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90/go.mod h1:Z7oKFLSG github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.4.0 h1:LUa41nrWTQNGhzdsZ5lTnkwbNjj6rXTdazA1cSdjkOY= -github.com/rogpeppe/go-internal v1.4.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= -github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= -github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -179,25 +161,26 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/traetox/pty v0.0.0-20141209045113-df6c8cd2e0e6 h1:rXBu3Xm94OsXCsv6J4G1QJqP59qpd2AtDXrvF+fnP/o= github.com/traetox/pty v0.0.0-20141209045113-df6c8cd2e0e6/go.mod h1:8GTrdL86wm4Eq6g80gbQjlcmCvDd3uIyIwfpP95gw5g= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= +github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.12.0/go.mod h1:229t1eWu9UXTPmoUkbpN/fctKPBY4IJoFXQnxHGXy6E= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= -github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= @@ -205,8 +188,6 @@ github.com/xiegeo/coloredgoroutine v0.1.1 h1:L6EaQHWIY+oIlKpj5ORu9hIorsLbQwTAStE github.com/xiegeo/coloredgoroutine v0.1.1/go.mod h1:d3jyamWlthEBXOL5qUpKOaaKSJM75HuCIn/z9f4ylrs= github.com/xiegeo/modbusone v0.2.4-0.20200428173500-797d647e237d h1:JlZE7TjLDXI+UkyBvy2AT6qsuI6WakLNb0cmBx+PCrM= github.com/xiegeo/modbusone v0.2.4-0.20200428173500-797d647e237d/go.mod h1:8bu9WscqP6hQ/Yr9+ziyGcXe28otlkUWOYgf071TTiI= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= @@ -222,10 +203,8 @@ go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKY go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -233,10 +212,13 @@ golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d h1:vtUKgx8dahOomfFzLREU8nSv25YHnTgLBn4rDnWZdU0= +golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -276,24 +258,21 @@ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDE golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180831094639-fa5fdf94c789/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU= @@ -317,7 +296,6 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -326,7 +304,6 @@ golang.org/x/tools v0.0.0-20200417140056-c07e33ef3290/go.mod h1:EkVYQZoAsY45+roY golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -344,15 +321,21 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 8191337..153c2bd 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -13,6 +13,11 @@ const ( UDP = "udp" ) +var ( + // Instantiate the proxy manager to allow other applications work with the proxies + Proxies = NewProxyManager() +) + // Proxy interface. type Proxy interface { // Start proxy function @@ -25,10 +30,12 @@ type Proxy interface { // Setter and Getter for the port SetPort(port int) (int, error) - GetPort() int + Port() int + Protocol() string // Set the service in the proxy SetService(service services.Service) + Service() services.Service } // Abstraction of the proxy endpoint @@ -102,7 +109,7 @@ func (pe *AbstractProxy) SetPort(port int) (p int, err error) { } // Returns the proxy port -func (pe *AbstractProxy) GetPort() int { +func (pe *AbstractProxy) Port() int { return pe.port } @@ -110,6 +117,16 @@ func (pe *AbstractProxy) SetService(service services.Service) { pe.service = service } +// Returns the service +func (pe *AbstractProxy) Service() services.Service { + return pe.service +} + +// Returns the service +func (pe *AbstractProxy) Protocol() string { + return pe.protocol +} + // Create a new instance of the proxy func NewProxyEndpoint(port int, protocol string) (pe Proxy, err error) { // Get the proxy for UDP or TCP @@ -129,6 +146,8 @@ type ProxyManager interface { CreateProxy(port int) (*TCPProxy, error) // Delete a proxy from the list DeleteProxy(port int) error + // Get all the proxies registered + Proxies() []Proxy // Get a proxy by the port it uses GetProxy(port int) (*TCPProxy, error) // Set the service for a proxy @@ -148,6 +167,7 @@ type ProxyManagerItem struct { middlewares *MiddlewareManagerItem } +// Create a new proxy and add it to the manager func (pm *ProxyManagerItem) CreateProxy(protocol string, port int) (pe Proxy, err error) { // Check if there is another proxy with the same port if proxy, _ := pm.GetProxy(port); proxy != nil { @@ -168,7 +188,7 @@ func (pm *ProxyManagerItem) CreateProxy(protocol string, port int) (pe Proxy, er func (pm *ProxyManagerItem) DeleteProxy(port int) (err error) { // Iterate the registered proxies for the proxy using the given port, and stop and remove it from the slice for ind, proxy := range pm.proxies { - if proxy.GetPort() == port { + if proxy.Port() == port { // Stop the proxy, just in case proxy.Stop() // Remove it from the slice by replacing it with the last item from the slice, and reducing the slice @@ -186,11 +206,15 @@ func (pm *ProxyManagerItem) DeleteProxy(port int) (err error) { return } +func (pm *ProxyManagerItem) Proxies() []Proxy { + return pm.proxies +} + // Returns a proxy by the port number func (pm *ProxyManagerItem) GetProxy(port int) (pe Proxy, err error) { // Iterate the proxies registered, and if the proxy using the given port is found, return it for _, proxy := range pm.proxies { - if proxy.GetPort() == port { + if proxy.Port() == port { pe = proxy return } diff --git a/internal/proxy/tcpproxy.go b/internal/proxy/tcpproxy.go index 06ed189..61cc5b0 100644 --- a/internal/proxy/tcpproxy.go +++ b/internal/proxy/tcpproxy.go @@ -89,7 +89,7 @@ func (tcpProxy *TCPProxy) Stop() (err error) { // Get or create a new listener func (tcpProxy *TCPProxy) GetListener() net.Listener { if tcpProxy.listener == nil || !tcpProxy.Alive() { - listener, err := net.Listen(tcpProxy.protocol, fmt.Sprintf(":%d", tcpProxy.GetPort())) + listener, err := net.Listen(tcpProxy.protocol, fmt.Sprintf(":%d", tcpProxy.Port())) if err != nil { log.Fatal(err) } diff --git a/test/api/api_test.go b/test/api/api_test.go new file mode 100644 index 0000000..f50e94a --- /dev/null +++ b/test/api/api_test.go @@ -0,0 +1,37 @@ +package api + +import ( + "io/ioutil" + "net/http" + "net/http/httptest" + "testing" + + "github.com/gin-gonic/gin" + api "github.com/riotpot/api/proxy" + "github.com/riotpot/internal/proxy" + "github.com/stretchr/testify/assert" +) + +func SetupRouter() *gin.Engine { + // Create a router + router := gin.Default() + group := router.Group("/api") + // Add the proxy routes + group = api.ProxyRouter.Group(group) + + return router +} + +func TestApi(t *testing.T) { + mockResponse := `[{"id":0,"port":8080,"protocol":"tcp","status":false,"service":null}]` + // Add a proxy to the manager + proxy.Proxies.CreateProxy(proxy.TCP, 8080) + router := SetupRouter() + + req, _ := http.NewRequest("GET", "/api/proxies/", nil) + w := httptest.NewRecorder() + router.ServeHTTP(w, req) + + responseData, _ := ioutil.ReadAll(w.Body) + assert.Equal(t, mockResponse, string(responseData)) +} diff --git a/test/internal/configuration/configuration_test.go b/test/internal/configuration/configuration_test.go index a74686e..f13760f 100644 --- a/test/internal/configuration/configuration_test.go +++ b/test/internal/configuration/configuration_test.go @@ -9,7 +9,7 @@ import ( ) var ( - settings = cfg.Settings{} + settings = cfg.Configuration{} path = "./configuration_test.yml" ) @@ -17,7 +17,7 @@ var ( // TODO: Since the test is broken the real function has not been tested. Change this. func TestLoadAndSaveConf(t *testing.T) { // load the configuration - err := settings.Load(path) + err := settings.Load() if err != nil { t.Error(err) } @@ -31,7 +31,7 @@ func TestLoadAndSaveConf(t *testing.T) { t.Logf("%s\n", string(out)) // save the configuration - err = settings.Save(path) + err = settings.Save() if err != nil { t.Error(err) } diff --git a/test/internal/database/database_test.go b/test/internal/database/database_test.go index 89dcc8c..c4637ff 100644 --- a/test/internal/database/database_test.go +++ b/test/internal/database/database_test.go @@ -3,12 +3,9 @@ package database import ( "context" "testing" - "time" "github.com/riotpot/internal/configuration" "github.com/riotpot/internal/database" - "github.com/riotpot/pkg/models" - "go.mongodb.org/mongo-driver/bson" ) // Runs a simple test to check the health of MongoDB database and the configuration. @@ -22,12 +19,12 @@ func TestDatabaseConnection(t *testing.T) { var ( // Load an identity for the database - id = configuration.ConfigIdentity{ + id = configuration.IdentityConfiguration{ Name: "test_db", } // Load a configuration for the database - config = configuration.ConfigDatabase{ + config = configuration.DatabaseConfiguration{ Username: "superuser", Password: "password", Host: "127.0.0.1", @@ -35,10 +32,7 @@ func TestDatabaseConnection(t *testing.T) { Port: "27017", } - // Load a database object - db = database.Database{ - Config: config, - } + db = database.NewDatabase(config) ) // Connect to the db @@ -51,6 +45,7 @@ func TestDatabaseConnection(t *testing.T) { } // TODO: Delete this test, it does too many things. Divide it at the very least +/* func TestDatabaseInsert(t *testing.T) { var ( @@ -132,3 +127,4 @@ func TestDatabaseInsert(t *testing.T) { t.Error("Database not accessible") } } +*/ diff --git a/test/internal/greeting/greeting_test.go b/test/internal/greeting/greeting_test.go deleted file mode 100644 index c58cc6c..0000000 --- a/test/internal/greeting/greeting_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package greeting - -import ( - "testing" - - "github.com/riotpot/internal/greeting" -) - -func TestExampleGreet(t *testing.T) { - g := greeting.Greet{ - Tutorial: false, - } - - g.Greeting() -} diff --git a/test/internal/proxy/proxy_test.go b/test/internal/proxy/proxy_test.go new file mode 100644 index 0000000..5beaa77 --- /dev/null +++ b/test/internal/proxy/proxy_test.go @@ -0,0 +1,193 @@ +package proxy + +import ( + "fmt" + "io/ioutil" + "net" + "testing" + + "github.com/riotpot/internal/proxy" + "github.com/riotpot/pkg/services" + "github.com/stretchr/testify/assert" +) + +const ( + proxyPort = 8080 + serverPort = 8081 + protocol = proxy.TCP +) + +// Test to create a service, the ports at the end should be the same +func TestCreateProxy(t *testing.T) { + // Instantiate the proxy + pr, err := proxy.NewProxyEndpoint(proxyPort, protocol) + + if err != nil { + t.Error(err) + } + + assert.Equal(t, pr.Port(), proxyPort, "The ports should be the same") +} + +// Test to start the proxy +// It creates a local client and server. The message should be transferred from +// the client to the server trhough the proxy +func TestStartProxy(t *testing.T) { + assert := assert.New(t) + + // use a channel to hand off the error + errs := make(chan error, 1) + + // Message to send + message := "Hi there!" + ret := "" + + // Instantiate the proxy + pr, err := proxy.NewProxyEndpoint(proxyPort, protocol) + if err != nil { + t.Fatal(err) + } + + // Create a new abstract service + service := services.NewAbstractPluginService("http", serverPort, protocol) + + // Set the service + pr.SetService(service) + + // Start a listener for that port and accept anything (server) + go func() { + l, err := net.Listen(protocol, service.GetAddress()) + if err != nil { + errs <- err + } + defer l.Close() + + // Accept the connection + for { + conn, err := l.Accept() + if err != nil { + errs <- err + } + defer conn.Close() + + buf, err := ioutil.ReadAll(conn) + if err != nil { + errs <- err + } + + ret = string(buf[:]) + + // Check that the first message we got is the same as the expected + assert.Equal(ret, message, "The messages must be equal") + + // Close the connection and return + l.Close() + return + } + }() + + // Start the proxy + pr.Start() + + // Start a new client connections that sends the message (client) + go func() { + // Connect to the proxy + conn, err := net.Dial(protocol, fmt.Sprintf(":%d", proxyPort)) + if err != nil { + errs <- err + } + defer conn.Close() + + // Send the message through the connection + if _, err := fmt.Fprint(conn, message); err != nil { + errs <- err + } + }() + + // wait for it + err = <-errs + if err != nil { + t.Fatal(err) + } + + assert.Equal(ret, message, "The messages must be equal") +} + +// Test to stop the proxy +func TestStopProxy(t *testing.T) { + assert := assert.New(t) + // use a channel to hand off the error + errs := make(chan error, 1) + + // Instantiate the proxy + pr, err := proxy.NewProxyEndpoint(proxyPort, protocol) + if err != nil { + t.Fatal(err) + } + + // Create a new abstract service + service := services.NewAbstractPluginService("http", serverPort, protocol) + + // Set the service + pr.SetService(service) + + // Start a listener for that port and accept anything (server) + go func() { + l, err := net.Listen(protocol, service.GetAddress()) + if err != nil { + errs <- err + } + defer l.Close() + + // Accept the connection + for { + conn, err := l.Accept() + if err != nil { + errs <- err + } + defer conn.Close() + + // Close the connection and return + l.Close() + return + } + }() + + // Start the proxy + pr.Start() + + // Give the proxy some time to start + alive := pr.Alive() + assert.Equal(alive, true, "The proxy is running") + + // Stop the service + pr.Stop() + alive = pr.Alive() + assert.Equal(alive, false, "The proxy is stop") +} + +func TestCreateNewProxy(t *testing.T) { + // Create a new proxy manager + proxyManager := proxy.NewProxyManager() + // Add a proxy + _, err := proxyManager.CreateProxy(proxy.TCP, proxyPort) + + // There would be an error if the proxy was already registered or the port is unavailable + if err != nil { + t.Fatal(err) + } +} + +func TestDeleteProxy(t *testing.T) { + // Create a new proxy manager + proxyManager := proxy.NewProxyManager() + // Add a proxy + proxyManager.CreateProxy(proxy.TCP, proxyPort) + // Delete the proxy + err := proxyManager.DeleteProxy(proxyPort) + + // There may be an error if the proxy was not found + if err != nil { + t.Fatal(err) + } +} diff --git a/test/internal/terminal/greeting_test.yml b/test/internal/terminal/greeting_test.yml deleted file mode 100644 index a084735..0000000 --- a/test/internal/terminal/greeting_test.yml +++ /dev/null @@ -1,25 +0,0 @@ -lines: - # Clear the console first - - animation: clear - - - str: | - 8888888b. 8888888 88888888888 8888888b. 888 - 888 Y88b 888 888 888 Y88b 888 - 888 888 888 888 888 888 888 - 888 d88P 888 .d88b. 888 888 d88P .d88b. 888888 - 8888888P" 888 d88""88b 888 8888888P" d88""88b 888 - 888 T88b 888 888 888 888 888 888 888 888 - 888 T88b 888 Y88..88P 888 888 Y88..88P Y88b. - 888 T88b 8888888 "Y88P" 888 888 "Y88P" "Y888 - h_align: center - - - str: "An IoT and OT honeypot." - h_align: center - - str: "~ By Shreyas S." - h_align: center - - - animation: delay - - animation: clear - - #- input: true ---- \ No newline at end of file diff --git a/test/internal/terminal/terminal_test.go b/test/internal/terminal/terminal_test.go deleted file mode 100644 index dac154e..0000000 --- a/test/internal/terminal/terminal_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package cli - -import ( - "os" - "testing" - - "github.com/riotpot/internal/cli" -) - -var ( - path = "./greeting_test.yml" -) - -func TestYBookParse(t *testing.T) { - book := cli.YBook{} - term := cli.Terminal{} - - reader, err := os.ReadFile(path) - - if err != nil { - t.Error(err) - } - - book.Parse(reader) - - for _, page := range book.Pages { - for _, line := range page.Lines { - term.Read(line) - } - } -} - -func TestLecture(t *testing.T) { - term := cli.Terminal{} - term.Lecture(path) -} diff --git a/test/pkg/services/services_test.go b/test/pkg/services/services_test.go index 7650f98..c938273 100644 --- a/test/pkg/services/services_test.go +++ b/test/pkg/services/services_test.go @@ -29,7 +29,7 @@ func init() { "../../../pkg/plugin/coapd/plugin.so", } - services := services.Services{} + services := services.Supervisor{} services.AutoRegister(servs) serviceToTest := COAP