summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-05-08 11:11:04 -0400
committerJames Moger <james.moger@gitblit.com>2014-05-08 11:13:10 -0400
commit813a1fab72a462bdd9387ac3f137055853a69710 (patch)
tree444875036242c6a21599e9998d198b347d53af43 /src/test/java
parent03d5ee0bcc4b9d7b6814d7212d19d1126638810d (diff)
downloadgitblit-813a1fab72a462bdd9387ac3f137055853a69710.tar.gz
gitblit-813a1fab72a462bdd9387ac3f137055853a69710.zip
Revise, complete, and fully test the FORK rpc
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/gitblit/tests/RpcTests.java69
-rw-r--r--src/test/java/com/gitblit/tests/Test.java11
2 files changed, 63 insertions, 17 deletions
diff --git a/src/test/java/com/gitblit/tests/RpcTests.java b/src/test/java/com/gitblit/tests/RpcTests.java
index 943153de..51b4671b 100644
--- a/src/test/java/com/gitblit/tests/RpcTests.java
+++ b/src/test/java/com/gitblit/tests/RpcTests.java
@@ -191,12 +191,6 @@ public class RpcTests extends GitblitUnitTest {
assertEquals(AccessRestrictionType.VIEW, retrievedRepository.accessRestriction);
assertEquals(AuthorizationControl.AUTHENTICATED, retrievedRepository.authorizationControl);
- //fork repo
- UserModel userModel = new UserModel("garbageUser");
- assertTrue("Failed to create Fork Repository!",
- RpcUtils.forkRpository(model, userModel, url, account, password.toCharArray()));
-
-
// rename and change access restriciton
String originalName = model.name;
model.name = "garbagerepo2.git";
@@ -403,4 +397,67 @@ public class RpcTests extends GitblitUnitTest {
assertNotNull(branches);
assertTrue(branches.size() > 0);
}
+
+ @Test
+ public void testFork() throws Exception {
+ // test forking by an administrator
+ // admins are all-powerful and can fork the unforakable :)
+ testFork(account, password, true, true);
+ testFork(account, password, false, true);
+
+ // test forking by a permitted normal user
+ UserModel forkUser = new UserModel("forkuser");
+ forkUser.password = forkUser.username;
+ forkUser.canFork = true;
+ RpcUtils.deleteUser(forkUser, url, account, password.toCharArray());
+ RpcUtils.createUser(forkUser, url, account, password.toCharArray());
+ testFork(forkUser.username, forkUser.password, true, true);
+ testFork(forkUser.username, forkUser.password, false, false);
+ RpcUtils.deleteUser(forkUser, url, account, password.toCharArray());
+
+ // test forking by a non-permitted normal user
+ UserModel noForkUser = new UserModel("noforkuser");
+ noForkUser.password = noForkUser.username;
+ noForkUser.canFork = false;
+ RpcUtils.deleteUser(noForkUser, url, account, password.toCharArray());
+ RpcUtils.createUser(noForkUser, url, account, password.toCharArray());
+ testFork(forkUser.username, forkUser.password, true, false);
+ testFork(forkUser.username, forkUser.password, false, false);
+ RpcUtils.deleteUser(noForkUser, url, account, password.toCharArray());
+ }
+
+ private void testFork(String forkAcct, String forkAcctPassword, boolean allowForks, boolean expectSuccess) throws Exception {
+ // test does not exist
+ RepositoryModel dne = new RepositoryModel();
+ dne.name = "doesNotExist.git";
+ assertFalse(String.format("Successfully forked %s!", dne.name),
+ RpcUtils.forkRepository(dne, url, forkAcct, forkAcctPassword.toCharArray()));
+
+ // delete any previous fork
+ RepositoryModel fork = findRepository(String.format("~%s/helloworld.git", forkAcct));
+ if (fork != null) {
+ RpcUtils.deleteRepository(fork, url, account, password.toCharArray());
+ }
+
+ // update the origin to allow forks or not
+ RepositoryModel origin = findRepository("helloworld.git");
+ origin.allowForks = allowForks;
+ RpcUtils.updateRepository(origin.name, origin, url, account, password.toCharArray());
+
+ // fork the repository
+ if (expectSuccess) {
+ assertTrue(String.format("Failed to fork %s!", origin.name),
+ RpcUtils.forkRepository(origin, url, forkAcct, forkAcctPassword.toCharArray()));
+ } else {
+ assertFalse(String.format("Successfully forked %s!", origin.name),
+ RpcUtils.forkRepository(origin, url, forkAcct, forkAcctPassword.toCharArray()));
+ }
+
+ // attempt another fork
+ assertFalse(String.format("Successfully forked %s!", origin.name),
+ RpcUtils.forkRepository(origin, url, forkAcct, forkAcctPassword.toCharArray()));
+
+ // delete the fork repository
+ RpcUtils.deleteRepository(fork, url, account, password.toCharArray());
+ }
}
diff --git a/src/test/java/com/gitblit/tests/Test.java b/src/test/java/com/gitblit/tests/Test.java
deleted file mode 100644
index 275c6b4c..00000000
--- a/src/test/java/com/gitblit/tests/Test.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.gitblit.tests;
-
-/**
- * Created with IntelliJ IDEA.
- * User: manisha
- * Date: 3/21/14
- * Time: 12:03 PM
- * To change this template use File | Settings | File Templates.
- */
-public @interface Test {
-}