Skip to content

Commit 400e24a

Browse files
rolandshoemakergopherbot
authored andcommitted
crypto/x509: properly gate test on macos version
Fixes the gating of TestIssue51759 by shelling out to sw_vers to check what version of macOS we are on. Fixes #64677 Change-Id: I5eef4fa39e5449e7b2aa73864625c3abf002aef8 Reviewed-on: https://go-review.googlesource.com/c/go/+/549195 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Roland Shoemaker <roland@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 89c532e commit 400e24a

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/crypto/x509/verify_test.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import (
1616
"fmt"
1717
"internal/testenv"
1818
"math/big"
19+
"os/exec"
1920
"reflect"
2021
"runtime"
2122
"sort"
23+
"strconv"
2224
"strings"
2325
"testing"
2426
"time"
@@ -1867,17 +1869,40 @@ func TestSystemRootsErrorUnwrap(t *testing.T) {
18671869
}
18681870
}
18691871

1872+
func macosMajorVersion(t *testing.T) (int, error) {
1873+
cmd := testenv.Command(t, "sw_vers", "-productVersion")
1874+
out, err := cmd.Output()
1875+
if err != nil {
1876+
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
1877+
return 0, fmt.Errorf("%v: %v\n%s", cmd, err, ee.Stderr)
1878+
}
1879+
return 0, fmt.Errorf("%v: %v", cmd, err)
1880+
}
1881+
before, _, ok := strings.Cut(string(out), ".")
1882+
major, err := strconv.Atoi(before)
1883+
if !ok || err != nil {
1884+
return 0, fmt.Errorf("%v: unexpected output: %q", cmd, out)
1885+
}
1886+
1887+
return major, nil
1888+
}
1889+
18701890
func TestIssue51759(t *testing.T) {
18711891
if runtime.GOOS != "darwin" {
18721892
t.Skip("only affects darwin")
18731893
}
1874-
builder := testenv.Builder()
1875-
if builder == "" {
1876-
t.Skip("only run this test on the builders, as we have no reasonable way to gate tests on macOS versions elsewhere")
1877-
}
1878-
if builder == "darwin-amd64-10_14" || builder == "darwin-amd64-10_15" {
1894+
1895+
testenv.MustHaveExecPath(t, "sw_vers")
1896+
if vers, err := macosMajorVersion(t); err != nil {
1897+
if builder := testenv.Builder(); builder != "" {
1898+
t.Fatalf("unable to determine macOS version: %s", err)
1899+
} else {
1900+
t.Skip("unable to determine macOS version")
1901+
}
1902+
} else if vers < 11 {
18791903
t.Skip("behavior only enforced in macOS 11 and after")
18801904
}
1905+
18811906
// badCertData contains a cert that we parse as valid
18821907
// but that macOS SecCertificateCreateWithData rejects.
18831908
const badCertData = "0\x82\x01U0\x82\x01\a\xa0\x03\x02\x01\x02\x02\x01\x020\x05\x06\x03+ep0R1P0N\x06\x03U\x04\x03\x13Gderpkey8dc58100b2493614ee1692831a461f3f4dd3f9b3b088e244f887f81b4906ac260\x1e\x17\r220112235755Z\x17\r220313235755Z0R1P0N\x06\x03U\x04\x03\x13Gderpkey8dc58100b2493614ee1692831a461f3f4dd3f9b3b088e244f887f81b4906ac260*0\x05\x06\x03+ep\x03!\x00bA\xd8e\xadW\xcb\xefZ\x89\xb5\"\x1eR\x9d\xba\x0e:\x1042Q@\u007f\xbd\xfb{ks\x04\xd1£\x020\x000\x05\x06\x03+ep\x03A\x00[\xa7\x06y\x86(\x94\x97\x9eLwA\x00\x01x\xaa\xbc\xbd Ê]\n(΅!ف0\xf5\x9a%I\x19<\xffo\xf1\xeaaf@\xb1\xa7\xaf\xfd\xe9R\xc7\x0f\x8d&\xd5\xfc\x0f\x82\x84a\xbc\r"

0 commit comments

Comments
 (0)