summaryrefslogtreecommitdiffstats
BranchCommit messageAuthorAge
masterSONAR-24079 Upgrade `html` plugins to version 3.18.0.5605github-actions[bot]9 hours
branch-10.8SONAR-23954 Fix calculation of the field installedVersionActive in the respon...Matteo Mara11 days
branch-9.9NO-JIRA prepare next LTA version 9.9.9Steve Marion3 weeks
lj/testing-releaseSONAR-23578 Add release.ymllukasz-jarocki-sonarsource7 weeks
greg/test-new-cirrus-config[DO NOT MERGE] Enable cirrus on this PRGrégoire Aubert8 weeks
branch-10.7SGB-163 Adding timer to all test inside issueApp as a temporary fixRevanshu Paliwal3 months
feat/smarini/BUILD-6088-add-security-mdBUILD-6088 Create SECURITY.mdSamir M4 months
task/sma/SONAR-22676_DO-NOT-MERGEDO NOT MERGE removal of StatusPrinterSteve Marion4 months
branch-10.6NO-JIRA Remove public modifier from Junit5 Test classesMatteo Mara6 months
branch-10.5SONAR-21218 Split QualityGate test to reduce runtimeAmbroise C7 months
copy_of_masterSONAR-22088 Fix GitLab auth when group sync is disabledAurelien Poscia8 months
branch-10.4SGB-12 Fix tests by setting `issueUpdateDate` instead `updatedAt`Duarte Meneses9 months
wip/ak/BUILD-3755-test-prDO NOT MERGE - testingAlain Kermis11 months
branch-10.3BUILD-3755 Don't trigger a public build for the branch-10.3Antoine Vigneau11 months
wip/ant1/try_BUILD-3755_no_public_build_for_lts[PATCH] BUILD-3755 Don't trigger a public build for the LTS branchAntoine Vigneau11 months
fix/jp/fix-jrogUse maven public repoJacek Poreda11 months
Martin/DefaultSymbol_ErrorMessageFix fail_on_reference_overlaps_declaration testMartin Strecker13 months
feature/wad/wip-node-18DO NOT MERGE!! POC to move to NodeJS 18Wouter Admiraal13 months
bug/cv/SONAR-20986-open-source-build-on-travis-failingSONAR-20986 Debug gradle buildCarmine Vassallo14 months
wouter-admiraal-sonarsource-patch-1[WIP] Move to NodeJS 18Wouter Admiraal14 months
branch-10.2SONAR-20855 uploading logs on failure on cirruslukasz-jarocki-sonarsource14 months
branch-10.1NO_JIRA prepare version 10.1.1 Benjamin Campomenosi18 months
ms/test-timeoutWIPMathieu Suen18 months
branch-10.0BUILD-2798 Move after_failure expressions to conditionJeremy Davis21 months
branch-8.9[NO-JIRA] Fix unittest that relies on no longer existing domainZipeng WU24 months
bugfix/cv/upgrade-travisenv-j17[NO-JIRA] Update the build env to use Ubuntu 22.04 and Java 17Carmine Vassallo24 months
branch-9.8[NO JIRA] Prepare next patch versioningalain2 years
prevent-jvm-overrideUpdate .travis.ymlKlaudio Sinani2 years
branch-9.7[NO-JIRA] Prepare the next release cycleMatteo Mara2 years
branch-9.6NO-JIRA bumping version of SonarQube 9.6Lukasz Jarocki2 years
branch-9.5Fix hash symbol in the name 'C#' for markdownPeeter Piegaze2 years
branch-9.4[NO JIRA] Update SonarJS to fix documentationWouter Admiraal3 years
jp/test-utTesting UT failureJacek3 years
lj/travis-fix-for-masterTesting fix, ignore pleaseLukasz Jarocki3 years
branch-9.3BUILD-1347 added whitesource scanTobias Trabelsi3 years
branch-9.2[NO-JIRA] Fix UT test for UpgradeNotificationMathieu Suen3 years
docs/th/AzureExtensionCompat15621Updated docs to show different compatibilitiesTom Howlett3 years
feature/jay/fix-travis-buildUpdate travis.shJay3 years
branch-9.1Bump version to 9.1.1Philippe Perrin3 years
branch-9.0Switch version to 9.0.1Philippe Perrin3 years
branch-8.7Update version to 8.7.1Duarte Meneses4 years
branch-7.9Prepare next development iterationMalena Ebert4 years
branch-8.6Bump patch versionMalena Ebert4 years
poc/me/travis-public-repoUpdate build.gradleMalena Ebert4 years
branch-8.5SONAR-14009 SVN configuration in SQ server does not workDuarte Meneses4 years
branch-8.4Release 8.4.2Zipeng WU4 years
poc/kirill+dam/open-issue-in-idePoC Add Open in IDE link in issueKirill Knize4 years
branch-8.3Update version to 8.3.1Jacek5 years
feature/wad/do-not-merge-do-not-mergeUpdate run_iris.shWouter Admiraal5 years
feature/wad/refresh-cacheDO NOT MERGE!!Wouter Admiraal5 years
branch-8.1SONAR-12849 Upgrade sonar-cfamily to 6.5Julien Lancelot5 years
feature/jh/scanner_report_uploaderDelete temp report after uploadJulien HENRY6 years
branch-6.7Prepare for next development iterationSimon Brandhof6 years
6.7fix Change Default Visibility localizationColin Mueller6 years
branch-7.0Prepare version 7.0-SNAPSHOTSimon Brandhof7 years
branch-6.6Prepare for next development iterationSimon Brandhof7 years
branch-5.6Fix integration testsDavid Rautureau7 years
branch-6.6-M1Set a version on each analysis to prevent 1 year old snapshots to be purgedJulien HENRY7 years
branch-6.5Prepare for next development iterationSimon Brandhof7 years
branch-6.5-M1Prepare next dev versionSimon Brandhof8 years
branch-6.4integration tests: avoid false positive after cpp quality profile changeDaniel Schwarz8 years
branch-6.3Reset version to 6.3-SNAPSHOTJulien Lancelot8 years
branch-6.2Prepare for next development iterationTom8 years
branch-6.1Prepare for next development iteration (ITs)David Rautureau8 years
branch-6.0prepare for next development iterationDavid Rautureau8 years
4.5.5Release 4.5.4Thomas Vérin10 years
 
