loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'chore: avoid using gock' (#6311) from gusted/forgejo-gock into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6311
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>

Gusted 2102163f 26797a86

+42 -17
-2
go.mod
··· 62 62 github.com/google/uuid v1.6.0 63 63 github.com/gorilla/feeds v1.2.0 64 64 github.com/gorilla/sessions v1.4.0 65 - github.com/h2non/gock v1.2.0 66 65 github.com/hashicorp/go-version v1.6.0 67 66 github.com/hashicorp/golang-lru/v2 v2.0.7 68 67 github.com/huandu/xstrings v1.5.0 ··· 209 208 github.com/gorilla/handlers v1.5.2 // indirect 210 209 github.com/gorilla/mux v1.8.1 // indirect 211 210 github.com/gorilla/securecookie v1.1.2 // indirect 212 - github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect 213 211 github.com/hashicorp/go-cleanhttp v0.5.2 // indirect 214 212 github.com/hashicorp/go-retryablehttp v0.7.7 // indirect 215 213 github.com/hashicorp/hcl v1.0.0 // indirect
-6
go.sum
··· 385 385 github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik= 386 386 github.com/grafana/go-json v0.0.0-20241210211703-a119ee5a0a3b h1:3LHDTH25Xtrac5UJfFlFL/BsykD7VLFg7xk4vtkjtk8= 387 387 github.com/grafana/go-json v0.0.0-20241210211703-a119ee5a0a3b/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= 388 - github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE= 389 - github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk= 390 - github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= 391 - github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= 392 388 github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= 393 389 github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= 394 390 github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= ··· 527 523 github.com/msteinert/pam v1.2.0/go.mod h1:d2n0DCUK8rGecChV3JzvmsDjOY4R7AYbsNxAT+ftQl0= 528 524 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= 529 525 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= 530 - github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4= 531 - github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= 532 526 github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek= 533 527 github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o= 534 528 github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
+42 -9
modules/auth/password/pwn/pwn_test.go
··· 4 4 package pwn 5 5 6 6 import ( 7 + "errors" 8 + "io" 7 9 "net/http" 10 + "strings" 8 11 "testing" 9 12 "time" 10 13 11 - "github.com/h2non/gock" 12 14 "github.com/stretchr/testify/assert" 13 15 "github.com/stretchr/testify/require" 14 16 ) 15 17 18 + type mockTransport struct{} 19 + 20 + func (mockTransport) RoundTrip(req *http.Request) (*http.Response, error) { 21 + if req.URL.Host != "api.pwnedpasswords.com" { 22 + return nil, errors.New("unexpected host") 23 + } 24 + 25 + res := &http.Response{ 26 + ProtoMajor: 1, 27 + ProtoMinor: 1, 28 + Proto: "HTTP/1.1", 29 + Request: req, 30 + Header: make(http.Header), 31 + StatusCode: 200, 32 + } 33 + 34 + switch req.URL.Path { 35 + case "/range/5c1d8": 36 + res.Body = io.NopCloser(strings.NewReader("EAF2F254732680E8AC339B84F3266ECCBB5:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2")) 37 + return res, nil 38 + case "/range/ba189": 39 + res.Body = io.NopCloser(strings.NewReader("FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4")) 40 + return res, nil 41 + case "/range/a1733": 42 + res.Body = io.NopCloser(strings.NewReader("C4CE0F1F0062B27B9E2F41AF0C08218017C:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2\r\nFE81480327C992FE62065A827429DD1318B:0")) 43 + return res, nil 44 + case "/range/5617b": 45 + res.Body = io.NopCloser(strings.NewReader("FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0")) 46 + return res, nil 47 + case "/range/79082": 48 + res.Body = io.NopCloser(strings.NewReader("FDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0\r\nAFEF386F56EB0B4BE314E07696E5E6E6536:0")) 49 + return res, nil 50 + } 51 + 52 + return nil, errors.New("unexpected path") 53 + } 54 + 16 55 var client = New(WithHTTP(&http.Client{ 17 - Timeout: time.Second * 2, 56 + Timeout: time.Second * 2, 57 + Transport: mockTransport{}, 18 58 })) 19 59 20 60 func TestPassword(t *testing.T) { 21 - defer gock.Off() 22 - 23 61 count, err := client.CheckPassword("", false) 24 62 require.ErrorIs(t, err, ErrEmptyPassword, "blank input should return ErrEmptyPassword") 25 63 assert.Equal(t, -1, count) 26 64 27 - gock.New("https://api.pwnedpasswords.com").Get("/range/5c1d8").Times(1).Reply(200).BodyString("EAF2F254732680E8AC339B84F3266ECCBB5:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2") 28 65 count, err = client.CheckPassword("pwned", false) 29 66 require.NoError(t, err) 30 67 assert.Equal(t, 1, count) 31 68 32 - gock.New("https://api.pwnedpasswords.com").Get("/range/ba189").Times(1).Reply(200).BodyString("FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4") 33 69 count, err = client.CheckPassword("notpwned", false) 34 70 require.NoError(t, err) 35 71 assert.Equal(t, 0, count) 36 72 37 - gock.New("https://api.pwnedpasswords.com").Get("/range/a1733").Times(1).Reply(200).BodyString("C4CE0F1F0062B27B9E2F41AF0C08218017C:1\r\nFC446EB88938834178CB9322C1EE273C2A7:2\r\nFE81480327C992FE62065A827429DD1318B:0") 38 73 count, err = client.CheckPassword("paddedpwned", true) 39 74 require.NoError(t, err) 40 75 assert.Equal(t, 1, count) 41 76 42 - gock.New("https://api.pwnedpasswords.com").Get("/range/5617b").Times(1).Reply(200).BodyString("FD4CB34F0378BCB15D23F6FFD28F0775C9E:3\r\nFDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0") 43 77 count, err = client.CheckPassword("paddednotpwned", true) 44 78 require.NoError(t, err) 45 79 assert.Equal(t, 0, count) 46 80 47 - gock.New("https://api.pwnedpasswords.com").Get("/range/79082").Times(1).Reply(200).BodyString("FDF342FCD8C3611DAE4D76E8A992A3E4169:4\r\nFE81480327C992FE62065A827429DD1318B:0\r\nAFEF386F56EB0B4BE314E07696E5E6E6536:0") 48 81 count, err = client.CheckPassword("paddednotpwnedzero", true) 49 82 require.NoError(t, err) 50 83 assert.Equal(t, 0, count)