Просмотр исходного кода

Added workaround for Go 1.24 printf analyzer (https://tip.golang.org/doc/go1.24#vet)

Amir Khan 1 год назад
Родитель
Сommit
2cb9875445

+ 2 - 2
psiphon/common/inproxy/inproxy_test.go

@@ -51,14 +51,14 @@ import (
 func TestInproxy(t *testing.T) {
 func TestInproxy(t *testing.T) {
 	err := runTestInproxy(false)
 	err := runTestInproxy(false)
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 }
 }
 
 
 func TestInproxyMustUpgrade(t *testing.T) {
 func TestInproxyMustUpgrade(t *testing.T) {
 	err := runTestInproxy(true)
 	err := runTestInproxy(true)
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 }
 }
 
 

+ 6 - 6
psiphon/common/inproxy/matcher_test.go

@@ -36,7 +36,7 @@ import (
 func TestMatcher(t *testing.T) {
 func TestMatcher(t *testing.T) {
 	err := runTestMatcher()
 	err := runTestMatcher()
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 
 
 }
 }
@@ -772,7 +772,7 @@ func randomIPAddress() string {
 func TestMatcherMultiQueue(t *testing.T) {
 func TestMatcherMultiQueue(t *testing.T) {
 	err := runTestMatcherMultiQueue()
 	err := runTestMatcherMultiQueue()
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 }
 }
 
 
@@ -1150,7 +1150,7 @@ func BenchmarkMatcherQueue(b *testing.B) {
 
 
 					err := m.addAnnouncementEntry(announcementEntry)
 					err := m.addAnnouncementEntry(announcementEntry)
 					if err != nil {
 					if err != nil {
-						b.Fatalf(errors.Trace(err).Error())
+						b.Fatal(errors.Trace(err).Error())
 					}
 					}
 				}
 				}
 			}
 			}
@@ -1160,7 +1160,7 @@ func BenchmarkMatcherQueue(b *testing.B) {
 
 
 			queueSize := m.announcementQueue.getLen()
 			queueSize := m.announcementQueue.getLen()
 			if queueSize != size {
 			if queueSize != size {
-				b.Fatalf(errors.Tracef("unexpected queue size: %d", queueSize).Error())
+				b.Fatal(errors.Tracef("unexpected queue size: %d", queueSize).Error())
 			}
 			}
 
 
 			for i := 0; i < b.N; i++ {
 			for i := 0; i < b.N; i++ {
@@ -1203,12 +1203,12 @@ func BenchmarkMatcherQueue(b *testing.B) {
 
 
 				err := m.addAnnouncementEntry(announcementEntry)
 				err := m.addAnnouncementEntry(announcementEntry)
 				if err != nil {
 				if err != nil {
-					b.Fatalf(errors.Trace(err).Error())
+					b.Fatal(errors.Trace(err).Error())
 				}
 				}
 
 
 				match, _ := m.matchOffer(offerEntry)
 				match, _ := m.matchOffer(offerEntry)
 				if match == nil {
 				if match == nil {
-					b.Fatalf(errors.TraceNew("unexpected no match").Error())
+					b.Fatal(errors.TraceNew("unexpected no match").Error())
 				}
 				}
 
 
 				m.removeAnnouncementEntry(false, match)
 				m.removeAnnouncementEntry(false, match)

+ 4 - 4
psiphon/common/inproxy/obfuscation_test.go

@@ -36,7 +36,7 @@ func FuzzSessionPacketDeobfuscation(f *testing.F) {
 
 
 	rootSecret, err := GenerateRootObfuscationSecret()
 	rootSecret, err := GenerateRootObfuscationSecret()
 	if err != nil {
 	if err != nil {
-		f.Fatalf(errors.Trace(err).Error())
+		f.Fatal(errors.Trace(err).Error())
 	}
 	}
 
 
 	n := 10
 	n := 10
@@ -48,7 +48,7 @@ func FuzzSessionPacketDeobfuscation(f *testing.F) {
 		obfuscatedPacket, err := obfuscateSessionPacket(
 		obfuscatedPacket, err := obfuscateSessionPacket(
 			rootSecret, true, packet, minPadding, maxPadding)
 			rootSecret, true, packet, minPadding, maxPadding)
 		if err != nil {
 		if err != nil {
-			f.Fatalf(errors.Trace(err).Error())
+			f.Fatal(errors.Trace(err).Error())
 		}
 		}
 
 
 		originals[i] = obfuscatedPacket
 		originals[i] = obfuscatedPacket
@@ -86,7 +86,7 @@ func FuzzSessionPacketDeobfuscation(f *testing.F) {
 func TestSessionPacketObfuscation(t *testing.T) {
 func TestSessionPacketObfuscation(t *testing.T) {
 	err := runTestSessionPacketObfuscation()
 	err := runTestSessionPacketObfuscation()
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 }
 }
 
 
@@ -349,7 +349,7 @@ func runTestSessionPacketObfuscation() error {
 func TestObfuscationReplayHistory(t *testing.T) {
 func TestObfuscationReplayHistory(t *testing.T) {
 	err := runTestObfuscationReplayHistory()
 	err := runTestObfuscationReplayHistory()
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 }
 }
 
 

+ 1 - 1
psiphon/common/inproxy/sdp_test.go

@@ -35,7 +35,7 @@ import (
 func TestProcessSDP(t *testing.T) {
 func TestProcessSDP(t *testing.T) {
 	err := runTestProcessSDP()
 	err := runTestProcessSDP()
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 }
 }
 
 

+ 2 - 2
psiphon/common/inproxy/session_test.go

@@ -38,7 +38,7 @@ import (
 func TestSessions(t *testing.T) {
 func TestSessions(t *testing.T) {
 	err := runTestSessions()
 	err := runTestSessions()
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 }
 }
 
 
@@ -582,7 +582,7 @@ func (t *testSessionRoundTripper) Close() error {
 func TestNoise(t *testing.T) {
 func TestNoise(t *testing.T) {
 	err := runTestNoise()
 	err := runTestNoise()
 	if err != nil {
 	if err != nil {
-		t.Errorf(errors.Trace(err).Error())
+		t.Error(errors.Trace(err).Error())
 	}
 	}
 }
 }
 
 

+ 3 - 3
psiphon/inproxy_test.go

@@ -42,17 +42,17 @@ func TestInproxyComponents(t *testing.T) {
 
 
 	err := runInproxyBrokerDialParametersTest(t)
 	err := runInproxyBrokerDialParametersTest(t)
 	if err != nil {
 	if err != nil {
-		t.Fatalf(errors.Trace(err).Error())
+		t.Fatal(errors.Trace(err).Error())
 	}
 	}
 
 
 	err = runInproxySTUNDialParametersTest()
 	err = runInproxySTUNDialParametersTest()
 	if err != nil {
 	if err != nil {
-		t.Fatalf(errors.Trace(err).Error())
+		t.Fatal(errors.Trace(err).Error())
 	}
 	}
 
 
 	err = runInproxyNATStateTest()
 	err = runInproxyNATStateTest()
 	if err != nil {
 	if err != nil {
-		t.Fatalf(errors.Trace(err).Error())
+		t.Fatal(errors.Trace(err).Error())
 	}
 	}
 
 
 	// TODO: test inproxyUDPConn multiplexed IPv6Synthesizer
 	// TODO: test inproxyUDPConn multiplexed IPv6Synthesizer

+ 8 - 3
psiphon/notice.go

@@ -399,25 +399,30 @@ func (nl *noticeLogger) outputNoticeToRotatingFile(output []byte) error {
 	return nil
 	return nil
 }
 }
 
 
+// nonConstantSprintf sidesteps the `go vet` "non-constant format string" check
+func nonConstantSprintf(format, _ string, args ...interface{}) string {
+	return fmt.Sprintf(format, args...)
+}
+
 // NoticeInfo is an informational message
 // NoticeInfo is an informational message
 func NoticeInfo(format string, args ...interface{}) {
 func NoticeInfo(format string, args ...interface{}) {
 	singletonNoticeLogger.outputNotice(
 	singletonNoticeLogger.outputNotice(
 		"Info", noticeIsDiagnostic,
 		"Info", noticeIsDiagnostic,
-		"message", fmt.Sprintf(format, args...))
+		"message", nonConstantSprintf(format, "", args...))
 }
 }
 
 
 // NoticeWarning is a warning message; typically a recoverable error condition
 // NoticeWarning is a warning message; typically a recoverable error condition
 func NoticeWarning(format string, args ...interface{}) {
 func NoticeWarning(format string, args ...interface{}) {
 	singletonNoticeLogger.outputNotice(
 	singletonNoticeLogger.outputNotice(
 		"Warning", noticeIsDiagnostic,
 		"Warning", noticeIsDiagnostic,
-		"message", fmt.Sprintf(format, args...))
+		"message", nonConstantSprintf(format, "", args...))
 }
 }
 
 
 // NoticeError is an error message; typically an unrecoverable error condition
 // NoticeError is an error message; typically an unrecoverable error condition
 func NoticeError(format string, args ...interface{}) {
 func NoticeError(format string, args ...interface{}) {
 	singletonNoticeLogger.outputNotice(
 	singletonNoticeLogger.outputNotice(
 		"Error", noticeIsDiagnostic,
 		"Error", noticeIsDiagnostic,
-		"message", fmt.Sprintf(format, args...))
+		"message", nonConstantSprintf(format, "", args...))
 }
 }
 
 
 // NoticeUserLog is a log message from the outer client user of tunnel-core
 // NoticeUserLog is a log message from the outer client user of tunnel-core

+ 1 - 1
psiphon/server/server_test.go

@@ -2170,7 +2170,7 @@ func waitOnNotification(t *testing.T, c, timeoutSignal <-chan struct{}, timeoutM
 		select {
 		select {
 		case <-c:
 		case <-c:
 		case <-timeoutSignal:
 		case <-timeoutSignal:
-			t.Fatalf(timeoutMessage)
+			t.Fatal(timeoutMessage)
 		}
 		}
 	}
 	}
 }
 }

+ 2 - 2
psiphon/tlsDialer_test.go

@@ -607,9 +607,9 @@ func testTLSDialerCompatibility(t *testing.T, address string, fragmentClientHell
 			tlsProfile, success, repeats, tlsVersions)
 			tlsProfile, success, repeats, tlsVersions)
 
 
 		if success == repeats {
 		if success == repeats {
-			t.Logf(result)
+			t.Log(result)
 		} else {
 		} else {
-			t.Errorf(result)
+			t.Error(result)
 		}
 		}
 	}
 	}
 }
 }