diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..847173a70c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI + +on: + push: + branches: [main, dev] + pull_request: + branches: [main, dev] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +permissions: + contents: read + +jobs: + test: + strategy: + fail-fast: false + matrix: + include: + - { os: ubuntu-latest, go: '1.26' } + - { os: windows-latest, go: '1.26' } + - { os: ubuntu-latest, go: '1.20' } + runs-on: ${{ matrix.os }} + env: + CGO_ENABLED: 0 + GOTOOLCHAIN: local + steps: + # Keep testdata byte-exact: autocrlf on Windows runners rewrites LF. + - name: Disable CRLF conversion + if: runner.os == 'Windows' + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - uses: actions/checkout@v5 + - uses: actions/setup-go@v6 + with: + go-version: ${{ matrix.go }} + # go.mod says go 1.20, so loopclosure flags upstream Go tests that assume + # per-iteration loop variables; the rest of vet stays on. + - name: Vet + if: matrix.go == '1.26' + run: go vet -loopclosure=false ./... + - name: Test + run: go test -count=1 ./... + + race: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-go@v6 + with: + go-version: '1.26' + - name: Test with the race detector + run: go test -race -count=1 ./... diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 381bbab17b..0000000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,46 +0,0 @@ -# This workflow will build a golang project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go - -name: "Go" - -on: - push: - pull_request: - -jobs: - build: - strategy: - matrix: - os: - - 'ubuntu-latest' # amd64 linux - - 'windows-latest' # amd64 windows - - 'macos-latest' # arm64 macos - - 'ubuntu-24.04-arm' # arm64 linux - - 'macos-15-intel' # amd64 macos - go-version: - - '1.25' - - '1.24' - - '1.23' - - '1.22' - - '1.21' - - '1.20' - fail-fast: false - runs-on: ${{ matrix.os }} - defaults: - run: - shell: bash - env: - CGO_ENABLED: 0 - GOTOOLCHAIN: local - # Fix mingw trying to be smart and converting paths https://github.com/moby/moby/issues/24029#issuecomment-250412919 - MSYS_NO_PATHCONV: true - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-go@v6 - with: - go-version: ${{ matrix.go-version }} - - run: go version - - name: Build - run: go build -v ./... - - name: Test - run: go test -v ./... diff --git a/handshake_test.go b/handshake_test.go index ad6405b907..1b01a8d312 100644 --- a/handshake_test.go +++ b/handshake_test.go @@ -496,7 +496,11 @@ func testUtlsHandshake(t *testing.T, clientConfig, serverConfig *Config, spec *C } if spec != nil { ucli := UClient(c, clientConfig, HelloCustom) - if err = ucli.ApplyPreset(spec); err != nil { + // Do not assign to the outer err: the test goroutine writes it + // concurrently, and returning without a send would block it. + if err := ucli.ApplyPreset(spec); err != nil { + errChan <- fmt.Errorf("client: %v", err) + c.Close() return } cli = ucli diff --git a/resumption_trust_test.go b/resumption_trust_test.go index 4433c4907e..642eb40b2d 100644 --- a/resumption_trust_test.go +++ b/resumption_trust_test.go @@ -11,6 +11,7 @@ import ( "crypto/rand" "crypto/x509" "crypto/x509/pkix" + "math/big" "testing" "time" ) @@ -29,6 +30,7 @@ func testHandshakeChainExpiryResumption(t *testing.T, version uint16) { createChain := func(leafNotAfter, rootNotAfter time.Time) (leafDER, expiredLeafDER []byte, root *x509.Certificate) { tmpl := &x509.Certificate{ + SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "root"}, NotBefore: rootNotAfter.Add(-time.Hour * 24), NotAfter: rootNotAfter, @@ -45,11 +47,12 @@ func testHandshakeChainExpiryResumption(t *testing.T, version uint16) { } tmpl = &x509.Certificate{ - Subject: pkix.Name{}, - DNSNames: []string{"expired-resume.example.com"}, - NotBefore: leafNotAfter.Add(-time.Hour * 24), - NotAfter: leafNotAfter, - KeyUsage: x509.KeyUsageDigitalSignature, + SerialNumber: big.NewInt(2), + Subject: pkix.Name{}, + DNSNames: []string{"expired-resume.example.com"}, + NotBefore: leafNotAfter.Add(-time.Hour * 24), + NotAfter: leafNotAfter, + KeyUsage: x509.KeyUsageDigitalSignature, } leafCertDER, err := x509.CreateCertificate(rand.Reader, tmpl, root, &testECDSAPrivateKey.PublicKey, testECDSAPrivateKey) if err != nil { @@ -148,6 +151,7 @@ func TestHandshakeGetConfigForClientDifferentClientCAs(t *testing.T) { func testHandshakeGetConfigForClientDifferentClientCAs(t *testing.T, version uint16) { now := time.Now() tmpl := &x509.Certificate{ + SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "root"}, NotBefore: now.Add(-time.Hour * 24), NotAfter: now.Add(time.Hour * 24), @@ -172,11 +176,12 @@ func testHandshakeGetConfigForClientDifferentClientCAs(t *testing.T, version uin } tmpl = &x509.Certificate{ - Subject: pkix.Name{}, - DNSNames: []string{"example.com"}, - NotBefore: now.Add(-time.Hour * 24), - NotAfter: now.Add(time.Hour * 24), - KeyUsage: x509.KeyUsageDigitalSignature, + SerialNumber: big.NewInt(2), + Subject: pkix.Name{}, + DNSNames: []string{"example.com"}, + NotBefore: now.Add(-time.Hour * 24), + NotAfter: now.Add(time.Hour * 24), + KeyUsage: x509.KeyUsageDigitalSignature, } certA, err := x509.CreateCertificate(rand.Reader, tmpl, rootA, &testECDSAPrivateKey.PublicKey, testECDSAPrivateKey) if err != nil { @@ -266,6 +271,7 @@ func TestHandshakeChangeRootCAsResumption(t *testing.T) { func testHandshakeChangeRootCAsResumption(t *testing.T, version uint16) { now := time.Now() tmpl := &x509.Certificate{ + SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "root"}, NotBefore: now.Add(-time.Hour * 24), NotAfter: now.Add(time.Hour * 24), @@ -290,11 +296,12 @@ func testHandshakeChangeRootCAsResumption(t *testing.T, version uint16) { } tmpl = &x509.Certificate{ - Subject: pkix.Name{}, - DNSNames: []string{"example.com"}, - NotBefore: now.Add(-time.Hour * 24), - NotAfter: now.Add(time.Hour * 24), - KeyUsage: x509.KeyUsageDigitalSignature, + SerialNumber: big.NewInt(2), + Subject: pkix.Name{}, + DNSNames: []string{"example.com"}, + NotBefore: now.Add(-time.Hour * 24), + NotAfter: now.Add(time.Hour * 24), + KeyUsage: x509.KeyUsageDigitalSignature, } certA, err := x509.CreateCertificate(rand.Reader, tmpl, rootA, &testECDSAPrivateKey.PublicKey, testECDSAPrivateKey) if err != nil {