@@ -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+
18701890func 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 \x01 U0\x82 \x01 \a \xa0 \x03 \x02 \x01 \x02 \x02 \x01 \x02 0\x05 \x06 \x03 +ep0R1P0N\x06 \x03 U\x04 \x03 \x13 Gderpkey8dc58100b2493614ee1692831a461f3f4dd3f9b3b088e244f887f81b4906ac260\x1e \x17 \r 220112235755Z\x17 \r 220313235755Z0R1P0N\x06 \x03 U\x04 \x03 \x13 Gderpkey8dc58100b2493614ee1692831a461f3f4dd3f9b3b088e244f887f81b4906ac260*0\x05 \x06 \x03 +ep\x03 !\x00 bA\xd8 e\xad W\xcb \xef Z\x89 \xb5 \" \x1e R\x9d \xba \x0e :\x10 42Q@\u007f \xbd \xfb {ks\x04 \xd1 £\x02 0\x00 0\x05 \x06 \x03 +ep\x03 A\x00 [\xa7 \x06 y\x86 (\x94 \x97 \x9e LwA\x00 \x01 x\xaa \xbc \xbd Ê]\n (΅!ف0\xf5 \x9a %I\x19 <\xff o\xf1 \xea af@\xb1 \xa7 \xaf \xfd \xe9 R\xc7 \x0f \x8d &\xd5 \xfc \x0f ;Ϙ\x82 \x84 a\xbc \r "
0 commit comments