예제 #1
0
 @Test
 public void should_allow_all_permission_on_github_org_only_if_member() throws Exception {
   DynamicProject project = Mockito.mock(DynamicProject.class);
   Mockito.when(project.getGithubRepoUrl()).thenReturn("https://github.com/groupon/DotCi");
   DotCiACL acl = new DotCiACL(project, "suryagaddipati", false);
   GithubAuthenticationToken githubAuthentication = getGithubAuthentication("chairman-meow");
   Mockito.when(githubAuthentication.hasRepositoryPermission("groupon/DotCi")).thenReturn(true);
   Assert.assertTrue(acl.hasPermission(githubAuthentication, Permission.DELETE));
 }
 public void put(String url) throws IOException {
   DBObject token = getToken(url);
   GithubAuthenticationToken auth =
       (GithubAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
   GitHub gh = auth.getGitHub();
   if (token != null) {
     delete(token);
   }
   String accessToken = Secret.fromString(auth.getAccessToken()).getEncryptedValue();
   BasicDBObject doc =
       new BasicDBObject("user", gh.getMyself().getLogin())
           .append("access_token", accessToken)
           .append("repo_url", url);
   save(doc);
 }
예제 #3
0
 private GithubAuthenticationToken getGithubAuthentication(String user) {
   GithubAuthenticationToken auth = Mockito.mock(GithubAuthenticationToken.class);
   Mockito.when(auth.getName()).thenReturn(user);
   Mockito.when(auth.isAuthenticated()).thenReturn(true);
   return auth;
 }