From b649bf48b1b666a1d5ff1ab6d8203ddf2415daaa Mon Sep 17 00:00:00 2001 From: Rod Hynes Date: Mon, 11 Nov 2024 12:22:33 -0500 Subject: [PATCH] Fix tests broken by f285be5a --- psiphon/common/inproxy/inproxy_test.go | 47 +++++++++++++++----------- psiphon/common/inproxy/matcher_test.go | 6 ++-- psiphon/common/tactics/tactics_test.go | 3 +- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/psiphon/common/inproxy/inproxy_test.go b/psiphon/common/inproxy/inproxy_test.go index 06e25f849..7aadc6eca 100644 --- a/psiphon/common/inproxy/inproxy_test.go +++ b/psiphon/common/inproxy/inproxy_test.go @@ -202,6 +202,29 @@ func runTestInproxy(doMustUpgrade bool) error { return errors.Trace(err) } + // API parameter handlers + + apiParameterValidator := func(params common.APIParameters) error { + if len(params) != len(baseAPIParameters) { + return errors.TraceNew("unexpected base API parameter count") + } + for name, value := range params { + if value.(string) != baseAPIParameters[name].(string) { + return errors.Tracef( + "unexpected base API parameter: %v: %v != %v", + name, + value.(string), + baseAPIParameters[name].(string)) + } + } + return nil + } + + apiParameterLogFieldFormatter := func( + _ string, _ common.GeoIPData, params common.APIParameters) common.LogFields { + return common.LogFields(params) + } + // Start broker logger.WithTrace().Info("START BROKER") @@ -231,26 +254,9 @@ func runTestInproxy(doMustUpgrade bool) error { CommonCompartmentIDs: testCommonCompartmentIDs, - APIParameterValidator: func(params common.APIParameters) error { - if len(params) != len(baseAPIParameters) { - return errors.TraceNew("unexpected base API parameter count") - } - for name, value := range params { - if value.(string) != baseAPIParameters[name].(string) { - return errors.Tracef( - "unexpected base API parameter: %v: %v != %v", - name, - value.(string), - baseAPIParameters[name].(string)) - } - } - return nil - }, + APIParameterValidator: apiParameterValidator, - APIParameterLogFieldFormatter: func( - geoIPData common.GeoIPData, params common.APIParameters) common.LogFields { - return common.LogFields(params) - }, + APIParameterLogFieldFormatter: apiParameterLogFieldFormatter, GetTacticsPayload: func(_ common.GeoIPData, _ common.APIParameters) ([]byte, string, error) { // Exercise both new and unchanged tactics @@ -297,7 +303,8 @@ func runTestInproxy(doMustUpgrade bool) error { // handler into the destination echo server) serverSessions, err := NewServerBrokerSessions( - serverPrivateKey, serverRootObfuscationSecret, []SessionPublicKey{brokerPublicKey}) + serverPrivateKey, serverRootObfuscationSecret, []SessionPublicKey{brokerPublicKey}, + apiParameterValidator, apiParameterLogFieldFormatter, "") if err != nil { return errors.Trace(err) } diff --git a/psiphon/common/inproxy/matcher_test.go b/psiphon/common/inproxy/matcher_test.go index 53146ad8c..3d19c642a 100644 --- a/psiphon/common/inproxy/matcher_test.go +++ b/psiphon/common/inproxy/matcher_test.go @@ -1065,8 +1065,7 @@ func BenchmarkMatcherQueue(b *testing.B) { NATType: NATTypePortRestrictedCone, PortMappingTypes: []PortMappingType{}, }, - ProxyID: ID{}, - ProxyProtocolVersion: ProxyProtocolVersion1, + ProxyID: ID{}, }, offerChan: make(chan *MatchOffer, 1), } @@ -1102,8 +1101,7 @@ func BenchmarkMatcherQueue(b *testing.B) { NATType: NATTypePortRestrictedCone, PortMappingTypes: []PortMappingType{}, }, - ProxyID: ID{}, - ProxyProtocolVersion: ProxyProtocolVersion1, + ProxyID: ID{}, }, offerChan: make(chan *MatchOffer, 1), } diff --git a/psiphon/common/tactics/tactics_test.go b/psiphon/common/tactics/tactics_test.go index 41a0b49bf..d07deaafd 100644 --- a/psiphon/common/tactics/tactics_test.go +++ b/psiphon/common/tactics/tactics_test.go @@ -191,7 +191,8 @@ func TestTactics(t *testing.T) { } formatter := func( - geoIPData common.GeoIPData, + _ string, + _ common.GeoIPData, apiParams common.APIParameters) common.LogFields { return common.LogFields(apiParams)