TagDownloadAuthorAge
24.12.0.100206sonarqube-24.12.0.100206.tar.gz  sonarqube-24.12.0.100206.zip  Steve Marion3 weeks
9.9.8.100196sonarqube-9.9.8.100196.tar.gz  sonarqube-9.9.8.100196.zip  David Cho-Lerat4 weeks
10.7.0.96327sonarqube-10.7.0.96327.tar.gz  sonarqube-10.7.0.96327.zip  Julien HENRY3 months
9.9.7.96285sonarqube-9.9.7.96285.tar.gz  sonarqube-9.9.7.96285.zip  David Cho-Lerat3 months
10.6.0.92116sonarqube-10.6.0.92116.tar.gz  sonarqube-10.6.0.92116.zip  Matteo Mara6 months
9.9.6.92038sonarqube-9.9.6.92038.tar.gz  sonarqube-9.9.6.92038.zip  Antoine Vigneau6 months
10.5.1.90531sonarqube-10.5.1.90531.tar.gz  sonarqube-10.5.1.90531.zip  Alain Kermis8 months
9.9.5.90363sonarqube-9.9.5.90363.tar.gz  sonarqube-9.9.5.90363.zip  Aurelien Poscia8 months
10.5.0.89998sonarqube-10.5.0.89998.tar.gz &nbs
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package integrations

import (
	"encoding/hex"
	"fmt"
	"math/rand"
	"net/http"
	"net/url"
	"os"
	"path"
	"path/filepath"
	"strconv"
	"testing"
	"time"

	"code.gitea.io/gitea/models"
	"code.gitea.io/gitea/models/perm"
	repo_model "code.gitea.io/gitea/models/repo"
	"code.gitea.io/gitea/models/unittest"
	user_model "code.gitea.io/gitea/models/user"
	"code.gitea.io/gitea/modules/git"
	"code.gitea.io/gitea/modules/lfs"
	"code.gitea.io/gitea/modules/setting"
	api "code.gitea.io/gitea/modules/structs"
	"code.gitea.io/gitea/modules/util"

	"github.com/stretchr/testify/assert"
)

const (
	littleSize = 1024              // 1ko
	bigSize    = 128 * 1024 * 1024 // 128Mo
)

func TestGit(t *testing.T) {
	onGiteaRun(t, testGit)
}

