mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
tests: Do not allow forced type asserts (#20905)
This commit is contained in:
@@ -22,10 +22,11 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func createTempFile(prefix, content string) (tempFile string, err error) {
|
||||
func createTempFile(t testing.TB, prefix, content string) (tempFile string, err error) {
|
||||
t.Helper()
|
||||
var tmpfile *os.File
|
||||
|
||||
if tmpfile, err = os.CreateTemp("", prefix); err != nil {
|
||||
if tmpfile, err = os.CreateTemp(t.TempDir(), prefix); err != nil {
|
||||
return tempFile, err
|
||||
}
|
||||
|
||||
@@ -42,14 +43,13 @@ func createTempFile(prefix, content string) (tempFile string, err error) {
|
||||
}
|
||||
|
||||
func TestParsePublicCertFile(t *testing.T) {
|
||||
tempFile1, err := createTempFile("public-cert-file", "")
|
||||
tempFile1, err := createTempFile(t, "public-cert-file", "")
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create temporary file. %v", err)
|
||||
}
|
||||
defer os.Remove(tempFile1)
|
||||
|
||||
tempFile2, err := createTempFile("public-cert-file",
|
||||
`-----BEGIN CERTIFICATE-----
|
||||
tempFile2, err := createTempFile(t, "public-cert-file", `-----BEGIN CERTIFICATE-----
|
||||
MIICdTCCAd4CCQCO5G/W1xcE9TANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJa
|
||||
WTEOMAwGA1UECBMFTWluaW8xETAPBgNVBAcTCEludGVybmV0MQ4wDAYDVQQKEwVN
|
||||
aW5pbzEOMAwGA1UECxMFTWluaW8xDjAMBgNVBAMTBU1pbmlvMR0wGwYJKoZIhvcN
|
||||
@@ -70,8 +70,7 @@ M9ofSEt/bdRD
|
||||
}
|
||||
defer os.Remove(tempFile2)
|
||||
|
||||
tempFile3, err := createTempFile("public-cert-file",
|
||||
`-----BEGIN CERTIFICATE-----
|
||||
tempFile3, err := createTempFile(t, "public-cert-file", `-----BEGIN CERTIFICATE-----
|
||||
MIICdTCCAd4CCQCO5G/W1xcE9TANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJa
|
||||
WTEOMAwGA1UECBMFTWluaW8xETAPBgNVBAcTCEludGVybmV0MQ4wDAYDVQQKEwVN
|
||||
aW5pbzEOMAwGA1UECxMFTWluaW8xDjAMBgNVBAMTBU1pbmlvMR0wGwYJKoZIhvcN
|
||||
@@ -92,8 +91,7 @@ M9ofSEt/bdRD
|
||||
}
|
||||
defer os.Remove(tempFile3)
|
||||
|
||||
tempFile4, err := createTempFile("public-cert-file",
|
||||
`-----BEGIN CERTIFICATE-----
|
||||
tempFile4, err := createTempFile(t, "public-cert-file", `-----BEGIN CERTIFICATE-----
|
||||
MIICdTCCAd4CCQCO5G/W1xcE9TANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJa
|
||||
WTEOMAwGA1UECBMFTWluaW8xETAPBgNVBAcTCEludGVybmV0MQ4wDAYDVQQKEwVN
|
||||
aW5pbzEOMAwGA1UECxMFTWluaW8xDjAMBgNVBAMTBU1pbmlvMR0wGwYJKoZIhvcN
|
||||
@@ -114,8 +112,7 @@ M9ofSEt/bdRD
|
||||
}
|
||||
defer os.Remove(tempFile4)
|
||||
|
||||
tempFile5, err := createTempFile("public-cert-file",
|
||||
`-----BEGIN CERTIFICATE-----
|
||||
tempFile5, err := createTempFile(t, "public-cert-file", `-----BEGIN CERTIFICATE-----
|
||||
MIICdTCCAd4CCQCO5G/W1xcE9TANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJa
|
||||
WTEOMAwGA1UECBMFTWluaW8xETAPBgNVBAcTCEludGVybmV0MQ4wDAYDVQQKEwVN
|
||||
aW5pbzEOMAwGA1UECxMFTWluaW8xDjAMBgNVBAMTBU1pbmlvMR0wGwYJKoZIhvcN
|
||||
@@ -184,11 +181,11 @@ func TestLoadX509KeyPair(t *testing.T) {
|
||||
os.Unsetenv(EnvCertPassword)
|
||||
})
|
||||
for i, testCase := range loadX509KeyPairTests {
|
||||
privateKey, err := createTempFile("private.key", testCase.privateKey)
|
||||
privateKey, err := createTempFile(t, "private.key", testCase.privateKey)
|
||||
if err != nil {
|
||||
t.Fatalf("Test %d: failed to create tmp private key file: %v", i, err)
|
||||
}
|
||||
certificate, err := createTempFile("public.crt", testCase.certificate)
|
||||
certificate, err := createTempFile(t, "public.crt", testCase.certificate)
|
||||
if err != nil {
|
||||
os.Remove(privateKey)
|
||||
t.Fatalf("Test %d: failed to create tmp certificate file: %v", i, err)
|
||||
|
||||
@@ -143,7 +143,6 @@ func (c *CoreDNS) list(key string, domain bool) ([]SrvRecord, error) {
|
||||
|
||||
srvRecord.Key = msgUnPath(srvRecord.Key)
|
||||
srvRecords = append(srvRecords, srvRecord)
|
||||
|
||||
}
|
||||
sort.Slice(srvRecords, func(i int, j int) bool {
|
||||
return srvRecords[i].Key < srvRecords[j].Key
|
||||
|
||||
@@ -534,7 +534,6 @@ func (r *Config) GetSettings() madmin.OpenIDSettings {
|
||||
HashedClientSecret: hashedSecret,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
@@ -125,7 +125,6 @@ func fetchSubSysTargets(ctx context.Context, cfg config.Config, subSys string, t
|
||||
return nil, err
|
||||
}
|
||||
targets = append(targets, t)
|
||||
|
||||
}
|
||||
case config.NotifyKafkaSubSys:
|
||||
kafkaTargets, err := GetNotifyKafka(cfg[config.NotifyKafkaSubSys])
|
||||
@@ -142,7 +141,6 @@ func fetchSubSysTargets(ctx context.Context, cfg config.Config, subSys string, t
|
||||
return nil, err
|
||||
}
|
||||
targets = append(targets, t)
|
||||
|
||||
}
|
||||
|
||||
case config.NotifyMQTTSubSys:
|
||||
|
||||
@@ -127,7 +127,6 @@ func LookupConfig(kvs config.KVS, transport http.RoundTripper) (cfg Config, err
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cfg.License = strings.TrimSpace(env.Get(config.EnvMinIOSubnetLicense, kvs.Get(config.License)))
|
||||
@@ -142,9 +141,11 @@ func LookupConfig(kvs config.KVS, transport http.RoundTripper) (cfg Config, err
|
||||
|
||||
// Make sure to clone the transport before editing the ProxyURL
|
||||
if proxyURL != nil {
|
||||
ctransport := transport.(*http.Transport).Clone()
|
||||
ctransport.Proxy = http.ProxyURL((*url.URL)(proxyURL))
|
||||
cfg.transport = ctransport
|
||||
if tr, ok := transport.(*http.Transport); ok {
|
||||
ctransport := tr.Clone()
|
||||
ctransport.Proxy = http.ProxyURL((*url.URL)(proxyURL))
|
||||
cfg.transport = ctransport
|
||||
}
|
||||
} else {
|
||||
cfg.transport = transport
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user