mirror of
https://github.com/golang/go
synced 2024-11-17 21:54:49 -07:00
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>
This commit is contained in:
parent
89c532e8b2
commit
400e24a8be
@ -16,9 +16,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os/exec"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -1867,17 +1869,40 @@ func TestSystemRootsErrorUnwrap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func macosMajorVersion(t *testing.T) (int, error) {
|
||||||
|
cmd := testenv.Command(t, "sw_vers", "-productVersion")
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
|
||||||
|
return 0, fmt.Errorf("%v: %v\n%s", cmd, err, ee.Stderr)
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%v: %v", cmd, err)
|
||||||
|
}
|
||||||
|
before, _, ok := strings.Cut(string(out), ".")
|
||||||
|
major, err := strconv.Atoi(before)
|
||||||
|
if !ok || err != nil {
|
||||||
|
return 0, fmt.Errorf("%v: unexpected output: %q", cmd, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
return major, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestIssue51759(t *testing.T) {
|
func TestIssue51759(t *testing.T) {
|
||||||
if runtime.GOOS != "darwin" {
|
if runtime.GOOS != "darwin" {
|
||||||
t.Skip("only affects darwin")
|
t.Skip("only affects darwin")
|
||||||
}
|
}
|
||||||
builder := testenv.Builder()
|
|
||||||
if builder == "" {
|
testenv.MustHaveExecPath(t, "sw_vers")
|
||||||
t.Skip("only run this test on the builders, as we have no reasonable way to gate tests on macOS versions elsewhere")
|
if vers, err := macosMajorVersion(t); err != nil {
|
||||||
}
|
if builder := testenv.Builder(); builder != "" {
|
||||||
if builder == "darwin-amd64-10_14" || builder == "darwin-amd64-10_15" {
|
t.Fatalf("unable to determine macOS version: %s", err)
|
||||||
|
} else {
|
||||||
|
t.Skip("unable to determine macOS version")
|
||||||
|
}
|
||||||
|
} else if vers < 11 {
|
||||||
t.Skip("behavior only enforced in macOS 11 and after")
|
t.Skip("behavior only enforced in macOS 11 and after")
|
||||||
}
|
}
|
||||||
|
|
||||||
// badCertData contains a cert that we parse as valid
|
// badCertData contains a cert that we parse as valid
|
||||||
// but that macOS SecCertificateCreateWithData rejects.
|
// but that macOS SecCertificateCreateWithData rejects.
|
||||||
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"
|
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user