mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Fix testcase
This commit is contained in:
@@ -4,13 +4,15 @@ import org.specs2.mutable.Specification
|
|||||||
import org.eclipse.jgit.transport.ReceiveCommand
|
import org.eclipse.jgit.transport.ReceiveCommand
|
||||||
import org.eclipse.jgit.lib.ObjectId
|
import org.eclipse.jgit.lib.ObjectId
|
||||||
import gitbucket.core.model.CommitState
|
import gitbucket.core.model.CommitState
|
||||||
import ProtectedBrancheService.ProtectedBranchInfo
|
import gitbucket.core.service.ProtectedBranchService.{ProtectedBranchCommitHook, ProtectedBranchInfo}
|
||||||
|
|
||||||
|
class ProtectedBranchServiceSpec extends Specification with ServiceSpecBase with ProtectedBranchService with CommitStatusService {
|
||||||
|
|
||||||
class ProtectedBrancheServiceSpec extends Specification with ServiceSpecBase with ProtectedBrancheService with CommitStatusService {
|
val commitHook = new ProtectedBranchCommitHook()
|
||||||
val now = new java.util.Date()
|
val now = new java.util.Date()
|
||||||
val sha = "0c77148632618b59b6f70004e3084002be2b8804"
|
val sha = "0c77148632618b59b6f70004e3084002be2b8804"
|
||||||
val sha2 = "0c77148632618b59b6f70004e3084002be2b8805"
|
val sha2 = "0c77148632618b59b6f70004e3084002be2b8805"
|
||||||
|
|
||||||
"getProtectedBranchInfo" should {
|
"getProtectedBranchInfo" should {
|
||||||
"empty is disabled" in {
|
"empty is disabled" in {
|
||||||
withTestDB { implicit session =>
|
withTestDB { implicit session =>
|
||||||
@@ -50,56 +52,56 @@ class ProtectedBrancheServiceSpec extends Specification with ServiceSpecBase wit
|
|||||||
withTestDB { implicit session =>
|
withTestDB { implicit session =>
|
||||||
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE_NONFASTFORWARD)
|
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE_NONFASTFORWARD)
|
||||||
generateNewUserWithDBRepository("user1", "repo1")
|
generateNewUserWithDBRepository("user1", "repo1")
|
||||||
getBranchProtectedReason("user1", "repo1", true, rc, "user1") must_== None
|
commitHook.hook("user1", "repo1", true, rc, "user1") must_== None
|
||||||
enableBranchProtection("user1", "repo1", "branch", false, Nil)
|
enableBranchProtection("user1", "repo1", "branch", false, Nil)
|
||||||
getBranchProtectedReason("user1", "repo1", true, rc, "user1") must_== Some("Cannot force-push to a protected branch")
|
commitHook.hook("user1", "repo1", true, rc, "user1") must_== Some("Cannot force-push to a protected branch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"getBranchProtectedReason on force push from othre" in {
|
"getBranchProtectedReason on force push from othre" in {
|
||||||
withTestDB { implicit session =>
|
withTestDB { implicit session =>
|
||||||
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE_NONFASTFORWARD)
|
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE_NONFASTFORWARD)
|
||||||
generateNewUserWithDBRepository("user1", "repo1")
|
generateNewUserWithDBRepository("user1", "repo1")
|
||||||
getBranchProtectedReason("user1", "repo1", true, rc, "user2") must_== None
|
commitHook.hook("user1", "repo1", true, rc, "user2") must_== None
|
||||||
enableBranchProtection("user1", "repo1", "branch", false, Nil)
|
enableBranchProtection("user1", "repo1", "branch", false, Nil)
|
||||||
getBranchProtectedReason("user1", "repo1", true, rc, "user2") must_== Some("Cannot force-push to a protected branch")
|
commitHook.hook("user1", "repo1", true, rc, "user2") must_== Some("Cannot force-push to a protected branch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"getBranchProtectedReason check status on push from othre" in {
|
"getBranchProtectedReason check status on push from othre" in {
|
||||||
withTestDB { implicit session =>
|
withTestDB { implicit session =>
|
||||||
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE)
|
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE)
|
||||||
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user2") must_== None
|
commitHook.hook("user1", "repo1", false, rc, "user2") must_== None
|
||||||
enableBranchProtection("user1", "repo1", "branch", false, Seq("must"))
|
enableBranchProtection("user1", "repo1", "branch", false, Seq("must"))
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user2") must_== Some("Required status check \"must\" is expected")
|
commitHook.hook("user1", "repo1", false, rc, "user2") must_== Some("Required status check \"must\" is expected")
|
||||||
enableBranchProtection("user1", "repo1", "branch", false, Seq("must", "must2"))
|
enableBranchProtection("user1", "repo1", "branch", false, Seq("must", "must2"))
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user2") must_== Some("2 of 2 required status checks are expected")
|
commitHook.hook("user1", "repo1", false, rc, "user2") must_== Some("2 of 2 required status checks are expected")
|
||||||
createCommitStatus("user1", "repo1", sha2, "context", CommitState.SUCCESS, None, None, now, user1)
|
createCommitStatus("user1", "repo1", sha2, "context", CommitState.SUCCESS, None, None, now, user1)
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user2") must_== Some("2 of 2 required status checks are expected")
|
commitHook.hook("user1", "repo1", false, rc, "user2") must_== Some("2 of 2 required status checks are expected")
|
||||||
createCommitStatus("user1", "repo1", sha2, "must", CommitState.SUCCESS, None, None, now, user1)
|
createCommitStatus("user1", "repo1", sha2, "must", CommitState.SUCCESS, None, None, now, user1)
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user2") must_== Some("Required status check \"must2\" is expected")
|
commitHook.hook("user1", "repo1", false, rc, "user2") must_== Some("Required status check \"must2\" is expected")
|
||||||
createCommitStatus("user1", "repo1", sha2, "must2", CommitState.SUCCESS, None, None, now, user1)
|
createCommitStatus("user1", "repo1", sha2, "must2", CommitState.SUCCESS, None, None, now, user1)
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user2") must_== None
|
commitHook.hook("user1", "repo1", false, rc, "user2") must_== None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"getBranchProtectedReason check status on push from admin" in {
|
"getBranchProtectedReason check status on push from admin" in {
|
||||||
withTestDB { implicit session =>
|
withTestDB { implicit session =>
|
||||||
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE)
|
val rc = new ReceiveCommand(ObjectId.fromString(sha), ObjectId.fromString(sha2), "refs/heads/branch", ReceiveCommand.Type.UPDATE)
|
||||||
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
val user1 = generateNewUserWithDBRepository("user1", "repo1")
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user1") must_== None
|
commitHook.hook("user1", "repo1", false, rc, "user1") must_== None
|
||||||
enableBranchProtection("user1", "repo1", "branch", false, Seq("must"))
|
enableBranchProtection("user1", "repo1", "branch", false, Seq("must"))
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user1") must_== None
|
commitHook.hook("user1", "repo1", false, rc, "user1") must_== None
|
||||||
enableBranchProtection("user1", "repo1", "branch", true, Seq("must"))
|
enableBranchProtection("user1", "repo1", "branch", true, Seq("must"))
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user1") must_== Some("Required status check \"must\" is expected")
|
commitHook.hook("user1", "repo1", false, rc, "user1") must_== Some("Required status check \"must\" is expected")
|
||||||
enableBranchProtection("user1", "repo1", "branch", false, Seq("must", "must2"))
|
enableBranchProtection("user1", "repo1", "branch", false, Seq("must", "must2"))
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user1") must_== None
|
commitHook.hook("user1", "repo1", false, rc, "user1") must_== None
|
||||||
enableBranchProtection("user1", "repo1", "branch", true, Seq("must", "must2"))
|
enableBranchProtection("user1", "repo1", "branch", true, Seq("must", "must2"))
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user1") must_== Some("2 of 2 required status checks are expected")
|
commitHook.hook("user1", "repo1", false, rc, "user1") must_== Some("2 of 2 required status checks are expected")
|
||||||
createCommitStatus("user1", "repo1", sha2, "context", CommitState.SUCCESS, None, None, now, user1)
|
createCommitStatus("user1", "repo1", sha2, "context", CommitState.SUCCESS, None, None, now, user1)
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user1") must_== Some("2 of 2 required status checks are expected")
|
commitHook.hook("user1", "repo1", false, rc, "user1") must_== Some("2 of 2 required status checks are expected")
|
||||||
createCommitStatus("user1", "repo1", sha2, "must", CommitState.SUCCESS, None, None, now, user1)
|
createCommitStatus("user1", "repo1", sha2, "must", CommitState.SUCCESS, None, None, now, user1)
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user1") must_== Some("Required status check \"must2\" is expected")
|
commitHook.hook("user1", "repo1", false, rc, "user1") must_== Some("Required status check \"must2\" is expected")
|
||||||
createCommitStatus("user1", "repo1", sha2, "must2", CommitState.SUCCESS, None, None, now, user1)
|
createCommitStatus("user1", "repo1", sha2, "must2", CommitState.SUCCESS, None, None, now, user1)
|
||||||
getBranchProtectedReason("user1", "repo1", false, rc, "user1") must_== None
|
commitHook.hook("user1", "repo1", false, rc, "user1") must_== None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package gitbucket.core.service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import gitbucket.core.model._
|
import gitbucket.core.model._
|
||||||
import gitbucket.core.model.Profile._
|
|
||||||
|
|
||||||
import org.specs2.mutable.Specification
|
import org.specs2.mutable.Specification
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +9,7 @@ class RepositoryServiceSpec extends Specification with ServiceSpecBase with Repo
|
|||||||
"renameRepository can rename CommitState, ProtectedBranches" in { withTestDB { implicit session =>
|
"renameRepository can rename CommitState, ProtectedBranches" in { withTestDB { implicit session =>
|
||||||
val tester = generateNewAccount("tester")
|
val tester = generateNewAccount("tester")
|
||||||
createRepository("repo","root",None,false)
|
createRepository("repo","root",None,false)
|
||||||
val service = new CommitStatusService with ProtectedBrancheService{}
|
val service = new CommitStatusService with ProtectedBranchService {}
|
||||||
val id = service.createCommitStatus(
|
val id = service.createCommitStatus(
|
||||||
userName = "root",
|
userName = "root",
|
||||||
repositoryName = "repo",
|
repositoryName = "repo",
|
||||||
|
|||||||
Reference in New Issue
Block a user