Skip to content

Commit

Permalink
Merge branch 'main' into update-go-jose
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Turner committed Apr 1, 2024
2 parents 8625463 + 2f21f77 commit 09c8ae6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request: {}
workflow_dispatch: {}
env:
GO_VERSION: 1.19
GO_VERSION: 1.21
jobs:
lint-linux:
runs-on: ubuntu-latest
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ ifeq ($(arch1),x86_64)
arch2=amd64
else ifeq ($(arch1),aarch64)
arch2=arm64
else ifeq ($(arch1),arm64)
arch2=arm64
else
$(error unsupported ARCH: $(arch1))
endif
Expand Down Expand Up @@ -70,7 +72,7 @@ protoc_gen_go_grpc_base_dir := $(build_dir)/protoc-gen-go-grpc
protoc_gen_go_grpc_dir := $(protoc_gen_go_grpc_base_dir)/$(protoc_gen_go_grpc_version)-go$(go_version)
protoc_gen_go_grpc_bin := $(protoc_gen_go_grpc_dir)/protoc-gen-go-grpc

golangci_lint_version = v1.50.1
golangci_lint_version = v1.57.2
golangci_lint_dir = $(build_dir)/golangci_lint/$(golangci_lint_version)
golangci_lint_bin = $(golangci_lint_dir)/golangci-lint

Expand All @@ -81,7 +83,7 @@ apiprotos := \
# Toolchain
#############################################################################

go_version_full := 1.19.12
go_version_full := 1.21.8
go_version := $(go_version_full:.0=)
go_dir := $(build_dir)/go/$(go_version)

Expand Down
25 changes: 14 additions & 11 deletions v2/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@ run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 10m

# include examples
skip-dirs-use-default: false

skip-dirs:
- testdata$
- test/mock

skip-files:
- ".*\\.pb\\.go"

linters:
enable:
- bodyclose
- depguard
- goimports
- revive
- gosec
Expand All @@ -28,6 +17,16 @@ linters:
- gocritic

issues:
# include examples
exclude-dirs-use-default: false

exclude-dirs:
- testdata$
- test/mock

exclude-files:
- ".*\\.pb\\.go"

exclude-rules:
# exclude some lints from examples test files
- path: examples_test.go
Expand All @@ -40,3 +39,7 @@ linters-settings:
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0.0
revive:
rules:
- name: unused-parameter
disabled: true # It's useful to name parameters in library code for better readability
2 changes: 1 addition & 1 deletion v2/internal/test/fakeworkloadapi/workload_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func New(tb testing.TB) *WorkloadAPI {
x509BundlesChans: make(map[chan *workload.X509BundlesResponse]struct{}),
}

listener, err := newListener()
listener, err := newListener(tb)
require.NoError(tb, err)

server := grpc.NewServer()
Expand Down
3 changes: 2 additions & 1 deletion v2/internal/test/fakeworkloadapi/workload_api_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package fakeworkloadapi
import (
"fmt"
"net"
"testing"
)

func newListener() (net.Listener, error) {
func newListener(_ testing.TB) (net.Listener, error) {
return net.Listen("tcp", "localhost:0")
}

Expand Down
27 changes: 20 additions & 7 deletions v2/internal/test/fakeworkloadapi/workload_api_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
package fakeworkloadapi

import (
"crypto/rand"
"fmt"
"math/rand"
"math"
"math/big"
"net"
"strings"
"testing"
"time"

"github.com/Microsoft/go-winio"
"github.com/spiffe/go-spiffe/v2/proto/spiffe/workload"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
)

var maxUint64 = maxBigUint64()

func NewWithNamedPipeListener(tb testing.TB) *WorkloadAPI {
w := &WorkloadAPI{
x509Chans: make(map[chan *workload.X509SVIDResponse]struct{}),
jwtBundlesChans: make(map[chan *workload.JWTBundlesResponse]struct{}),
}

listener, err := winio.ListenPipe(fmt.Sprintf(`\\.\pipe\go-spiffe-test-pipe-%x`, rand.Uint64()), nil) //nolint: gosec // not use for crypto
listener, err := winio.ListenPipe(fmt.Sprintf(`\\.\pipe\go-spiffe-test-pipe-%x`, randUint64(tb)), nil)
require.NoError(tb, err)

server := grpc.NewServer()
Expand All @@ -45,12 +48,22 @@ func GetPipeName(s string) string {
return strings.TrimPrefix(s, `\\.\pipe`)
}

func init() {
rand.Seed(time.Now().UnixNano())
func maxBigUint64() *big.Int {
n := big.NewInt(0)
return n.SetUint64(math.MaxUint64)
}

func randUint64(t testing.TB) uint64 {
n, err := rand.Int(rand.Reader, maxUint64)
if err != nil {
t.Fail()
}

return n.Uint64()
}

func newListener() (net.Listener, error) {
return winio.ListenPipe(fmt.Sprintf(`\\.\pipe\go-spiffe-test-pipe-%x`, rand.Uint64()), nil) //nolint: gosec // not used for crypto
func newListener(tb testing.TB) (net.Listener, error) {
return winio.ListenPipe(fmt.Sprintf(`\\.\pipe\go-spiffe-test-pipe-%x`, randUint64(tb)), nil)
}

func getTargetName(addr net.Addr) string {
Expand Down

0 comments on commit 09c8ae6

Please sign in to comment.