use of hudson.model.User in project hudson-2.x by hudson.
the class FunctionsTest method testIsAuthorUserIdNull.
@Test
@PrepareForTest(User.class)
public void testIsAuthorUserIdNull() throws Exception {
mockStatic(User.class);
User user = createMock(User.class);
expect(user.getId()).andReturn(null);
expect(User.current()).andReturn(user);
Job job = createMock(FreeStyleProject.class);
expect(job.getCreatedBy()).andReturn(USER).times(2);
replay(User.class, user, job);
boolean result = Functions.isAuthor(job);
verify(User.class, user, job);
assertFalse(result);
}
use of hudson.model.User in project hudson-2.x by hudson.
the class FunctionsTest method testIsAuthorTrue.
@Test
@PrepareForTest(User.class)
public void testIsAuthorTrue() throws Exception {
mockStatic(User.class);
User user = createMock(User.class);
expect(user.getId()).andReturn(USER);
expect(User.current()).andReturn(user);
Job job = createMock(FreeStyleProject.class);
expect(job.getCreatedBy()).andReturn(USER).times(2);
replay(User.class, user, job);
boolean result = Functions.isAuthor(job);
verify(User.class, user, job);
assertTrue(result);
}
use of hudson.model.User in project hudson-2.x by hudson.
the class FunctionsTest method testIsAuthorFalse.
@Test
@PrepareForTest(User.class)
public void testIsAuthorFalse() throws Exception {
mockStatic(User.class);
User user = createMock(User.class);
expect(user.getId()).andReturn(USER);
expect(User.current()).andReturn(user);
Job job = createMock(FreeStyleProject.class);
expect(job.getCreatedBy()).andReturn("user").times(2);
replay(User.class, user, job);
boolean result = Functions.isAuthor(job);
verify(User.class, user, job);
assertFalse(result);
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class BlueOceanCredentialsProvider method getCredentials.
@Nonnull
public <C extends Credentials> List<C> getCredentials(@Nonnull final Class<C> type, @Nullable ItemGroup itemGroup, @Nullable Authentication authentication, @Nonnull List<DomainRequirement> domainRequirements) {
final List<C> result = new ArrayList<>();
final FolderPropertyImpl prop = propertyOf(itemGroup);
if (prop != null && prop.domain.test(domainRequirements)) {
final User proxyUser = User.get(prop.getUser(), false, Collections.emptyMap());
Authentication proxyAuth = proxyUser == null ? null : proxyUser.impersonate();
if (proxyAuth != null) {
ACL.impersonate(proxyAuth, new Runnable() {
@Override
public void run() {
for (CredentialsStore s : CredentialsProvider.lookupStores(proxyUser)) {
for (Domain d : s.getDomains()) {
if (d.test(PROXY_REQUIREMENT)) {
for (Credentials c : filter(s.getCredentials(d), withId(prop.getId()))) {
if (type.isInstance(c)) {
result.add((C) c);
}
}
}
}
}
}
});
}
}
return result;
}
use of hudson.model.User in project blueocean-plugin by jenkinsci.
the class CredentialContainer method iterator.
@Override
public Iterator<CredentialApi> iterator() {
List<CredentialApi> apis = new ArrayList<>();
User user = User.current();
if (user != null) {
for (CredentialsStore store : CredentialsProvider.lookupStores(user)) {
if (store.getStoreAction() != null) {
apis.add(new CredentialApi(store.getStoreAction(), this));
}
}
} else {
for (CredentialsStore store : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
if (store.getStoreAction() != null) {
apis.add(new CredentialApi(store.getStoreAction(), this));
}
}
}
return apis.iterator();
}
Aggregations