/*
* Copyright 2012 gitblit.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitblit.tests;
import java.util.Date;
import org.junit.Test;
import com.gitblit.Constants.AccessPermission;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.AuthorizationControl;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
/**
* Comprehensive, brute-force test of all permutations of discrete permissions.
*
* @author James Moger
*
*/
public class PermissionsTest extends GitblitUnitTest {
/**
* Admin access rights/permissions
*/
@Test
public void testAdmin() throws Exception {
UserModel user = new UserModel("admin");
user.canAdmin = true;
for (AccessRestrictionType ar : AccessRestrictionType.values()) {
RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = ar;
assertTrue("admin CAN NOT view!", user.canView(repository));
assertTrue("admin CAN NOT clone!", user.canClone(repository));
assertTrue("admin CAN NOT push!", user.canPush(repository));
assertTrue("admin CAN NOT create ref!", user.canCreateRef(repository));
assertTrue("admin CAN NOT delete ref!", user.canDeleteRef(repository));
assertTrue("admin CAN NOT rewind ref!", user.canRewindRef(repository));
assertEquals("admin has wrong permission!", AccessPermission.REWIND, user.getRepositoryPermission(repository).permission);
assertTrue("admin CAN NOT fork!", user.canFork(repository));
assertTrue("admin CAN NOT delete!", user.canDelete(repository));
assertTrue("admin CAN NOT edit!", user.canEdit(repository));
}
}
/**
* Anonymous access rights/permissions
*/
@Test
public void testAnonymous_NONE() throws Exception {
RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
UserModel user = UserModel.ANONYMOUS;
// all permissions, except fork
assertTrue("anonymous CAN NOT view!", user.canView(repository));
assertTrue("anonymous CAN NOT clone!", user.canClone(repository));
assertTrue("anonymous CAN NOT push!", user.canPush(repository));
assertTrue("anonymous CAN NOT create ref!", user.canCreateRef(repository));
assertTrue("anonymous CAN NOT delete ref!", user.canDeleteRef(repository));
assertTrue("anonymous CAN NOT rewind ref!", user.canRewindRef(repository));
assertEquals("anonymous has wrong permission!", AccessPermission.REWIND, user.getRepositoryPermission(repository).permission);
repository.allowForks = false;
assertFalse("anonymous CAN fork!", user.canFork(repository));
repository.allowForks = true;
assertFalse("anonymous CAN fork!", user.canFork(repository));
assertFalse("anonymous CAN delete!", user.canDelete(repository));
assertFalse("anonymous CAN edit!", user.canEdit(repository));
}
@Test
public void testAnonymous_PUSH() throws Exception {
RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
UserModel user = UserModel.ANONYMOUS;
assertTrue("anonymous CAN NOT view!", user.canView(repository));
assertTrue("anonymous CAN NOT clone!", user.canClone(repository));
assertFalse("anonymous CAN push!", user.canPush(repository));
assertFalse("anonymous CAN create ref!", user.canCreateRef(repository));
assertFalse("anonymous CAN delete ref!", user.canDeleteRef(repository));
assertFalse("anonymous CAN rewind ref!", user.canRewindRef(repository));
assertEquals("anonymous has wrong permission!", AccessPermission.CLONE, user.getRepositoryPermission(repository).permission);
repository.allowForks = false;
assertFalse("anonymous CAN fork!", user.canFork(repository));
repository.allowForks = true;
assertFalse("anonymous CAN fork!", user.canFork(repository));
}
@Test
public void testAnonymous_CLONE() throws Exception {
RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
UserModel user = UserModel.ANONYMOUS;
assertTrue("anonymous CAN NOT view!", user.canView(repository));
assertFalse("anonymous CAN clone!", user.canClone(repository));
assertFalse("anonymous CAN push!", user.canPush(repository));
assertFalse("anonymous CAN create ref!", user.canCreateRef(repository));
assertFalse("anonymous CAN delete ref!", user.canDeleteRef(repository));
assertFalse("anonymous CAN rewind ref!", user.canRewindRef(repository));
assertEquals("anonymous has wrong permission!", AccessPermission.VIEW, user.getRepositoryPermission(repository).permission);
repository.allowForks = false;
assertFalse("anonymous CAN fork!", user.canFork(repository));
repository.allowForks = true;
assertFalse("anonymous CAN fork!", user.canFork(repository));
}
@Test
public void testAnonymous_VIEW() throws Exception {
RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
UserModel user = UserModel.ANONYMOUS;
assertFalse("anonymous CAN view!", user.canView(repository));
assertFalse("anonymous CAN clone!", user.canClone(repository));
assertFalse("anonymous CAN push!", user.canPush(repository));
assertFalse("anonymous CAN create ref!", user.canCreateRef(repository));
assertFalse("anonymous CAN delete ref!", user.canDeleteRef(repository));
assertFalse("anonymous CAN rewind ref!", user.canRewindRef(repository));
assertEquals("anonymous has wrong permission!", AccessPermission.NONE, user.getRepositoryPermission(repository).permission);
repository.allowForks = false;
assertFalse("anonymous CAN fork!", user.canFork(repository));
repository.allowForks = true;
assertFalse("anonymous CAN fork!", user.canFork(repository));
}
/**
* Authenticated access rights/permissions
*/
@Test
public void testAuthenticated_NONE() throws Exception {
RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
repository.accessRestriction = AccessRestrictionType.NONE;
UserModel user = new UserModel("test");
// all permissions, except fork
assertTrue("authenticated CAN NOT view!", user.canView(repository));
assertTrue("authenticated CAN NOT clone!", user.canClone(repository));
assertTrue("authenticated CAN NOT push!", user.canPush(repository));
assertTrue("authenticated CAN NOT create ref!", user.canCreateRef(repository));
assertTrue("authenticated CAN NOT delete ref!", user.canDeleteRef(repository));
assertTrue("authenticated CAN NOT rewind ref!", user.canRewindRef(repository));
assertEquals("authenticated has wrong permission!", AccessPermission.REWIND, user.getRepositoryPermission(repository).permission);
user.canFork = false;
repository.allowForks = false;
assertFalse("authenticated CAN fork!", user.canFork(repository));
repository.allowForks = true;
assertFalse("authenticated CAN
没有合适的资源?快使用搜索试试~ 我知道了~
纯 Java git 解决方案.zip
共1134个文件
java:549个
png:160个
html:117个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 111 浏览量
2024-11-25
05:11:57
上传
评论
收藏 8.21MB ZIP 举报
温馨提示
吉特布利特Gitblit 是一个开源的纯 Java Git 解决方案,用于管理、查看和提供Git存储库。它可以通过 GIT、HTTP 和 SSH 传输提供存储库它可以根据多个提供商进行身份验证并且它允许您在不到 5 分钟的时间内启动并运行一个美观、功能强大的 Git 服务器。有关 Gitblit 的更多信息可以在这里找到。 执照Gitblit 是根据Apache 软件基金会许可证 2.0 版发布的。许可证文本包含在项目根目录中的 LICENSE 文件中。Java 运行时要求Gitblit 需要 Java 8 运行时环境 (JRE) 或 Java 8 开发工具包 (JDK)。获取帮助来源 地点文档 Gitblit 网站论坛 Google 群组叽叽喳喳 @gitblit 或 @jamesmoger贡献优先使用 GitHub 拉取请求。任何贡献都必须根据Apache 软件基金会许可证 2.0 版的条款进行分发。请参阅CONTRIBUTING 文件以获取有关对 Gitblit 做出贡献的建议和指南。谢谢!总结分叉(然后git clone
资源推荐
资源详情
资源评论
收起资源包目录
纯 Java git 解决方案.zip (1134个子文件)
iconic_stroke.afm 7KB
iconic_fill.afm 7KB
ghreleasenotes.awk 2KB
.checkstyle 504B
.classpath 12KB
installService.cmd 1KB
add-indexed-branch.cmd 1KB
reindex-tickets.cmd 673B
migrate-tickets.cmd 650B
authority.cmd 197B
gitblit.cmd 184B
uninstallService.cmd 151B
gitblit-stop.cmd 80B
pt.cmd 22B
users.conf 2KB
test-ui-users.conf 1KB
issue0259.conf 726B
projects_ja.conf 350B
issue0271.conf 320B
test-users.conf 278B
authority.conf 136B
projects.conf 87B
users.conf 74B
bootstrap.css 98KB
gitblit.css 50KB
font-awesome.min.css 27KB
bootstrap-responsive.css 14KB
octicons.css 11KB
iconic.css 11KB
jquery.fancybox-1.3.4.css 9KB
iconic_stroke.css 6KB
iconic_fill.css 6KB
editor.dev.css 1KB
gitblit-editor.min.css 858B
bootstrap-fixes.css 709B
prettify.css 675B
email.css 498B
flotr2.custom.css 442B
hideheader.css 64B
6x13.dfont 130KB
7x13.dfont 118KB
6x12.dfont 88KB
7x14.dfont 88KB
fontawesome-webfont.eot 69KB
iconic_stroke.eot 31KB
octicons.eot 31KB
iconic_fill.eot 30KB
gitblit.exe 200KB
gitblitw.exe 101KB
gitblit.exe 98KB
gitblit.exe 76KB
FilterableRepositoryList.fm 2KB
FilterableProjectList.fm 944B
macros.ftl 4KB
releasecurrent.ftl 554B
releasehistory.ftl 465B
rss.ftl 93B
atom.ftl 93B
stjude_150x150.gif 7KB
blank.gif 43B
.gitbugtraq 578B
.gitignore 409B
.gitignore 50B
.gitignore 38B
.gitignore 29B
.gitignore 21B
.gitignore 13B
.gitignore 12B
.gitignore 8B
.gitignore 7B
.gitmodules 257B
sendmail-html.groovy 18KB
youtrack.groovy 8KB
sendmail.groovy 7KB
fogbugz.groovy 7KB
subgit.groovy 5KB
protect-refs.groovy 5KB
localclone.groovy 4KB
fisheye.groovy 4KB
thebuggenie.groovy 4KB
jenkins.groovy 4KB
blockpush.groovy 4KB
redmine-fetch.groovy 3KB
TicketPage.html 26KB
TicketsPage.html 9KB
EditRepositoryPage.html 7KB
RepositoriesPanel.html 6KB
EditUserPage.html 5KB
MyTicketsPage.html 5KB
CommitPage.html 5KB
NestedRepositoryTreePanel.html 4KB
RepositoryUrlPanel.html 4KB
RepositoryPage.html 4KB
ComparePage.html 4KB
EditTeamPage.html 4KB
EditTicketPage.html 4KB
NewTicketPage.html 4KB
LuceneSearchPage.html 4KB
ProjectRepositoryPanel.html 3KB
BlobPage.html 3KB
共 1134 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
赵闪闪168
- 粉丝: 1526
- 资源: 2758
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功