Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: codeql

on:
push:
branches: [ main ]
branches: [ main, release/* ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [ main, release/* ]
schedule:
- cron: '18 13 * * 6'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
pull_request:
branches:
- '*'
- 'release/*'
push:
branches:
- 'main'
- 'release/*'
tags:
- '*'
workflow_dispatch: {}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ on:
pull_request:
branches:
- 'main'
- 'release/*'
push:
branches:
- 'main'
- 'release/*'
workflow_dispatch: {}

jobs:
Expand Down
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ linters:
- durationcheck
- errcheck
- exhaustive
- exportloopref
- forbidigo
- gochecknoinits
- gocritic
Expand Down
5 changes: 3 additions & 2 deletions internal/test/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"bytes"
"context"
"io"
"net/http"
"strings"
Expand Down Expand Up @@ -107,8 +108,8 @@ func EventuallyExpectResponse(
require.Eventually(
t,
func() bool {
r := req.Clone(t.Context())
resp, err := httpClient.Do(r) //nolint:gosec
r := req.Clone(context.Background())
resp, err := httpClient.Do(r)
if err != nil {
t.Logf("WARNING: error while waiting for %s: %v", req.URL, err)
return false
Expand Down
21 changes: 20 additions & 1 deletion pkg/clusters/addons/kong/enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,32 @@ type LicensePayload struct {
type LicenseData struct {
Payload LicensePayload `json:"payload"`
Signature string `json:"signature"`
Version int `json:"version"`
Version Version `json:"version"`
}

type License struct {
Data LicenseData `json:"license"`
}

// Version represents the version of a Kong Enterprise License.
// It is expected to be an integer and it can be specified in
// the license JSON as a string or as a number.
type Version int

// UnmarshalJSON unmarshals a Version from a JSON string or number.
func (v *Version) UnmarshalJSON(data []byte) error {
var version json.Number
if err := json.Unmarshal(data, &version); err != nil {
return err
}
i, err := version.Int64()
if err != nil {
return err
}
*v = Version(i)
return nil
}

// -----------------------------------------------------------------------------
// Kong License - Helper Functions
// -----------------------------------------------------------------------------
Expand Down
67 changes: 67 additions & 0 deletions pkg/clusters/addons/kong/enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,70 @@ func TestGetLicenseJSON(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, validLicenseJSON, licenseSecret.Data["license"])
}

func TestLicenseDataUnmarshalJSON(t *testing.T) {
tests := []struct {
name string
json string
want LicenseData
wantErr bool
}{
{
name: "version as string",
json: `{"payload":{},"signature":"sig","version":"1"}`,
want: LicenseData{
Version: 1,
Signature: "sig",
},
},
{
name: "version as integer",
json: `{"payload":{},"signature":"sig","version":1}`,
want: LicenseData{
Version: 1,
Signature: "sig",
},
},
{
name: "version missing",
json: `{"payload":{},"signature":"sig"}`,
want: LicenseData{
Signature: "sig",
},
},
{
name: "version as boolean",
json: `{"payload":{},"signature":"sig","version":true}`,
wantErr: true,
},
{
name: "full license with version as int",
json: `{"signature":"XXX","version":"1","payload":{"license_expiration_date":"2002-05-20","customer":"tests","license_creation_date":"2002-04-13","support_plan":"None","admin_seats":"1","product_subscription":"Product","license_key":"XXX"}}`,
want: LicenseData{
Version: 1,
Payload: LicensePayload{
ExpirationDate: "2002-05-20",
Customer: "tests",
CreationDate: "2002-04-13",
SupportPlan: "None",
AdminSeats: "1",
ProductSubscription: "Product",
Key: "XXX",
},
Signature: "XXX",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var ld LicenseData
err := json.Unmarshal([]byte(tt.json), &ld)
if tt.wantErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.want, ld)
})
}
}
Loading