Skip to content

Commit

Permalink
Fix vulnerabilities and add go linter
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbosch authored and lukasmittag committed Jul 20, 2023
1 parent 2b2a908 commit d886dec
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 150 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/kuksa-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ jobs:
export PATH=$PATH:$HOME/go/bin
go generate .
go test .
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
working-directory: kuksa_go_client

4 changes: 2 additions & 2 deletions kuksa-client/kuksa_client/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ def _load_creds(self) -> Optional[grpc.ChannelCredentials]:
if self.private_key and self.certificate_chain:
private_key = self.private_key.read_bytes()
certificate_chain = self.certificate_chain.read_bytes()
logger.info(f"Using private client key {self.private_key} "
f"and chain/certificate {self.certificate_chain}")
# As of today there is no option in KUKSA.val Databroker to require client authentication
logger.info("Using client private key and certificates, mutual TLS supported if supported by server")
return grpc.ssl_channel_credentials(root_certificates, private_key, certificate_chain)
else:
logger.info(f"No client certificates provided, mutual TLS not supported!")
Expand Down
4 changes: 4 additions & 0 deletions kuksa_go_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ go mod tidy

This will update `go.mod`and `go.sum`.

## Linters

Our Continuous Integration verifies that the code pass the [Golang Linter](https://golangci-lint.run/usage/install).
To avoid failing PR builds it is recommended to run the linter manually before creating a Pull Request.
158 changes: 116 additions & 42 deletions kuksa_go_client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

//********************************************************************************
// Copyright (c) 2022 Contributors to the Eclipse Foundation
//
Expand All @@ -15,8 +14,8 @@
package main

import (
"testing"
"github.com/eclipse/kuksa.val/kuksa_go_client/kuksa_client"
"testing"
)

// Note: Go support two methods to write a string
Expand All @@ -32,96 +31,171 @@ import (
func TestArrayParseNoQuote(t *testing.T) {

array, _ := kuksa_client.GetArrayFromInput[string](`[say hello, abc]`)
if len(array) != 2 { t.Fail()}
if array[0] != "say hello" { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != "say hello" {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestArrayParseNoInsideQuote(t *testing.T) {

array, _ := kuksa_client.GetArrayFromInput[string](`["say hello","abc"]`)
if len(array) != 2 { t.Fail()}
if array[0] != "say hello" { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != "say hello" {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestArrayParseNoInsideQuoteSingle(t *testing.T) {

array, _ := kuksa_client.GetArrayFromInput[string](`['say hello','abc']`)
if len(array) != 2 { t.Fail()}
if array[0] != "say hello" { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != "say hello" {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestArrayParseDoubleQuote(t *testing.T) {

array, _ := kuksa_client.GetArrayFromInput[string](`["say \"hello\"","abc"]`)
if len(array) != 2 { t.Fail()}
if array[0] != `say "hello"` { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != `say "hello"` {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestArrayParseSingleQuote(t *testing.T) {

array, _ := kuksa_client.GetArrayFromInput[string](`[say \'hello\',"abc"]`)
if len(array) != 2 { t.Fail()}
if array[0] != `say 'hello'` { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != `say 'hello'` {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestArrayParseComma(t *testing.T) {

array, _ := kuksa_client.GetArrayFromInput[string](`["say, hello","abc"]`)
if len(array) != 2 { t.Fail()}
if array[0] != `say, hello` { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != `say, hello` {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestArraySquare(t *testing.T) {

array, _ := kuksa_client.GetArrayFromInput[string](`[say hello[], abc]`)
if len(array) != 2 { t.Fail()}
if array[0] != `say hello[]` { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != `say hello[]` {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestArrayEmptyStringQuoted(t *testing.T) {

array, _ := kuksa_client.GetArrayFromInput[string](`["", abc]`)
if len(array) != 2 { t.Fail()}
if array[0] != `` { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != `` {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestArrayEmptyStringNotQuoted(t *testing.T) {
// First item shall be ignored
array, _ := kuksa_client.GetArrayFromInput[string](`[, abc]`)
if len(array) != 1 { t.Fail()}
if array[0] != "abc" { t.Fail()}
if len(array) != 1 {
t.Fail()
}
if array[0] != "abc" {
t.Fail()
}
}

func TestDoubleComma(t *testing.T) {
// In this case the middle item is ignored
array, _ := kuksa_client.GetArrayFromInput[string](`[def,, abc]`)
if len(array) != 2 { t.Fail()}
if array[0] != "def" { t.Fail()}
if array[1] != "abc" { t.Fail()}
if len(array) != 2 {
t.Fail()
}
if array[0] != "def" {
t.Fail()
}
if array[1] != "abc" {
t.Fail()
}
}

func TestQuotesInStringValues(t *testing.T) {
array, _ := kuksa_client.GetArrayFromInput[string](`["dtc1, dtc2", dtc3, \" dtc4, dtc4\"]`)
if len(array) != 4 { t.Fail()}
if array[0] != "dtc1, dtc2" { t.Fail()}
if array[1] != "dtc3" { t.Fail()}
if array[2] != "\" dtc4" { t.Fail()}
if array[3] != "dtc4\"" { t.Fail()}
if len(array) != 4 {
t.Fail()
}
if array[0] != "dtc1, dtc2" {
t.Fail()
}
if array[1] != "dtc3" {
t.Fail()
}
if array[2] != "\" dtc4" {
t.Fail()
}
if array[3] != "dtc4\"" {
t.Fail()
}
}

func TestQuotesInStringValues2(t *testing.T) {
array, _ := kuksa_client.GetArrayFromInput[string]("['dtc1, dtc2', dtc3, \" dtc4, dtc4\"]")
if len(array) != 3 { t.Fail()}
if array[0] != "dtc1, dtc2" { t.Fail()}
if array[1] != "dtc3" { t.Fail()}
if array[2] != " dtc4, dtc4" { t.Fail()}
if len(array) != 3 {
t.Fail()
}
if array[0] != "dtc1, dtc2" {
t.Fail()
}
if array[1] != "dtc3" {
t.Fail()
}
if array[2] != " dtc4, dtc4" {
t.Fail()
}
}

5 changes: 4 additions & 1 deletion kuksa_go_client/kuksa_client/commn.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ func (cc *KuksaClientCommWs) startCommunication() error {
for {
req, ok := <-cc.sendChannel
if ok {
cc.connSocket.WriteMessage(websocket.TextMessage, []byte(req))
err := cc.connSocket.WriteMessage(websocket.TextMessage, []byte(req))
if err != nil {
log.Fatal("WriteMessage error: ", err)
}
}
}
}()
Expand Down
6 changes: 5 additions & 1 deletion kuksa_go_client/kuksa_client/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ func (cg *KuksaClientCommGrpc) UnsubscribeFromKuksaVal(id string) error {
cancel := *cg.cancel[id]
cancel()
client := *cg.subsChannel[id]
client.CloseSend()
err := client.CloseSend()
if err != nil {
log.Fatal("Error with CloseSend: ", err)
return err
}

return nil
}
Expand Down
Loading

0 comments on commit d886dec

Please sign in to comment.