Update unit tests for refactored architecture
Change-Id: I04639db977c515e5e1090ef8f0e1ce858820cb03
| | |
| | | mailWriter.forwardSlashChar = forwardSlashChar
|
| | | mailWriter.commands = commands
|
| | | mailWriter.url = url
|
| | | mailWriter.mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true)
|
| | | mailWriter.includeGravatar = GitBlit.getBoolean(Keys.web.allowGravatar, true)
|
| | | mailWriter.shortCommitIdLength = GitBlit.getInteger(Keys.web.shortCommitIdLength, 8)
|
| | | mailWriter.mountParameters = gitblit.getBoolean(Keys.web.mountParameters, true)
|
| | | mailWriter.includeGravatar = gitblit.getBoolean(Keys.web.allowGravatar, true)
|
| | | mailWriter.shortCommitIdLength = gitblit.getInteger(Keys.web.shortCommitIdLength, 8)
|
| | |
|
| | | def content = mailWriter.write()
|
| | |
|
| | |
| | | this.settings = gitblit.getSettings();
|
| | | this.gitblit = gitblit;
|
| | | this.repository = repository;
|
| | | this.user = user == null ? UserModel.ANONYMOUS : user;
|
| | | this.user = user;
|
| | | this.groovyDir = gitblit.getHooksFolder();
|
| | | try {
|
| | | // set Grape root
|
| | |
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.RpcRequest;
|
| | | import com.gitblit.IStoredSettings;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.Constants.RpcRequest;
|
| | | import com.gitblit.Keys.web;
|
| | | import com.gitblit.manager.IRuntimeManager;
|
| | | import com.gitblit.manager.ISessionManager;
|
| | | import com.gitblit.models.UserModel;
|
| | |
| | | return;
|
| | | }
|
| | | // valid user, but not for requested access. send 403.
|
| | | if (runtimeManager.isDebugMode()) {
|
| | | logger.info(MessageFormat.format("RPC: {0} forbidden to access {1}",
|
| | | logger.warn(MessageFormat.format("RPC: {0} forbidden to access {1}",
|
| | | user.username, fullUrl));
|
| | | }
|
| | | httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
|
| | | return;
|
| | | }
|
| | |
| | | git.repositoriesFolder = ${baseFolder}/git |
| | | git.searchRepositoriesSubfolders = true |
| | | git.enableGitServlet = true |
| | | git.daemonPort = 8300 |
| | | groovy.scriptsFolder = src/main/distrib/data/groovy |
| | | groovy.preReceiveScripts = blockpush |
| | | groovy.postReceiveScripts = sendmail |
| | | web.authenticateViewPages = false |
| | | web.authenticateAdminPages = true |
| | | web.allowCookieAuthentication = true |
| | | realm.userService = ${baseFolder}/src/test/config/test-users.conf |
| | | realm.userService = src/test/config/test-users.conf |
| | | realm.passwordStorage = md5 |
| | | realm.minPasswordLength = 5 |
| | | web.siteName = Test Gitblit |
| | |
| | | role = "#admin" |
| | | role = "#notfederated" |
| | | [user "userthree"] |
| | | password = StoredInLDAP |
| | | password = "#externalAccount" |
| | | cookie = d7d3894fc517612aa6c595555b6e1ab8e147e597 |
| | | displayName = User Three |
| | | emailAddress = userthree@gitblit.com |
| | | role = "#admin" |
| | | [user "userone"] |
| | | password = StoredInLDAP |
| | | password = "#externalAccount" |
| | | cookie = c97cd38e50858cd0b389ec61b18fb9a89b4da54c |
| | | displayName = User One |
| | | emailAddress = User.One@gitblit.com |
| | | role = "#admin" |
| | | [user "usertwo"] |
| | | password = StoredInLDAP |
| | | password = "#externalAccount" |
| | | cookie = 498ca9bd2841d39050fa45d1d737b9f9f767858d |
| | | displayName = User Two |
| | | emailAddress = usertwo@gitblit.com |
| | |
| | | cookie = dd94709528bb1c83d08f3088d4043f4742891f4f |
| | | role = "#admin" |
| | | role = "#notfederated" |
| | | [user "sampleuser"] |
| | | password = sampleuser |
| | | cookie = 6e07ed42149fc166206319faffdfba2e2ec82e43 |
| | | role = "#none" |
| | | [team "admins"] |
| | | role = "#none" |
| | | user = admin |
| | |
| | | ModelUtilsTest.class, JnaUtilsTest.class })
|
| | | public class GitBlitSuite {
|
| | |
|
| | | public static final File BASEFOLDER = new File("data");
|
| | |
|
| | | public static final File REPOSITORIES = new File("data/git");
|
| | |
|
| | | public static final File SETTINGS = new File("src/test/config/test-gitblit.properties");
|
| | |
| | |
|
| | | private static AtomicBoolean started = new AtomicBoolean(false);
|
| | |
|
| | | public static Repository getHelloworldRepository() throws Exception {
|
| | | public static Repository getHelloworldRepository() {
|
| | | return getRepository("helloworld.git");
|
| | | }
|
| | |
|
| | | public static Repository getTicgitRepository() throws Exception {
|
| | | public static Repository getTicgitRepository() {
|
| | | return getRepository("ticgit.git");
|
| | | }
|
| | |
|
| | | public static Repository getJGitRepository() throws Exception {
|
| | | public static Repository getJGitRepository() {
|
| | | return getRepository("test/jgit.git");
|
| | | }
|
| | |
|
| | | public static Repository getAmbitionRepository() throws Exception {
|
| | | public static Repository getAmbitionRepository() {
|
| | | return getRepository("test/ambition.git");
|
| | | }
|
| | |
|
| | | public static Repository getGitectiveRepository() throws Exception {
|
| | | public static Repository getGitectiveRepository() {
|
| | | return getRepository("test/gitective.git");
|
| | | }
|
| | |
|
| | | private static Repository getRepository(String name) throws Exception {
|
| | | File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
|
| | | Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
|
| | | return repository;
|
| | | private static Repository getRepository(String name) {
|
| | | try {
|
| | | File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
|
| | | Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
|
| | | return repository;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public static boolean startGitblit() throws Exception {
|
| | |
| | | assertEquals(5, settings().getInteger("realm.userService", 5));
|
| | |
|
| | | assertTrue(settings().getBoolean("git.enableGitServlet", false));
|
| | | assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), settings().getString("realm.userService", null));
|
| | | assertEquals("src/test/config/test-users.conf", settings().getString("realm.userService", null));
|
| | | assertEquals(5, settings().getInteger("realm.minPasswordLength", 0));
|
| | | List<String> mdExtensions = settings().getStrings("web.markdownExtensions");
|
| | | assertTrue(mdExtensions.size() > 0);
|
| | |
| | |
|
| | | private void testRefChange(AccessPermission permission, Status expectedCreate, Status expectedDelete, Status expectedRewind) throws Exception {
|
| | |
|
| | | final String originName = "ticgit.git";
|
| | | final String forkName = "refchecks/ticgit.git";
|
| | | final String workingCopy = "refchecks/ticgit-wc";
|
| | |
|
| | |
|
| | | // lower access restriction on origin repository
|
| | | RepositoryModel origin = repositories().getRepositoryModel(originName);
|
| | | origin.accessRestriction = AccessRestrictionType.NONE;
|
| | | repositories().updateRepositoryModel(origin.name, origin, false);
|
| | |
|
| | | UserModel user = getUser();
|
| | | delete(user);
|
| | |
|
| | | CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);
|
| | |
|
| | | // fork from original to a temporary bare repo
|
| | | File refChecks = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit.git");
|
| | | File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName);
|
| | | if (refChecks.exists()) {
|
| | | FileUtils.delete(refChecks, FileUtils.RECURSIVE);
|
| | | }
|
| | | CloneCommand clone = Git.cloneRepository();
|
| | | clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
|
| | | clone.setURI(url + "/" + originName);
|
| | | clone.setDirectory(refChecks);
|
| | | clone.setBare(true);
|
| | | clone.setCloneAllBranches(true);
|
| | |
| | | GitBlitSuite.close(clone.call());
|
| | |
|
| | | // elevate repository to clone permission
|
| | | RepositoryModel model = repositories().getRepositoryModel("refchecks/ticgit.git");
|
| | | RepositoryModel model = repositories().getRepositoryModel(forkName);
|
| | | switch (permission) {
|
| | | case VIEW:
|
| | | model.accessRestriction = AccessRestrictionType.CLONE;
|
| | |
| | | repositories().updateRepositoryModel(model.name, model, false);
|
| | |
|
| | | // clone temp bare repo to working copy
|
| | | File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit-wc");
|
| | | File local = new File(GitBlitSuite.REPOSITORIES, workingCopy);
|
| | | if (local.exists()) {
|
| | | FileUtils.delete(local, FileUtils.RECURSIVE);
|
| | | }
|
| | |
| | | return dv;
|
| | | }
|
| | |
|
| | | public int getInteger(String key, int defaultValue) {
|
| | | return defaultValue;
|
| | | }
|
| | |
|
| | | public void sendMail(String subject, String message, Collection<String> toAddresses) {
|
| | | messages.add(new MockMail(subject, message, toAddresses));
|
| | | }
|
| | |
| | | private LuceneService newLuceneExecutor() {
|
| | | MemorySettings settings = new MemorySettings();
|
| | | settings.put(Keys.git.repositoriesFolder, GitBlitSuite.REPOSITORIES);
|
| | | RuntimeManager runtime = new RuntimeManager(settings);
|
| | | UserManager users = new UserManager(runtime);
|
| | | RuntimeManager runtime = new RuntimeManager(settings, GitBlitSuite.BASEFOLDER).start();
|
| | | UserManager users = new UserManager(runtime).start();
|
| | | RepositoryManager repos = new RepositoryManager(runtime, users);
|
| | | return new LuceneService(settings, repos);
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | @Test
|
| | | public void testIndex() throws Exception {
|
| | | public void testIndex() {
|
| | | // reindex helloworld
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RepositoryModel model = newRepositoryModel(repository);
|
| | |
| | | import com.gitblit.Constants.AuthorizationControl;
|
| | | import com.gitblit.Constants.PermissionType;
|
| | | import com.gitblit.Constants.RegistrantType;
|
| | | import com.gitblit.GitBlitException.NotAllowedException;
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.FederationModel;
|
| | |
| | | UserModel user = null;
|
| | | try {
|
| | | user = RpcUtils.getUser("admin", url, null, null);
|
| | | } catch (NotAllowedException e) {
|
| | | } catch (ForbiddenException e) {
|
| | | }
|
| | | assertNull("Server allows anyone to get user!", user);
|
| | |
|