func testGit(t *testing.T, u *url.URL) {
	username := "user2"
	baseAPITestContext := NewAPITestContext(t, username, "repo1")

	u.Path = baseAPITestContext.GitPath()

	forkedUserCtx := NewAPITestContext(t, "user4", "repo1")

	t.Run("HTTP", func(t *testing.T) {
		defer PrintCurrentTest(t)()
		ensureAnonymousClone(t, u)
		httpContext := baseAPITestContext
		httpContext.Reponame = "repo-tmp-17"
		forkedUserCtx.Reponame = httpContext.Reponame

		dstPath, err := os.MkdirTemp("", httpContext.Reponame)
		assert.NoError(t, err)
		defer util.RemoveAll(dstPath)

		t.Run("CreateRepoInDifferentUser", doAPICreateRepository(forkedUserCtx, false))
		t.Run("AddUserAsCollaborator", doAPIAddCollaborator(forkedUserCtx, httpContext.Username, perm.AccessModeRead))

		t.Run("ForkFromDifferentUser", doAPIForkRepository(httpContext, forkedUserCtx.Username))

		u.Path = httpContext.GitPath()
		u.User = url.UserPassword(username, userPassword)

		t.Run("Clone", doGitClone(dstPath, u))

		dstPath2, err := os.MkdirTemp("", httpContext.Reponame)
		assert.NoError(t, err)
		defer util.RemoveAll(dstPath2)

		t.Run("Partial Clone", doPartialGitClone(dstPath2, u))

		little, big := standardCommitAndPushTest(t, dstPath)
		littleLFS, bigLFS := lfsCommitAndPushTest(t, dstPath)
		rawTest(t, &httpContext, little, big, littleLFS, bigLFS)
		mediaTest(t, &httpContext, little, big, littleLFS, bigLFS)

		t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "master", "test/head"))
		t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath))
		t.Run("CreatePRAndSetManuallyMerged", doCreatePRAndSetManuallyMerged(httpContext, httpContext, dstPath, "master", "test-manually-merge"))
		t.Run("MergeFork", func(t *testing.T) {
			defer PrintCurrentTest(t)()
			t.Run("CreatePRAndMerge", doMergeFork(httpContext, forkedUserCtx, "master", httpContext.Username+":master"))
			rawTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
			mediaTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
		})

		t.Run("PushCreate", doPushCreate(httpContext, u))
	})
	t.Run("SSH", func(t *testing.T) {
		defer PrintCurrentTest(t)()
		sshContext := baseAPITestContext
		sshContext.Reponame = "repo-tmp-18"
		keyname := "my-testing-key"
		forkedUserCtx.Reponame = sshContext.Reponame
		t.Run("CreateRepoInDifferentUser", doAPICreateRepository(forkedUserCtx, false))
		t.Run("AddUserAsCollaborator", doAPIAddCollaborator(forkedUserCtx, sshContext.Username, perm.AccessModeRead))
		t.Run("ForkFromDifferentUser", doAPIForkRepository(sshContext, forkedUserCtx.Username))

		// Setup key the user ssh key
		withKeyFile(t, keyname, func(keyFile string) {
			t.Run("CreateUserKey", doAPICreateUserKey(sshContext, "test-key", keyFile))

			// Setup remote link
			// TODO: get url from api
			sshURL := createSSHUrl(sshContext.GitPath(), u)

			// Setup clone folder
			dstPath, err := os.MkdirTemp("", sshContext.Reponame)
			assert.NoError(t, err)
			defer util.RemoveAll(dstPath)

			t.Run("Clone", doGitClone(dstPath, sshURL))

			little, big := standardCommitAndPushTest(t, dstPath)
			littleLFS, bigLFS := lfsCommitAndPushTest(t, dstPath)
			rawTest(t, &sshContext, little, big, littleLFS, bigLFS)
			mediaTest(t, &sshContext, little, big, littleLFS, bigLFS)

			t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &sshContext, "master", "test/head2"))
			t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath))
			t.Run("MergeFork", func(t *testing.T) {
				defer PrintCurrentTest(t)()
				t.Run("CreatePRAndMerge", doMergeFork(sshContext, forkedUserCtx, "master", sshContext.Username+":master"))
				rawTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
				mediaTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
			})

			t.Run("PushCreate", doPushCreate(sshContext, sshURL))
		})
	})
}

func ensureAnonymousClone(t *testing.T, u *url.URL) {
	dstLocalPath, err := os.MkdirTemp("", "repo1")
	assert.NoError(t, err)
	defer util.RemoveAll(dstLocalPath)
	t.Run("CloneAnonymous", doGitClone(dstLocalPath, u))
}

func standardCommitAndPushTest(t *testing.T, dstPath string) (little, big string) {
	t.Run("Standard", func(t *testing.T) {
		defer PrintCurrentTest(t)()
		little, big = commitAndPushTest(t, dstPath, "data-file-")
	})
	return
}

func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS string) {
	t.Run("LFS", func(t *testing.T) {
		defer PrintCurrentTest(t)()
		git.CheckLFSVersion()
		if !setting.LFS.StartServer {
			t.Skip()
			return
		}
		prefix := "lfs-data-file-"
		_, err := git.NewCommand(git.DefaultContext, "lfs").AddArguments("install").RunInDir(dstPath)
		assert.NoError(t, err)
		_, err = git.NewCommand(git.DefaultContext, "lfs").AddArguments("track", prefix+"*").RunInDir(dstPath)
		assert.NoError(t, err)
		err = git.AddChanges(dstPath, false, ".gitattributes")
		assert.NoError(t, err)

		err = git.CommitChangesWithArgs(dstPath, git.AllowLFSFiltersArgs(), git.CommitChangesOptions{
			Committer: &git.Signature{
				Email: "user2@example.com",
				Name:  "User Two",
				When:  time.Now(),
			},
			Author: &git.Signature{
				Email: "user2@example.com",
				Name:  "User Two",
				When:  time.Now(),
			},
			Message: fmt.Sprintf("Testing commit @ %v", time.Now()),
		})
		assert.NoError(t, err)

		littleLFS, bigLFS = commitAndPushTest(t, dstPath, prefix)

		t.Run("Locks", func(t *testing.T) {
			defer PrintCurrentTest(t)()
			lockTest(t, dstPath)
		})
	})
	return
}

func commitAndPushTest(t *testing.T, dstPath, prefix string) (little, big string) {
	t.Run("PushCommit", func(t *testing.T) {
		defer PrintCurrentTest(t)()
		t.Run("Little", func(t *testing.T) {
			defer PrintCurrentTest(t)()
			little = doCommitAndPush(t, littleSize, dstPath, prefix)
		})
		t.Run("Big", func(t *testing.T) {
			if testing.Short() {
				t.Skip("Skipping test in short mode.")
				return
			}
			defer PrintCurrentTest(t)()
			big = doCommitAndPush(t, bigSize, dstPath, prefix)
		})
	})
	return
}

func rawTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS string) {
	t.Run("Raw", func(t *testing.T) {
		defer PrintCurrentTest(t)()
		username := ctx.Username
		reponame := ctx.Reponame

		session := loginUser(t, username)

		// Request raw paths
		req := NewRequest(t, "GET", path.Join("/", username, reponame, "/raw/branch/master/", little))
		resp := session.MakeRequestNilResponseRecorder(t, req, http.StatusOK)
		assert.Equal(t, littleSize, resp.Length)

		git.CheckLFSVersionsonarqube-5.4-M4.zip  
Stas Vilchik9 years
5.3sonarqube-5.3.tar.gz  sonarqube-5.3.zip  Thomas Vérin9 years
5.3-RC3sonarqube-5.3-RC3.tar.gz  sonarqube-5.3-RC3.zip  Thomas Vérin9 years
5.4-M3sonarqube-5.4-M3.tar.gz  sonarqube-5.4-M3.zip  Simon Brandhof9 years
5.4-M2sonarqube-5.4-M2.tar.gz  sonarqube-5.4-M2.zip  Stas Vilchik9 years
5.3-RC2sonarqube-5.3-RC2.tar.gz  sonarqube-5.3-RC2.zip  Thomas Vérin9 years
5.3-RC1sonarqube-5.3-RC1.tar.gz  sonarqube-5.3-RC1.zip  Eric Hartmann9 years
5.2sonarqube-5.2.tar.gz  sonarqube-5.2.zip  Simon Brandhof9 years
5.2-RC3sonarqube-5.2-RC3.tar.gz  sonarqube-5.2-RC3.zip  Thomas Vérin9 years
4.5.6sonarqube-4.5.6.tar.gz  sonarqube-4.5.6.zip  Thomas Vérin9 years
4.5.5sonarqube-4.5.5.tar.gz  sonarqube-4.5.5.zip  Thomas Vérin9 years
5.2-RC2sonarqube-5.2-RC2.tar.gz  sonarqube-5.2-RC2.zip  Thomas Vérin9 years
5.2-RC1sonarqube-5.2-RC1.tar.gz  sonarqube-5.2-RC1.zip  Thomas Vérin9 years
5.1.2sonarqube-5.1.2.tar.gz  sonarqube-5.1.2.zip  Eric Hartmann9 years
5.1.1sonarqube-5.1.1.tar.gz  sonarqube-5.1.1.zip  Eric Hartmann10 years
5.1sonarqube-5.1.tar.gz  sonarqube-5.1.zip  Sonartech10 years
5.1-RC2sonarqube-5.1-RC2.tar.gz  sonarqube-5.1-RC2.zip  Eric Hartmann10 years
5.1-RC1sonarqube-5.1-RC1.tar.gz  sonarqube-5.1-RC1.zip  Eric Hartmann10 years
4.5.4sonarqube-4.5.4.tar.gz  sonarqube-4.5.4.zip  Thomas Vérin10 years
4.5.3sonarqube-4.5.3.tar.gz  sonarqube-4.5.3.zip  Thomas Vérin10 years
5.0.1sonarqube-5.0.1.tar.gz  sonarqube-5.0.1.zip  Thomas Vérin10 years
latest-silver-master-#65sonarqube-latest-silver-master-#65.tar.gz  sonarqube-latest-silver-master-#65.zip  Jean-Baptiste Lievremont10 years
5.0sonarqube-5.0.tar.gz  sonarqube-5.0.zip  Eric Hartmann10 years
5.0-RC4sonarqube-5.0-RC4.tar.gz  sonarqube-5.0-RC4.zip  Thomas Vérin10 years
4.5.2sonarqube-4.5.2.tar.gz  sonarqube-4.5.2.zip  Thomas Vérin10 years
5.0-RC3sonarqube-5.0-RC3.tar.gz  sonarqube-5.0-RC3.zip  Eric Hartmann10 years
5.0-RC2sonarqube-5.0-RC2.tar.gz  sonarqube-5.0-RC2.zip  Eric Hartmann10 years
5.0-RC1sonarqube-5.0-RC1.tar.gz  sonarqube-5.0-RC1.zip  Eric Hartmann10 years
4.5.1sonarqube-4.5.1.tar.gz  sonarqube-4.5.1.zip  Eric Hartmann10 years
4.5.1-RC1sonarqube-4.5.1-RC1.tar.gz  sonarqube-4.5.1-RC1.zip  Julien Lancelot10 years
4.5sonarqube-4.5.tar.gz  sonarqube-4.5.zip  Eric Hartmann10 years
4.5-RC3sonarqube-4.5-RC3.tar.gz  sonarqube-4.5-RC3.zip  Eric Hartmann10 years
4.4.1sonarqube-4.4.1.tar.gz  sonarqube-4.4.1.zip  Eric Hartmann10 years
4.5-RC2sonarqube-4.5-RC2.tar.gz  sonarqube-4.5-RC2.zip  Eric Hartmann10 years
4.5-RC1sonarqube-4.5-RC1.tar.gz  sonarqube-4.5-RC1.zip  Eric Hartmann10 years
4.3.3sonarqube-4.3.3.tar.gz  sonarqube-4.3.3.zip  Eric Hartmann10 years
4.4sonarqube-4.4.tar.gz  sonarqube-4.4.zip  Eric Hartmann10 years
4.4-RC3sonarqube-4.4-RC3.tar.gz  sonarqube-4.4-RC3.zip  Eric Hartmann10 years
4.4-RC2sonarqube-4.4-RC2.tar.gz  sonarqube-4.4-RC2.zip  Eric Hartmann10 years
4.4-RC1sonarqube-4.4-RC1.tar.gz  sonarqube-4.4-RC1.zip  Eric Hartmann10 years
4.3.2sonarqube-4.3.2.tar.gz  sonarqube-4.3.2.zip  Eric Hartmann11 years
4.3.1sonarqube-4.3.1.tar.gz  sonarqube-4.3.1.zip  Eric Hartmann11 years
4.3sonarqube-4.3.tar.gz  sonarqube-4.3.zip  Eric Hartmann11 years
4.2sonarqube-4.2.tar.gz  sonarqube-4.2.zip  Eric Hartmann11 years
4.1.2sonarqube-4.1.2.tar.gz  sonarqube-4.1.2.zip  Julien Lancelot11 years
4.1.1sonarqube-4.1.1.tar.gz  sonarqube-4.1.1.zip  Eric Hartmann11 years
4.1sonarqube-4.1.tar.gz  sonarqube-4.1.zip  Eric Hartmann11 years
3.7.4sonarqube-3.7.4.tar.gz  sonarqube-3.7.4.zip  Eric Hartmann11 years
4.1-RC2sonarqube-4.1-RC2.tar.gz  sonarqube-4.1-RC2.zip  Eric Hartmann11 years
4.1-RC1sonarqube-4.1-RC1.tar.gz  sonarqube-4.1-RC1.zip  Eric Hartmann11 years
4.0sonarqube-4.0.tar.gz  sonarqube-4.0.zip  Eric Hartmann11 years
3.7.2sonarqube-3.7.2.tar.gz  sonarqube-3.7.2.zip  Eric Hartmann11 years
3.7.1sonarqube-3.7.1.tar.gz  sonarqube-3.7.1.zip  Eric Hartmann11 years
3.7.1-RC1-sonarqube-3.7.1-RC1-.tar.gz  sonarqube-3.7.1-RC1-.zip  Eric Hartmann11 years
3.7sonarqube-3.7.tar.gz  sonarqube-3.7.zip  Eric Hartmann11 years
3.6.3sonarqube-3.6.3.tar.gz  sonarqube-3.6.3.zip  Eric Hartmann11 years
3.6.2sonarqube-3.6.2.tar.gz  sonarqube-3.6.2.zip  Eric Hartmann11 years
3.6.1sonarqube-3.6.1.tar.gz  sonarqube-3.6.1.zip  Eric Hartmann11 years
3.6sonarqube-3.6.tar.gz  sonarqube-3.6.zip  Eric Hartmann12 years
3.5.1sonarqube-3.5.1.tar.gz  sonarqube-3.5.1.zip  Eric Hartmann12 years
3.5sonarqube-3.5.tar.gz  sonarqube-3.5.zip  Eric Hartmann12 years
3.4.1sonarqube-3.4.1.tar.gz  sonarqube-3.4.1.zip  Eric Hartmann12 years
3.4sonarqube-3.4.tar.gz  sonarqube-3.4.zip  GAUDIN12 years
3.3.2sonarqube-3.3.2.tar.gz  sonarqube-3.3.2.zip  Eric Hartmann12 years
3.3.1sonarqube-3.3.1.tar.gz  sonarqube-3.3.1.zip  Eric Hartmann12 years
3.3sonarqube-3.3.tar.gz  sonarqube-3.3.zip  Eric Hartmann12 years
3.2.1sonarqube-3.2.1.tar.gz  sonarqube-3.2.1.zip  Eric Hartmann12 years
3.2sonarqube-3.2.tar.gz  sonarqube-3.2.zip  Eric Hartmann12 years
3.1.1sonarqube-3.1.1.tar.gz  sonarqube-3.1.1.zip  Eric Hartmann13 years
3.1sonarqube-3.1.tar.gz  sonarqube-3.1.zip  Eric Hartmann13 years
3.0.1sonarqube-3.0.1.tar.gz  sonarqube-3.0.1.zip  Eric Hartmann13 years
3.0sonarqube-3.0.tar.gz  sonarqube-3.0.zip  Eric Hartmann13 years
2.14sonarqube-2.14.tar.gz  sonarqube-2.14.zip  Eric Hartmann13 years
2.13.1sonarqube-2.13.1.tar.gz  sonarqube-2.13.1.zip  Eric Hartmann13 years
2.13sonarqube-2.13.tar.gz  sonarqube-2.13.zip  Eric Hartmann13 years
2.12sonarqube-2.12.tar.gz  sonarqube-2.12.zip  Eric Hartmann13 years
2.10.1sonarqube-2.10.1.tar.gz  sonarqube-2.10.1.zip  GAUDIN13 years
2.11sonarqube-2.11.tar.gz  sonarqube-2.11.zip  GAUDIN13 years
2.10sonarqube-2.10.tar.gz  sonarqube-2.10.zip  Simon Brandhof13 years
2.9sonarqube-2.9.tar.gz  sonarqube-2.9.zip  simonbrandhof13 years
2.8sonarqube-2.8.tar.gz  sonarqube-2.8.zip  simonbrandhof14 years
2.7sonarqube-2.7.tar.gz  sonarqube-2.7.zip  simonbrandhof14 years
2.6sonarqube-2.6.tar.gz  sonarqube-2.6.zip  simonbrandhof14 years
="w"> tmpFile.Close() written := 0 for written < size { n := size - written if n > bufSize { n = bufSize } _, err := rand.Read(buffer[:n]) if err != nil { return "", err } n, err = tmpFile.Write(buffer[:n]) if err != nil { return "", err } written += n } if err != nil { return "", err } // Commit // Now here we should explicitly allow lfs filters to run globalArgs := git.AllowLFSFiltersArgs() err = git.AddChangesWithArgs(repoPath, globalArgs, false, filepath.Base(tmpFile.Name())) if err != nil { return "", err } err = git.CommitChangesWithArgs(repoPath, globalArgs, git.CommitChangesOptions{ Committer: &git.Signature{ Email: email, Name: fullName, When: time.Now(), }, Author: &git.Signature{ Email: email, Name: fullName, When: time.Now(), }, Message: fmt.Sprintf("Testing commit @ %v", time.Now()), }) return filepath.Base(tmpFile.Name()), err } func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { return func(t *testing.T) { defer PrintCurrentTest(t)() t.Run("CreateBranchProtected", doGitCreateBranch(dstPath, "protected")) t.Run("PushProtectedBranch", doGitPushTestRepository(dstPath, "origin", "protected")) ctx := NewAPITestContext(t, baseCtx.Username, baseCtx.Reponame) t.Run("ProtectProtectedBranchNoWhitelist", doProtectBranch(ctx, "protected", "", "")) t.Run("GenerateCommit", func(t *testing.T) { _, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-") assert.NoError(t, err) }) t.Run("FailToPushToProtectedBranch", doGitPushTestRepositoryFail(dstPath, "origin", "protected")) t.Run("PushToUnprotectedBranch", doGitPushTestRepository(dstPath, "origin", "protected:unprotected")) var pr api.PullRequest var err error t.Run("CreatePullRequest", func(t *testing.T) { pr, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, "protected", "unprotected")(t) assert.NoError(t, err) }) t.Run("GenerateCommit", func(t *testing.T) { _, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-") assert.NoError(t, err) }) t.Run("PushToUnprotectedBranch", doGitPushTestRepository(dstPath, "origin", "protected:unprotected-2")) var pr2 api.PullRequest t.Run("CreatePullRequest", func(t *testing.T) { pr2, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, "unprotected", "unprotected-2")(t) assert.NoError(t, err) }) t.Run("MergePR2", doAPIMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr2.Index)) t.Run("MergePR", doAPIMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)) t.Run("PullProtected", doGitPull(dstPath, "origin", "protected")) t.Run("ProtectProtectedBranchUnprotectedFilePaths", doProtectBranch(ctx, "protected", "", "unprotected-file-*")) t.Run("GenerateCommit", func(t *testing.T) { _, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "unprotected-file-") assert.NoError(t, err) }) t.Run("PushUnprotectedFilesToProtectedBranch", doGitPushTestRepository(dstPath, "origin", "protected")) t.Run("ProtectProtectedBranchWhitelist", doProtectBranch(ctx, "protected", baseCtx.Username, "")) t.Run("CheckoutMaster", doGitCheckoutBranch(dstPath, "master")) t.Run("CreateBranchForced", doGitCreateBranch(dstPath, "toforce")) t.Run("GenerateCommit", func(t *testing.T) { _, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-") assert.NoError(t, err) }) t.Run("FailToForcePushToProtectedBranch", doGitPushTestRepositoryFail(dstPath, "-f", "origin", "toforce:protected")) t.Run("MergeProtectedToToforce", doGitMerge(dstPath, "protected")) t.Run("PushToProtectedBranch", doGitPushTestRepository(dstPath, "origin", "toforce:protected")) t.Run("CheckoutMasterAgain", doGitCheckoutBranch(dstPath, "master")) } } func doProtectBranch(ctx APITestContext, branch, userToWhitelist, unprotectedFilePatterns string) func(t *testing.T) { // We are going to just use the owner to set the protection. return func(t *testing.T) { csrf := GetCSRF(t, ctx.Session, fmt.Sprintf("/%s/%s/settings/branches", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame))) if userToWhitelist == "" { // Change branch to protected req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/branches/%s", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), url.PathEscape(branch)), map[string]string{ "_csrf": csrf, "protected": "on", "unprotected_file_patterns": unprotectedFilePatterns, }) ctx.Session.MakeRequest(t, req, http.StatusSeeOther) } else { user, err := user_model.GetUserByName(userToWhitelist) assert.NoError(t, err) // Change branch to protected req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/branches/%s", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), url.PathEscape(branch)), map[string]string{ "_csrf": csrf, "protected": "on", "enable_push": "whitelist", "enable_whitelist": "on", "whitelist_users": strconv.FormatInt(user.ID, 10), "unprotected_file_patterns": unprotectedFilePatterns, }) ctx.Session.MakeRequest(t, req, http.StatusSeeOther) } // Check if master branch has been locked successfully flashCookie := ctx.Session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) assert.EqualValues(t, "success%3DBranch%2Bprotection%2Bfor%2Bbranch%2B%2527"+url.QueryEscape(branch)+"%2527%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value) } } func doMergeFork(ctx, baseCtx APITestContext, baseBranch, headBranch string) func(t *testing.T) { return func(t *testing.T) { defer PrintCurrentTest(t)() var pr api.PullRequest var err error // Create a test pullrequest t.Run("CreatePullRequest", func(t *testing.T) { pr, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, baseBranch, headBranch)(t) assert.NoError(t, err) }) // Ensure the PR page works t.Run("EnsureCanSeePull", doEnsureCanSeePull(baseCtx, pr)) // Then get the diff string var diffHash string var diffLength int t.Run("GetDiff", func(t *testing.T) { req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d.diff", url.PathEscape(baseCtx.Username), url.PathEscape(baseCtx.Reponame), pr.Index)) resp := ctx.Session.MakeRequestNilResponseHashSumRecorder(t, req, http.StatusOK) diffHash = string(resp.Hash.Sum(nil)) diffLength = resp.Length }) // Now: Merge the PR & make sure that doesn't break the PR page or change its diff t.Run("MergePR", doAPIMergePullRequest(baseCtx, baseCtx.Username, baseCtx.Reponame, pr.Index)) t.Run("EnsureCanSeePull", doEnsureCanSeePull(baseCtx, pr)) t.Run("CheckPR", func(t *testing.T) { oldMergeBase := pr.MergeBase pr2, err := doAPIGetPullRequest(baseCtx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t) assert.NoError(t, err) assert.Equal(t, oldMergeBase, pr2.MergeBase) }) t.Run("EnsurDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash, diffLength)) // Then: Delete the head branch & make sure that doesn't break the PR page or change its diff t.Run("DeleteHeadBranch", doBranchDelete(baseCtx, baseCtx.Username, baseCtx.Reponame, headBranch)) t.Run("EnsureCanSeePull", doEnsureCanSeePull(baseCtx, pr)) t.Run("EnsureDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash, diffLength)) // Delete the head repository & make sure that doesn't break the PR page or change its diff t.Run("DeleteHeadRepository", doAPIDeleteRepository(ctx)) t.Run("EnsureCanSeePull", doEnsureCanSeePull(baseCtx, pr)) t.Run("EnsureDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash, diffLength)) } } func doCreatePRAndSetManuallyMerged(ctx, baseCtx APITestContext, dstPath, baseBranch, headBranch string) func(t *testing.T) { return func(t *testing.T) { defer PrintCurrentTest(t)() var ( pr api.PullRequest err error lastCommitID string ) trueBool := true falseBool := false t.Run("AllowSetManuallyMergedAndSwitchOffAutodetectManualMerge", doAPIEditRepository(baseCtx, &api.EditRepoOption{ HasPullRequests: &trueBool, AllowManualMerge: &trueBool, AutodetectManualMerge: &falseBool, })) t.Run("CreateHeadBranch", doGitCreateBranch(dstPath, headBranch)) t.Run("PushToHeadBranch", doGitPushTestRepository(dstPath, "origin", headBranch)) t.Run("CreateEmptyPullRequest", func(t *testing.T) { pr, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, baseBranch, headBranch)(t) assert.NoError(t, err) }) lastCommitID = pr.Base.Sha t.Run("ManuallyMergePR", doAPIManuallyMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, lastCommitID, pr.Index)) } } func doEnsureCanSeePull(ctx APITestContext, pr api.PullRequest) func(t *testing.T) { return func(t *testing.T) { req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), pr.Index)) ctx.Session.MakeRequest(t, req, http.StatusOK) req = NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d/files", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), pr.Index)) ctx.Session.MakeRequest(t, req, http.StatusOK) req = NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d/commits", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), pr.Index)) ctx.Session.MakeRequest(t, req, http.StatusOK) } } func doEnsureDiffNoChange(ctx APITestContext, pr api.PullRequest, diffHash string, diffLength int) func(t *testing.T) { return func(t *testing.T) { req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d.diff", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), pr.Index)) resp := ctx.Session.MakeRequestNilResponseHashSumRecorder(t, req, http.StatusOK) actual := string(resp.Hash.Sum(nil)) actualLength := resp.Length equal := diffHash == actual assert.True(t, equal, "Unexpected change in the diff string: expected hash: %s size: %d but was actually: %s size: %d", hex.EncodeToString([]byte(diffHash)), diffLength, hex.EncodeToString([]byte(actual)), actualLength) } } func doPushCreate(ctx APITestContext, u *url.URL) func(t *testing.T) { return func(t *testing.T) { defer PrintCurrentTest(t)() // create a context for a currently non-existent repository ctx.Reponame = fmt.Sprintf("repo-tmp-push-create-%s", u.Scheme) u.Path = ctx.GitPath() // Create a temporary directory tmpDir, err := os.MkdirTemp("", ctx.Reponame) assert.NoError(t, err) defer util.RemoveAll(tmpDir) // Now create local repository to push as our test and set its origin t.Run("InitTestRepository", doGitInitTestRepository(tmpDir)) t.Run("AddRemote", doGitAddRemote(tmpDir, "origin", u)) // Disable "Push To Create" and attempt to push setting.Repository.EnablePushCreateUser = false t.Run("FailToPushAndCreateTestRepository", doGitPushTestRepositoryFail(tmpDir, "origin", "master")) // Enable "Push To Create" setting.Repository.EnablePushCreateUser = true // Assert that cloning from a non-existent repository does not create it and that it definitely wasn't create above t.Run("FailToCloneFromNonExistentRepository", doGitCloneFail(u)) // Then "Push To Create"x t.Run("SuccessfullyPushAndCreateTestRepository", doGitPushTestRepository(tmpDir, "origin", "master")) // Finally, fetch repo from database and ensure the correct repository has been created repo, err := repo_model.GetRepositoryByOwnerAndName(ctx.Username, ctx.Reponame) assert.NoError(t, err) assert.False(t, repo.IsEmpty) assert.True(t, repo.IsPrivate) // Now add a remote that is invalid to "Push To Create" invalidCtx := ctx invalidCtx.Reponame = fmt.Sprintf("invalid/repo-tmp-push-create-%s", u.Scheme) u.Path = invalidCtx.GitPath() t.Run("AddInvalidRemote", doGitAddRemote(tmpDir, "invalid", u)) // Fail to "Push To Create" the invalid t.Run("FailToPushAndCreateInvalidTestRepository", doGitPushTestRepositoryFail(tmpDir, "invalid", "master")) } } func doBranchDelete(ctx APITestContext, owner, repo, branch string) func(*testing.T) { return func(t *testing.T) { csrf := GetCSRF(t, ctx.Session, fmt.Sprintf("/%s/%s/branches", url.PathEscape(owner), url.PathEscape(repo))) req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/branches/delete?name=%s", url.PathEscape(owner), url.PathEscape(repo), url.QueryEscape(branch)), map[string]string{ "_csrf": csrf, }) ctx.Session.MakeRequest(t, req, http.StatusOK) } } func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headBranch string) func(t *testing.T) { return func(t *testing.T) { defer PrintCurrentTest(t)() // skip this test if git version is low if git.CheckGitVersionAtLeast("2.29") != nil { return } gitRepo, err := git.OpenRepository(git.DefaultContext, dstPath) if !assert.NoError(t, err) { return } defer gitRepo.Close() var ( pr1, pr2 *models.PullRequest commit string ) repo, err := repo_model.GetRepositoryByOwnerAndName(ctx.Username, ctx.Reponame) if !assert.NoError(t, err) { return } pullNum := unittest.GetCount(t, &models.PullRequest{}) t.Run("CreateHeadBranch", doGitCreateBranch(dstPath, headBranch)) t.Run("AddCommit", func(t *testing.T) { err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content"), 0o666) if !assert.NoError(t, err) { return } err = git.AddChanges(dstPath, true) assert.NoError(t, err) err = git.CommitChanges(dstPath, git.CommitChangesOptions{ Committer: &git.Signature{ Email: "user2@example.com", Name: "user2", When: time.Now(), }, Author: &git.Signature{ Email: "user2@example.com", Name: "user2", When: time.Now(), }, Message: "Testing commit 1", }) assert.NoError(t, err) commit, err = gitRepo.GetRefCommitID("HEAD") assert.NoError(t, err) }) t.Run("Push", func(t *testing.T) { _, err := git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master", "-o", "topic="+headBranch).RunInDir(dstPath) if !assert.NoError(t, err) { return } unittest.AssertCount(t, &models.PullRequest{}, pullNum+1) pr1 = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ HeadRepoID: repo.ID, Flow: models.PullRequestFlowAGit, }).(*models.PullRequest) if !assert.NotEmpty(t, pr1) { return } prMsg, err := doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index)(t) if !assert.NoError(t, err) { return } assert.Equal(t, "user2/"+headBranch, pr1.HeadBranch) assert.Equal(t, false, prMsg.HasMerged) assert.Contains(t, "Testing commit 1", prMsg.Body) assert.Equal(t, commit, prMsg.Head.Sha) _, err = git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master/test/"+headBranch).RunInDir(dstPath) if !assert.NoError(t, err) { return } unittest.AssertCount(t, &models.PullRequest{}, pullNum+2) pr2 = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ HeadRepoID: repo.ID, Index: pr1.Index + 1, Flow: models.PullRequestFlowAGit, }).(*models.PullRequest) if !assert.NotEmpty(t, pr2) { return } prMsg, err = doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr2.Index)(t) if !assert.NoError(t, err) { return } assert.Equal(t, "user2/test/"+headBranch, pr2.HeadBranch) assert.Equal(t, false, prMsg.HasMerged) }) if pr1 == nil || pr2 == nil { return } t.Run("AddCommit2", func(t *testing.T) { err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content \n ## test content 2"), 0o666) if !assert.NoError(t, err) { return } err = git.AddChanges(dstPath, true) assert.NoError(t, err) err = git.CommitChanges(dstPath, git.CommitChangesOptions{ Committer: &git.Signature{ Email: "user2@example.com", Name: "user2", When: time.Now(), }, Author: &git.Signature{ Email: "user2@example.com", Name: "user2", When: time.Now(), }, Message: "Testing commit 2", }) assert.NoError(t, err) commit, err = gitRepo.GetRefCommitID("HEAD") assert.NoError(t, err) }) t.Run("Push2", func(t *testing.T) { _, err := git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master", "-o", "topic="+headBranch).RunInDir(dstPath) if !assert.NoError(t, err) { return } unittest.AssertCount(t, &models.PullRequest{}, pullNum+2) prMsg, err := doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index)(t) if !assert.NoError(t, err) { return } assert.Equal(t, false, prMsg.HasMerged) assert.Equal(t, commit, prMsg.Head.Sha) _, err = git.NewCommand(git.DefaultContext, "push", "origin", "HEAD:refs/for/master/test/"+headBranch).RunInDir(dstPath) if !assert.NoError(t, err) { return } unittest.AssertCount(t, &models.PullRequest{}, pullNum+2) prMsg, err = doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr2.Index)(t) if !assert.NoError(t, err) { return } assert.Equal(t, false, prMsg.HasMerged) assert.Equal(t, commit, prMsg.Head.Sha) }) t.Run("Merge", doAPIMergePullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index)) t.Run("CheckoutMasterAgain", doGitCheckoutBranch(dstPath, "master")) } }