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 committed Jul 18, 2023
1 parent 7ea6026 commit 8ca3216
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 146 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/kuksa-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ jobs:
export PATH=$PATH:$HOME/go/bin
go generate .
go test .
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest

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
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()
}
}

Loading

0 comments on commit 8ca3216

Please sign in to comment.