diff --git a/modules/util/util_test.go b/modules/util/util_test.go index 7dbb14e374..a11a756ab8 100644 --- a/modules/util/util_test.go +++ b/modules/util/util_test.go @@ -86,31 +86,35 @@ func Test_NormalizeEOL(t *testing.T) { } func Test_RandomInt(t *testing.T) { - randInt := CryptoRandomInt(255) + randInt, err := CryptoRandomInt(255) + assert.NoError(t, err) assert.GreaterOrEqual(t, randInt, int64(0)) assert.LessOrEqual(t, randInt, int64(255)) } func Test_RandomString(t *testing.T) { - str1 := CryptoRandomString(32) - var err error + str1, err := CryptoRandomString(32) + assert.NoError(t, err) matches, err := regexp.MatchString(`^[a-zA-Z0-9]{32}$`, str1) assert.NoError(t, err) assert.True(t, matches) - str2 := CryptoRandomString(32) + str2, err := CryptoRandomString(32) + assert.NoError(t, err) matches, err = regexp.MatchString(`^[a-zA-Z0-9]{32}$`, str1) assert.NoError(t, err) assert.True(t, matches) assert.NotEqual(t, str1, str2) - str3 := CryptoRandomString(256) + str3, err := CryptoRandomString(256) + assert.NoError(t, err) matches, err = regexp.MatchString(`^[a-zA-Z0-9]{256}$`, str3) assert.NoError(t, err) assert.True(t, matches) - str4 := CryptoRandomString(256) + str4, err := CryptoRandomString(256) + assert.NoError(t, err) matches, err = regexp.MatchString(`^[a-zA-Z0-9]{256}$`, str4) assert.NoError(t, err) assert.True(t, matches) @@ -119,15 +123,19 @@ func Test_RandomString(t *testing.T) { } func Test_RandomBytes(t *testing.T) { - bytes1 := CryptoRandomBytes(32) + bytes1, err := CryptoRandomBytes(32) + assert.NoError(t, err) - bytes2 := CryptoRandomBytes(32) + bytes2, err := CryptoRandomBytes(32) + assert.NoError(t, err) assert.NotEqual(t, bytes1, bytes2) - bytes3 := CryptoRandomBytes(256) + bytes3, err := CryptoRandomBytes(256) + assert.NoError(t, err) - bytes4 := CryptoRandomBytes(256) + bytes4, err := CryptoRandomBytes(256) + assert.NoError(t, err) assert.NotEqual(t, bytes3, bytes4) } diff --git a/routers/web/repo/issue_comment.go b/routers/web/repo/issue_comment.go index 45bdfac975..48e846f57d 100644 --- a/routers/web/repo/issue_comment.go +++ b/routers/web/repo/issue_comment.go @@ -185,7 +185,7 @@ func NewComment(ctx *context.Context) { } // end if: handle close or reopen // Handle custom status from the status dropdown (replaces close button for issues with org statuses). - if statusIDStr := ctx.Req.FormValue("status_id"); statusIDStr != "" && statusIDStr != "" { + if statusIDStr := ctx.Req.FormValue("status_id"); statusIDStr != "" { if statusIDStr == "reopen" { // Reopen via dropdown if issue.IsClosed { diff --git a/tests/integration/api_license_keys_test.go b/tests/integration/api_license_keys_test.go index d9807b9856..1e30d0f864 100644 --- a/tests/integration/api_license_keys_test.go +++ b/tests/integration/api_license_keys_test.go @@ -6,6 +6,7 @@ package integration import ( "fmt" "net/http" + "strings" "testing" auth_model "code.mokoconsulting.tech/MokoConsulting/MokoGitea/models/auth" @@ -36,7 +37,7 @@ func TestAPILicensePackages(t *testing.T) { t.Run("CreatePackage", func(t *testing.T) { body := `{"name":"Test Pro Annual","description":"Annual pro subscription","duration_days":365,"max_sites":5}` - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-packages", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-packages", strings.NewReader(body)). AddTokenAuth(token). SetHeader("Content-Type", "application/json") resp := MakeRequest(t, req, http.StatusCreated) @@ -51,7 +52,7 @@ func TestAPILicensePackages(t *testing.T) { t.Run("CreatePackageNoName", func(t *testing.T) { body := `{"description":"Missing name"}` - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-packages", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-packages", strings.NewReader(body)). AddTokenAuth(token). SetHeader("Content-Type", "application/json") MakeRequest(t, req, http.StatusUnprocessableEntity) @@ -68,7 +69,7 @@ func TestAPILicenseKeys(t *testing.T) { // Create a package first. body := `{"name":"Test Package","duration_days":30}` - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-packages", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-packages", strings.NewReader(body)). AddTokenAuth(token). SetHeader("Content-Type", "application/json") resp := MakeRequest(t, req, http.StatusCreated) @@ -80,7 +81,7 @@ func TestAPILicenseKeys(t *testing.T) { t.Run("CreateKey", func(t *testing.T) { body := fmt.Sprintf(`{"package_id":%d,"licensee_name":"John Doe","licensee_email":"john@example.com"}`, pkg.ID) - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys", strings.NewReader(body)). AddTokenAuth(token). SetHeader("Content-Type", "application/json") resp := MakeRequest(t, req, http.StatusCreated) @@ -104,7 +105,7 @@ func TestAPILicenseKeys(t *testing.T) { t.Run("EditKey", func(t *testing.T) { body := `{"licensee_name":"Jane Doe","domain_restriction":"example.com,test.com"}` - req := NewRequestWithBody(t, "PATCH", fmt.Sprintf("%s/license-keys/%d", urlPrefix, createdKeyID), []byte(body)). + req := NewRequestWithBody(t, "PATCH", fmt.Sprintf("%s/license-keys/%d", urlPrefix, createdKeyID), strings.NewReader(body)). AddTokenAuth(token). SetHeader("Content-Type", "application/json") resp := MakeRequest(t, req, http.StatusOK) @@ -124,7 +125,7 @@ func TestAPILicenseKeys(t *testing.T) { t.Run("ValidateKey", func(t *testing.T) { body := fmt.Sprintf(`{"key":"%s","domain":"example.com"}`, rawKey) - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys/validate", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys/validate", strings.NewReader(body)). SetHeader("Content-Type", "application/json") // Note: no token — this is a public endpoint. resp := MakeRequest(t, req, http.StatusOK) @@ -136,7 +137,7 @@ func TestAPILicenseKeys(t *testing.T) { t.Run("ValidateInvalidKey", func(t *testing.T) { body := `{"key":"MOKO-XXXX-XXXX-XXXX-XXXX","domain":"example.com"}` - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys/validate", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys/validate", strings.NewReader(body)). SetHeader("Content-Type", "application/json") resp := MakeRequest(t, req, http.StatusOK) var result api.ValidateLicenseKeyResponse @@ -161,7 +162,7 @@ func TestAPILicensePurchaseWebhook(t *testing.T) { // Create a package. body := `{"name":"Purchase Test","duration_days":90}` - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-packages", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-packages", strings.NewReader(body)). AddTokenAuth(token). SetHeader("Content-Type", "application/json") resp := MakeRequest(t, req, http.StatusCreated) @@ -170,7 +171,7 @@ func TestAPILicensePurchaseWebhook(t *testing.T) { t.Run("PurchaseNewKey", func(t *testing.T) { body := fmt.Sprintf(`{"package_id":%d,"licensee_name":"Buyer","licensee_email":"buyer@shop.com","domain":"shop.com","payment_ref":"stripe_pi_test123"}`, pkg.ID) - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys/purchase", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys/purchase", strings.NewReader(body)). AddTokenAuth(token). SetHeader("Content-Type", "application/json") resp := MakeRequest(t, req, http.StatusCreated) @@ -183,7 +184,7 @@ func TestAPILicensePurchaseWebhook(t *testing.T) { t.Run("PurchaseIdempotent", func(t *testing.T) { // Same payment_ref should return existing key without raw_key. body := fmt.Sprintf(`{"package_id":%d,"licensee_name":"Buyer","payment_ref":"stripe_pi_test123"}`, pkg.ID) - req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys/purchase", []byte(body)). + req := NewRequestWithBody(t, "POST", urlPrefix+"/license-keys/purchase", strings.NewReader(body)). AddTokenAuth(token). SetHeader("Content-Type", "application/json") resp := MakeRequest(t, req, http.StatusOK) diff --git a/tests/integration/auth_oauth2_test.go b/tests/integration/auth_oauth2_test.go index e6a032d803..90794f9ff9 100644 --- a/tests/integration/auth_oauth2_test.go +++ b/tests/integration/auth_oauth2_test.go @@ -253,7 +253,7 @@ func TestOAuth2CallbackReactivationGating(t *testing.T) { defer test.MockVariableValue(&setting.OAuth2Client.EnableAutoRegistration, true)() defer test.MockVariableValue(&setting.OAuth2Client.Username, setting.OAuth2UsernameUserid)() - srv := newFakeOIDCServer(t, FakeOIDCConfig{Sub: "test-sub", Email: "test@example.com", Name: "Test User"}) + srv := newFakeOIDCServerWithConfig(t, FakeOIDCConfig{Sub: "test-sub", Email: "test@example.com", Name: "Test User"}) addOAuth2Source(t, "test-oauth-source", oauth2.Source{ Provider: "openidConnect", ClientID: "test-client-id", @@ -308,7 +308,7 @@ type FakeOIDCConfig struct { } // newFakeOIDCServer starts a httptest.Server that implements the minimum OIDC endpoints needed to complete a sign-in flow -func newFakeOIDCServer(t *testing.T, cfg FakeOIDCConfig) *httptest.Server { +func newFakeOIDCServerWithConfig(t *testing.T, cfg FakeOIDCConfig) *httptest.Server { t.Helper() var srv *httptest.Server