Source:
public void testDoFillCredentialsIdItems() throws IOException { Domain domain = new Domain("example", "test domain", Arrays.<DomainSpecification>asList(new HostnameSpecification("example.org", null))); StandardUsernamePasswordCredentials c = new UsernamePasswordCredentialsImpl( CredentialsScope.SYSTEM, null, null, "username", "password" ); CredentialsProvider.lookupStores(r.jenkins).iterator().next().addDomain(domain, c); MockFolder dummy = r.createFolder("dummy"); r.jenkins.setSecurityRealm(r.createDummySecurityRealm()); MockAuthorizationStrategy as = new MockAuthorizationStrategy(); as.grant(Jenkins.ADMINISTER).everywhere().to("admin"); as.grant(Item.READ).onItems(dummy).to("alice"); r.jenkins.setAuthorizationStrategy(as); try (ACLContext context = ACL.as(User.get("admin"))) { ListBoxModel options = r.jenkins.getDescriptorByType(JiraSite.DescriptorImpl.class).doFillCredentialsIdItems(null, "<LINK_1>"); assertThat(options, hasSize(2)); assertEquals(CredentialsNameProvider.name(c), options.get(1).name); options = r.jenkins.getDescriptorByType(JiraSite.DescriptorImpl.class).doFillCredentialsIdItems(null, "<LINK_0>"); assertThat(options, hasSize(1)); assertEquals("", options.get(0).value); options = r.jenkins.getDescriptorByType(JiraSite.DescriptorImpl.class).doFillCredentialsIdItems(dummy, "<LINK_1>"); assertThat(options, hasSize(2)); assertEquals(CredentialsNameProvider.name(c), options.get(1).name); } try (ACLContext context = ACL.as(User.get("alice"))) { ListBoxModel options = r.jenkins.getDescriptorByType(JiraSite.DescriptorImpl.class).doFillCredentialsIdItems(dummy, "<LINK_1>"); assertThat(options, empty()); } }

Target:
public void testDoFillCredentialsIdItems() throws IOException { Domain domain = new Domain("example", "test domain", Arrays.<DomainSpecification>asList(new HostnameSpecification("example.org", null))); StandardUsernamePasswordCredentials c = new UsernamePasswordCredentialsImpl( CredentialsScope.SYSTEM, null, null, "username", "password" ); CredentialsProvider.lookupStores(r.jenkins).iterator().next().addDomain(domain, c); MockFolder dummy = r.createFolder("dummy"); r.jenkins.setSecurityRealm(r.createDummySecurityRealm()); MockAuthorizationStrategy as = new MockAuthorizationStrategy(); as.grant(Jenkins.ADMINISTER).everywhere().to("admin"); as.grant(Item.READ).onItems(dummy).to("alice"); r.jenkins.setAuthorizationStrategy(as); try (ACLContext ignored = ACL.as(User.get("admin"))) { ListBoxModel options = r.jenkins.getDescriptorByType(JiraSite.DescriptorImpl.class).doFillCredentialsIdItems(null, "<LINK_1>"); assertThat(options, hasSize(2)); assertEquals(CredentialsNameProvider.name(c), options.get(1).name); options = r.jenkins.getDescriptorByType(JiraSite.DescriptorImpl.class).doFillCredentialsIdItems(null, "<LINK_0>"); assertThat(options, hasSize(1)); assertEquals("", options.get(0).value); options = r.jenkins.getDescriptorByType(JiraSite.DescriptorImpl.class).doFillCredentialsIdItems(dummy, "<LINK_1>"); assertThat(options, hasSize(2)); assertEquals(CredentialsNameProvider.name(c), options.get(1).name); } try (ACLContext ignored = ACL.as(User.get("alice"))) { ListBoxModel options = r.jenkins.getDescriptorByType(JiraSite.DescriptorImpl.class).doFillCredentialsIdItems(dummy, "<LINK_1>"); assertThat(options, empty()); } }