diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 907f140e..682f7863 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -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' diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 2ec0455e..f4dcdacb 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -4,9 +4,11 @@ on: pull_request: branches: - '*' + - 'release/*' push: branches: - 'main' + - 'release/*' tags: - '*' workflow_dispatch: {} diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 7ff24f8f..7a54eca6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -10,9 +10,11 @@ on: pull_request: branches: - 'main' + - 'release/*' push: branches: - 'main' + - 'release/*' workflow_dispatch: {} jobs: diff --git a/.golangci.yaml b/.golangci.yaml index d12534c6..d7101b32 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -8,7 +8,6 @@ linters: - durationcheck - errcheck - exhaustive - - exportloopref - forbidigo - gochecknoinits - gocritic diff --git a/internal/test/assert.go b/internal/test/assert.go index 9265694a..d5eec362 100644 --- a/internal/test/assert.go +++ b/internal/test/assert.go @@ -2,6 +2,7 @@ package test import ( "bytes" + "context" "io" "net/http" "strings" @@ -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 diff --git a/pkg/clusters/addons/kong/enterprise.go b/pkg/clusters/addons/kong/enterprise.go index 4dc868b1..e36e0657 100644 --- a/pkg/clusters/addons/kong/enterprise.go +++ b/pkg/clusters/addons/kong/enterprise.go @@ -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 // ----------------------------------------------------------------------------- diff --git a/pkg/clusters/addons/kong/enterprise_test.go b/pkg/clusters/addons/kong/enterprise_test.go index 57f536e0..8fc2f555 100644 --- a/pkg/clusters/addons/kong/enterprise_test.go +++ b/pkg/clusters/addons/kong/enterprise_test.go @@ -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) + }) + } +}