Search in sources :

Example 1 with PathRequirement

use of com.cloudbees.plugins.credentials.domains.PathRequirement in project blueocean-plugin by jenkinsci.

the class BlueOceanCredentialsProviderTest method getCredentialsWhenUserExistedButNotAccessible.

@Test
@Issue("JENKINS-53188")
public void getCredentialsWhenUserExistedButNotAccessible() {
    PowerMockito.mockStatic(Jenkins.class);
    PowerMockito.when(Jenkins.get()).thenReturn(jenkins);
    PowerMockito.when(Jenkins.get()).thenReturn(jenkins);
    PowerMockito.when(Jenkins.get()).thenReturn(jenkins);
    when(jenkins.getSecurityRealm()).thenReturn(SecurityRealm.NO_AUTHENTICATION);
    when(jenkins.getSecretKey()).thenReturn("xxx");
    PowerMockito.mockStatic(User.class);
    // Make sure we return a user, cause it did once exist
    PowerMockito.when(User.get(anyString(), anyBoolean(), any())).thenReturn(user);
    Domain domain = BlueOceanCredentialsProvider.createDomain("api.github.com");
    BlueOceanCredentialsProvider blueOceanCredentialsProvider = new BlueOceanCredentialsProvider();
    BlueOceanCredentialsProvider.FolderPropertyImpl prop = new BlueOceanCredentialsProvider.FolderPropertyImpl("halkeye", "halkeye", domain);
    when(folder.getProperties()).thenReturn(describableList);
    when(describableList.get(BlueOceanCredentialsProvider.FolderPropertyImpl.class)).thenReturn(prop);
    // Should be empty when trying to impersonate and grab credentials though
    List<StandardUsernameCredentials> credentials = blueOceanCredentialsProvider.getCredentials(StandardUsernameCredentials.class, (ItemGroup) folder, ACL.SYSTEM, new ArrayList<>(Arrays.asList(new SchemeRequirement("https"), new HostnameRequirement("api.github.com"), new PathRequirement("/"))));
    assertEquals(Collections.emptyList(), credentials);
    List<Credentials> storeCredentials = prop.getStore().getCredentials(domain);
    assertEquals(Collections.emptyList(), storeCredentials);
}
Also used : HostnameRequirement(com.cloudbees.plugins.credentials.domains.HostnameRequirement) PathRequirement(com.cloudbees.plugins.credentials.domains.PathRequirement) StandardUsernameCredentials(com.cloudbees.plugins.credentials.common.StandardUsernameCredentials) Domain(com.cloudbees.plugins.credentials.domains.Domain) SchemeRequirement(com.cloudbees.plugins.credentials.domains.SchemeRequirement) Credentials(com.cloudbees.plugins.credentials.Credentials) StandardUsernameCredentials(com.cloudbees.plugins.credentials.common.StandardUsernameCredentials) Issue(org.jvnet.hudson.test.Issue) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Credentials (com.cloudbees.plugins.credentials.Credentials)1 StandardUsernameCredentials (com.cloudbees.plugins.credentials.common.StandardUsernameCredentials)1 Domain (com.cloudbees.plugins.credentials.domains.Domain)1 HostnameRequirement (com.cloudbees.plugins.credentials.domains.HostnameRequirement)1 PathRequirement (com.cloudbees.plugins.credentials.domains.PathRequirement)1 SchemeRequirement (com.cloudbees.plugins.credentials.domains.SchemeRequirement)1 Test (org.junit.Test)1 Issue (org.jvnet.hudson.test.Issue)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1