diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..f2ce4c95 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,123 @@ +on: + push: + branches: + - main + pull_request: + +name: Go test coverage + +jobs: + coverage: + name: Measure test coverage (unit + integration tests) + runs-on: ubuntu-latest + steps: + - name: Install golang + uses: actions/setup-go@v5 + with: + go-version: "1.25" + + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Run unit tests with coverage + run: go test -coverpkg=./... -coverprofile=coverage-unit.out -covermode=atomic ./... + + - name: Set up coverage directory + run: | + GOCOVERDIR="$(pwd)/coverage-integration" + echo "GOCOVERDIR=${GOCOVERDIR}" >> "$GITHUB_ENV" + rm -rf "$GOCOVERDIR" + mkdir -p "$GOCOVERDIR" + + - name: Run integration tests with coverage + run: | + source test/ci/utils.sh + install_server + + passed=0 + failed=0 + for t in test/ci/test-*.sh; do + echo "=== Running: $t ===" + source "$t" + if run_test; then + passed=$((passed + 1)) + else + failed=$((failed + 1)) + echo "WARN: $t failed, continuing" + fi + cleanup || true + done + echo "=== Integration tests: $passed passed, $failed failed ===" + + - name: Merge coverage profiles + run: | + go tool covdata textfmt -i="$GOCOVERDIR" -o=coverage-integration.out + go install github.com/wadey/gocovmerge@latest + gocovmerge coverage-unit.out coverage-integration.out > coverage.out + + - name: Download base coverage breakdown + id: download-main-breakdown + uses: dawidd6/action-download-artifact@v6 + with: + branch: main + workflow_conclusion: success + name: main.breakdown + if_no_artifact_found: warn + + # continue-on-error: allow workflow to proceed to post PR comment and upload artifacts + - name: Check coverage thresholds + id: coverage + uses: vladopajic/go-test-coverage@v2 + continue-on-error: true + with: + config: .testcoverage.yml + breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }} + diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact == 'true' && 'main.breakdown' || '' }} + + - name: Find pull request ID + run: | + PR_DATA=$(curl -s -H "Authorization: token ${{ github.token }}" \ + "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.head_ref || github.ref_name }}&state=open") + PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number') + if [ "$PR_ID" != "null" ]; then + echo "pull_request_id=$PR_ID" >> "$GITHUB_ENV" + else + echo "No open pull request found for branch ${{ github.head_ref || github.ref_name }}." + fi + + - name: Post coverage report to PR + if: env.pull_request_id + uses: thollander/actions-comment-pull-request@v3 + with: + github-token: ${{ github.token }} + comment-tag: coverage-report + pr-number: ${{ env.pull_request_id }} + message: | + `go-test-coverage` report + ``` + ${{ fromJSON(steps.coverage.outputs.report) }}``` + + - name: Upload coverage breakdown + uses: actions/upload-artifact@v4 + if: github.ref_name == 'main' + with: + name: main.breakdown + path: main.breakdown + if-no-files-found: error + + - name: Generate HTML report + if: always() + run: go tool cover -html=coverage.out -o coverage.html + + - name: Upload coverage report + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage.html + + # fail the workflow if coverage thresholds are not met, after PR comment and artifacts are posted + - name: Fail if coverage thresholds not met + if: steps.coverage.outcome == 'failure' + shell: bash + run: echo "Coverage thresholds are not met." && exit 1 diff --git a/.gitignore b/.gitignore index 90abaf59..af8ea38b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ go-fdo-server go-fdo-server-*.tar.* rpmbuild test/workdir +coverage*.out +coverage*.html +coverage-integration/ diff --git a/.testcoverage.yml b/.testcoverage.yml new file mode 100644 index 00000000..a33d3a76 --- /dev/null +++ b/.testcoverage.yml @@ -0,0 +1,8 @@ +profile: coverage.out +threshold: + file: 0 + package: 0 + total: 0 +exclude: + paths: + - \.gen\.go$ diff --git a/go.mod b/go.mod index 0dc674d8..7282b8fb 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/jackc/pgx/v5 v5.7.6 github.com/mattn/go-sqlite3 v1.14.32 github.com/mitchellh/mapstructure v1.5.0 - github.com/oapi-codegen/runtime v1.1.2 + github.com/oapi-codegen/runtime v1.2.0 github.com/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.1 golang.org/x/time v0.11.0 @@ -38,7 +38,7 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/neilotoole/jsoncolor v0.7.1 // indirect - github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 // indirect + github.com/oapi-codegen/oapi-codegen/v2 v2.6.0 // indirect github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect diff --git a/go.sum b/go.sum index a42511eb..846e9192 100644 --- a/go.sum +++ b/go.sum @@ -105,10 +105,10 @@ github.com/nwidger/jsoncolor v0.3.2/go.mod h1:Cs34umxLbJvgBMnVNVqhji9BhoT/N/KinH github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 h1:5vHNY1uuPBRBWqB2Dp0G7YB03phxLQZupZTIZaeorjc= -github.com/oapi-codegen/oapi-codegen/v2 v2.5.1/go.mod h1:ro0npU1BWkcGpCgGD9QwPp44l5OIZ94tB3eabnT7DjQ= -github.com/oapi-codegen/runtime v1.1.2 h1:P2+CubHq8fO4Q6fV1tqDBZHCwpVpvPg7oKiYzQgXIyI= -github.com/oapi-codegen/runtime v1.1.2/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg= +github.com/oapi-codegen/oapi-codegen/v2 v2.6.0 h1:4i+F2cvwBFZeplxCssNdLy3MhNzUD87mI3HnayHZkAU= +github.com/oapi-codegen/oapi-codegen/v2 v2.6.0/go.mod h1:eWHeJSohQJIINJZzzQriVynfGsnlQVh0UkN2UYYcw4Q= +github.com/oapi-codegen/runtime v1.2.0 h1:RvKc1CVS1QeKSNzO97FBQbSMZyQ8s6rZd+LpmzwHMP4= +github.com/oapi-codegen/runtime v1.2.0/go.mod h1:Y7ZhmmlE8ikZOmuHRRndiIm7nf3xcVv+YMweKgG1DT0= github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY= github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw= github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c= @@ -173,8 +173,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk= github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ= github.com/woodsbury/decimal128 v1.3.0 h1:8pffMNWIlC0O5vbyHWFZAt5yWvWcrHA+3ovIIjVWss0= diff --git a/internal/handlers/components/models.gen.go b/internal/handlers/components/models.gen.go index 01d0beaa..b46f3782 100644 --- a/internal/handlers/components/models.gen.go +++ b/internal/handlers/components/models.gen.go @@ -1,6 +1,6 @@ // Package components provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT. +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. package components import ( @@ -33,6 +33,54 @@ const ( WiredAll MediumMedium = "wired_all" ) +// Valid indicates whether the value is a known member of the MediumMedium enum. +func (e MediumMedium) Valid() bool { + switch e { + case Wifi1: + return true + case Wifi2: + return true + case Wifi3: + return true + case Wifi4: + return true + case Wifi5: + return true + case Wifi6: + return true + case Wifi7: + return true + case Wifi8: + return true + case Wifi9: + return true + case WifiAll: + return true + case Wired1: + return true + case Wired2: + return true + case Wired3: + return true + case Wired4: + return true + case Wired5: + return true + case Wired6: + return true + case Wired7: + return true + case Wired8: + return true + case Wired9: + return true + case WiredAll: + return true + default: + return false + } +} + // Defines values for ProtocolType. const ( Coap ProtocolType = "coap" @@ -44,6 +92,28 @@ const ( Tls ProtocolType = "tls" ) +// Valid indicates whether the value is a known member of the ProtocolType enum. +func (e ProtocolType) Valid() bool { + switch e { + case Coap: + return true + case CoapTcp: + return true + case Http: + return true + case Https: + return true + case Rest: + return true + case Tcp: + return true + case Tls: + return true + default: + return false + } +} + // ClCertHash Client certificate hash for validation (SHA-256 or SHA-384) type ClCertHash struct { ClCertHash *string `json:"cl_cert_hash,omitempty"` diff --git a/internal/handlers/deviceca/handler.gen.go b/internal/handlers/deviceca/handler.gen.go index a4e428f2..facb67bd 100644 --- a/internal/handlers/deviceca/handler.gen.go +++ b/internal/handlers/deviceca/handler.gen.go @@ -2,7 +2,7 @@ // Package deviceca provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT. +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. package deviceca import ( @@ -33,6 +33,20 @@ const ( Valid ListTrustedDeviceCACertsParamsValidityStatus = "valid" ) +// Valid indicates whether the value is a known member of the ListTrustedDeviceCACertsParamsValidityStatus enum. +func (e ListTrustedDeviceCACertsParamsValidityStatus) Valid() bool { + switch e { + case Expired: + return true + case NotYetValid: + return true + case Valid: + return true + default: + return false + } +} + // Defines values for ListTrustedDeviceCACertsParamsSortBy. const ( CreatedAt ListTrustedDeviceCACertsParamsSortBy = "createdAt" @@ -42,12 +56,42 @@ const ( Subject ListTrustedDeviceCACertsParamsSortBy = "subject" ) +// Valid indicates whether the value is a known member of the ListTrustedDeviceCACertsParamsSortBy enum. +func (e ListTrustedDeviceCACertsParamsSortBy) Valid() bool { + switch e { + case CreatedAt: + return true + case Issuer: + return true + case NotAfter: + return true + case NotBefore: + return true + case Subject: + return true + default: + return false + } +} + // Defines values for ListTrustedDeviceCACertsParamsSortOrder. const ( Asc ListTrustedDeviceCACertsParamsSortOrder = "asc" Desc ListTrustedDeviceCACertsParamsSortOrder = "desc" ) +// Valid indicates whether the value is a known member of the ListTrustedDeviceCACertsParamsSortOrder enum. +func (e ListTrustedDeviceCACertsParamsSortOrder) Valid() bool { + switch e { + case Asc: + return true + case Desc: + return true + default: + return false + } +} + // TrustedDeviceCACert defines model for TrustedDeviceCACert. type TrustedDeviceCACert struct { // CreatedAt The timestamp when the certificate was added. @@ -195,7 +239,7 @@ func (siw *ServerInterfaceWrapper) ListTrustedDeviceCACerts(w http.ResponseWrite // ------------- Optional query parameter "limit" ------------- - err = runtime.BindQueryParameter("form", true, false, "limit", r.URL.Query(), ¶ms.Limit) + err = runtime.BindQueryParameterWithOptions("form", true, false, "limit", r.URL.Query(), ¶ms.Limit, runtime.BindQueryParameterOptions{Type: "integer", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err}) return @@ -203,7 +247,7 @@ func (siw *ServerInterfaceWrapper) ListTrustedDeviceCACerts(w http.ResponseWrite // ------------- Optional query parameter "offset" ------------- - err = runtime.BindQueryParameter("form", true, false, "offset", r.URL.Query(), ¶ms.Offset) + err = runtime.BindQueryParameterWithOptions("form", true, false, "offset", r.URL.Query(), ¶ms.Offset, runtime.BindQueryParameterOptions{Type: "integer", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "offset", Err: err}) return @@ -211,7 +255,7 @@ func (siw *ServerInterfaceWrapper) ListTrustedDeviceCACerts(w http.ResponseWrite // ------------- Optional query parameter "issuer" ------------- - err = runtime.BindQueryParameter("form", true, false, "issuer", r.URL.Query(), ¶ms.Issuer) + err = runtime.BindQueryParameterWithOptions("form", true, false, "issuer", r.URL.Query(), ¶ms.Issuer, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "issuer", Err: err}) return @@ -219,7 +263,7 @@ func (siw *ServerInterfaceWrapper) ListTrustedDeviceCACerts(w http.ResponseWrite // ------------- Optional query parameter "subject" ------------- - err = runtime.BindQueryParameter("form", true, false, "subject", r.URL.Query(), ¶ms.Subject) + err = runtime.BindQueryParameterWithOptions("form", true, false, "subject", r.URL.Query(), ¶ms.Subject, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "subject", Err: err}) return @@ -227,7 +271,7 @@ func (siw *ServerInterfaceWrapper) ListTrustedDeviceCACerts(w http.ResponseWrite // ------------- Optional query parameter "validityStatus" ------------- - err = runtime.BindQueryParameter("form", true, false, "validityStatus", r.URL.Query(), ¶ms.ValidityStatus) + err = runtime.BindQueryParameterWithOptions("form", true, false, "validityStatus", r.URL.Query(), ¶ms.ValidityStatus, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "validityStatus", Err: err}) return @@ -235,7 +279,7 @@ func (siw *ServerInterfaceWrapper) ListTrustedDeviceCACerts(w http.ResponseWrite // ------------- Optional query parameter "search" ------------- - err = runtime.BindQueryParameter("form", true, false, "search", r.URL.Query(), ¶ms.Search) + err = runtime.BindQueryParameterWithOptions("form", true, false, "search", r.URL.Query(), ¶ms.Search, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "search", Err: err}) return @@ -243,7 +287,7 @@ func (siw *ServerInterfaceWrapper) ListTrustedDeviceCACerts(w http.ResponseWrite // ------------- Optional query parameter "sortBy" ------------- - err = runtime.BindQueryParameter("form", true, false, "sortBy", r.URL.Query(), ¶ms.SortBy) + err = runtime.BindQueryParameterWithOptions("form", true, false, "sortBy", r.URL.Query(), ¶ms.SortBy, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sortBy", Err: err}) return @@ -251,7 +295,7 @@ func (siw *ServerInterfaceWrapper) ListTrustedDeviceCACerts(w http.ResponseWrite // ------------- Optional query parameter "sortOrder" ------------- - err = runtime.BindQueryParameter("form", true, false, "sortOrder", r.URL.Query(), ¶ms.SortOrder) + err = runtime.BindQueryParameterWithOptions("form", true, false, "sortOrder", r.URL.Query(), ¶ms.SortOrder, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sortOrder", Err: err}) return @@ -304,7 +348,7 @@ func (siw *ServerInterfaceWrapper) DeleteTrustedDeviceCACert(w http.ResponseWrit // ------------- Path parameter "fingerprint" ------------- var fingerprint string - err = runtime.BindStyledParameterWithOptions("simple", "fingerprint", r.PathValue("fingerprint"), &fingerprint, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "fingerprint", r.PathValue("fingerprint"), &fingerprint, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "fingerprint", Err: err}) return @@ -343,7 +387,7 @@ func (siw *ServerInterfaceWrapper) GetTrustedDeviceCACertByFingerprint(w http.Re // ------------- Path parameter "fingerprint" ------------- var fingerprint string - err = runtime.BindStyledParameterWithOptions("simple", "fingerprint", r.PathValue("fingerprint"), &fingerprint, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "fingerprint", r.PathValue("fingerprint"), &fingerprint, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "fingerprint", Err: err}) return diff --git a/internal/handlers/health/handler.gen.go b/internal/handlers/health/handler.gen.go index 9dd591b3..1b32afc0 100644 --- a/internal/handlers/health/handler.gen.go +++ b/internal/handlers/health/handler.gen.go @@ -2,7 +2,7 @@ // Package health provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT. +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. package health import ( diff --git a/internal/handlers/rvinfo/handler.gen.go b/internal/handlers/rvinfo/handler.gen.go index 9998822a..1e21c408 100644 --- a/internal/handlers/rvinfo/handler.gen.go +++ b/internal/handlers/rvinfo/handler.gen.go @@ -2,7 +2,7 @@ // Package rvinfo provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT. +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. package rvinfo import ( diff --git a/internal/handlers/rvto2addr/handler.gen.go b/internal/handlers/rvto2addr/handler.gen.go index aa13a06c..f5ed37a9 100644 --- a/internal/handlers/rvto2addr/handler.gen.go +++ b/internal/handlers/rvto2addr/handler.gen.go @@ -2,7 +2,7 @@ // Package rvto2addr provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT. +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. package rvto2addr import ( diff --git a/internal/handlers/voucher/handler.gen.go b/internal/handlers/voucher/handler.gen.go index 4eeeac56..f20d869e 100644 --- a/internal/handlers/voucher/handler.gen.go +++ b/internal/handlers/voucher/handler.gen.go @@ -2,7 +2,7 @@ // Package voucher provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT. +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.6.0 DO NOT EDIT. package voucher import ( @@ -36,6 +36,26 @@ const ( SHA512 HashAlgorithm = "SHA-512" ) +// Valid indicates whether the value is a known member of the HashAlgorithm enum. +func (e HashAlgorithm) Valid() bool { + switch e { + case HMACSHA256: + return true + case HMACSHA384: + return true + case HMACSHA512: + return true + case SHA256: + return true + case SHA384: + return true + case SHA512: + return true + default: + return false + } +} + // Defines values for PublicKeyType. const ( RSA2048RESTR PublicKeyType = "RSA2048RESTR" @@ -44,6 +64,22 @@ const ( SECP384R1 PublicKeyType = "SECP384R1" ) +// Valid indicates whether the value is a known member of the PublicKeyType enum. +func (e PublicKeyType) Valid() bool { + switch e { + case RSA2048RESTR: + return true + case RSAPKCS: + return true + case SECP256R1: + return true + case SECP384R1: + return true + default: + return false + } +} + // Defines values for ListOwnershipVouchersParamsSortBy. const ( CreatedAt ListOwnershipVouchersParamsSortBy = "createdAt" @@ -52,12 +88,40 @@ const ( UpdatedAt ListOwnershipVouchersParamsSortBy = "updatedAt" ) +// Valid indicates whether the value is a known member of the ListOwnershipVouchersParamsSortBy enum. +func (e ListOwnershipVouchersParamsSortBy) Valid() bool { + switch e { + case CreatedAt: + return true + case DeviceInfo: + return true + case Guid: + return true + case UpdatedAt: + return true + default: + return false + } +} + // Defines values for ListOwnershipVouchersParamsSortOrder. const ( Asc ListOwnershipVouchersParamsSortOrder = "asc" Desc ListOwnershipVouchersParamsSortOrder = "desc" ) +// Valid indicates whether the value is a known member of the ListOwnershipVouchersParamsSortOrder enum. +func (e ListOwnershipVouchersParamsSortOrder) Valid() bool { + switch e { + case Asc: + return true + case Desc: + return true + default: + return false + } +} + // Hash defines model for Hash. type Hash struct { // Algorithm Hash algorithm. @@ -76,7 +140,7 @@ type HashAlgorithm string // OwnershipVoucher defines model for OwnershipVoucher. type OwnershipVoucher struct { // CertChain X.509 certificate chain in PEM format (null for Intel EPID). - CertChain *[]string `json:"certChain"` + CertChain *[]string `json:"certChain,omitempty"` // DeviceInfo Device information string. DeviceInfo VoucherDeviceInfo `json:"deviceInfo"` @@ -168,7 +232,7 @@ type VoucherDeviceInfo = string // VoucherEntry defines model for VoucherEntry. type VoucherEntry struct { // Extra Additional optional data. - Extra *map[string]interface{} `json:"extra"` + Extra *map[string]interface{} `json:"extra,omitempty"` HeaderHash Hash `json:"headerHash"` PreviousHash Hash `json:"previousHash"` PublicKey PublicKey `json:"publicKey"` @@ -180,7 +244,7 @@ type VoucherGuid = string // VoucherHeader defines model for VoucherHeader. type VoucherHeader struct { // CertChainHash Hash of the certificate chain (required when certChain is present). - CertChainHash *Hash `json:"certChainHash"` + CertChainHash *Hash `json:"certChainHash,omitempty"` // DeviceInfo Device information string. DeviceInfo string `json:"deviceInfo"` @@ -296,7 +360,7 @@ func (siw *ServerInterfaceWrapper) ListOwnershipVouchers(w http.ResponseWriter, // ------------- Optional query parameter "limit" ------------- - err = runtime.BindQueryParameter("form", true, false, "limit", r.URL.Query(), ¶ms.Limit) + err = runtime.BindQueryParameterWithOptions("form", true, false, "limit", r.URL.Query(), ¶ms.Limit, runtime.BindQueryParameterOptions{Type: "integer", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err}) return @@ -304,7 +368,7 @@ func (siw *ServerInterfaceWrapper) ListOwnershipVouchers(w http.ResponseWriter, // ------------- Optional query parameter "offset" ------------- - err = runtime.BindQueryParameter("form", true, false, "offset", r.URL.Query(), ¶ms.Offset) + err = runtime.BindQueryParameterWithOptions("form", true, false, "offset", r.URL.Query(), ¶ms.Offset, runtime.BindQueryParameterOptions{Type: "integer", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "offset", Err: err}) return @@ -312,7 +376,7 @@ func (siw *ServerInterfaceWrapper) ListOwnershipVouchers(w http.ResponseWriter, // ------------- Optional query parameter "guid" ------------- - err = runtime.BindQueryParameter("form", true, false, "guid", r.URL.Query(), ¶ms.Guid) + err = runtime.BindQueryParameterWithOptions("form", true, false, "guid", r.URL.Query(), ¶ms.Guid, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "guid", Err: err}) return @@ -320,7 +384,7 @@ func (siw *ServerInterfaceWrapper) ListOwnershipVouchers(w http.ResponseWriter, // ------------- Optional query parameter "deviceInfo" ------------- - err = runtime.BindQueryParameter("form", true, false, "deviceInfo", r.URL.Query(), ¶ms.DeviceInfo) + err = runtime.BindQueryParameterWithOptions("form", true, false, "deviceInfo", r.URL.Query(), ¶ms.DeviceInfo, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "deviceInfo", Err: err}) return @@ -328,7 +392,7 @@ func (siw *ServerInterfaceWrapper) ListOwnershipVouchers(w http.ResponseWriter, // ------------- Optional query parameter "search" ------------- - err = runtime.BindQueryParameter("form", true, false, "search", r.URL.Query(), ¶ms.Search) + err = runtime.BindQueryParameterWithOptions("form", true, false, "search", r.URL.Query(), ¶ms.Search, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "search", Err: err}) return @@ -336,7 +400,7 @@ func (siw *ServerInterfaceWrapper) ListOwnershipVouchers(w http.ResponseWriter, // ------------- Optional query parameter "sortBy" ------------- - err = runtime.BindQueryParameter("form", true, false, "sortBy", r.URL.Query(), ¶ms.SortBy) + err = runtime.BindQueryParameterWithOptions("form", true, false, "sortBy", r.URL.Query(), ¶ms.SortBy, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sortBy", Err: err}) return @@ -344,7 +408,7 @@ func (siw *ServerInterfaceWrapper) ListOwnershipVouchers(w http.ResponseWriter, // ------------- Optional query parameter "sortOrder" ------------- - err = runtime.BindQueryParameter("form", true, false, "sortOrder", r.URL.Query(), ¶ms.SortOrder) + err = runtime.BindQueryParameterWithOptions("form", true, false, "sortOrder", r.URL.Query(), ¶ms.SortOrder, runtime.BindQueryParameterOptions{Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sortOrder", Err: err}) return @@ -397,7 +461,7 @@ func (siw *ServerInterfaceWrapper) DeleteOwnershipVoucher(w http.ResponseWriter, // ------------- Path parameter "guid" ------------- var guid string - err = runtime.BindStyledParameterWithOptions("simple", "guid", r.PathValue("guid"), &guid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "guid", r.PathValue("guid"), &guid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "guid", Err: err}) return @@ -436,7 +500,7 @@ func (siw *ServerInterfaceWrapper) GetOwnershipVoucherByGuid(w http.ResponseWrit // ------------- Path parameter "guid" ------------- var guid string - err = runtime.BindStyledParameterWithOptions("simple", "guid", r.PathValue("guid"), &guid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "guid", r.PathValue("guid"), &guid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "guid", Err: err}) return @@ -475,7 +539,7 @@ func (siw *ServerInterfaceWrapper) ExtendOwnershipVoucher(w http.ResponseWriter, // ------------- Path parameter "guid" ------------- var guid string - err = runtime.BindStyledParameterWithOptions("simple", "guid", r.PathValue("guid"), &guid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + err = runtime.BindStyledParameterWithOptions("simple", "guid", r.PathValue("guid"), &guid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: ""}) if err != nil { siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "guid", Err: err}) return diff --git a/test/ci/utils.sh b/test/ci/utils.sh index 10d05eb0..acd6e979 100644 --- a/test/ci/utils.sh +++ b/test/ci/utils.sh @@ -319,7 +319,8 @@ run_go_fdo_server() { shift 5 mkdir -p "$(dirname "${log}")" mkdir -p "$(dirname "${pid_file}")" - nohup "${bin_dir}/go-fdo-server" "${role}" "${address_port}" --db-type sqlite --db-dsn "file:${base_dir}/${name}.db" --log-level=debug "${@}" &>"${log}" & + GOCOVERDIR="${GOCOVERDIR:-}" nohup "${bin_dir}/go-fdo-server" "${role}" "${address_port}" --db-type sqlite \ + --db-dsn "file:${base_dir}/${name}.db" --log-level=debug "${@}" &>"${log}" & echo -n $! >"${pid_file}" } @@ -407,7 +408,13 @@ uninstall_client() { install_server() { mkdir -p "${bin_dir}" - make build && install -m 755 go-fdo-server "${bin_dir}" && rm -f go-fdo-server + if [[ -n "${GOCOVERDIR:-}" ]]; then + # Build with coverage instrumentation for code coverage measurement + go build -cover -covermode=atomic -o go-fdo-server . && + install -m 755 go-fdo-server "${bin_dir}" && rm -f go-fdo-server + else + make build && install -m 755 go-fdo-server "${bin_dir}" && rm -f go-fdo-server + fi } uninstall_server() {