-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into buildparam_158_202
- Loading branch information
Showing
8 changed files
with
99 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2020, Tobias Gruetzmacher | ||
|
||
function find_resource_name(element) { | ||
var row = element.up('tr'); | ||
var resourceName = row.getAttribute('data-resource-name'); | ||
return resourceName; | ||
} | ||
|
||
function resource_action(button, action) { | ||
// TODO: Migrate to form:link after Jenkins 2.233 (for button-styled links) | ||
var form = document.createElement('form'); | ||
form.setAttribute('method', 'POST'); | ||
form.setAttribute('action', action + "?resource=" + find_resource_name(button)); | ||
crumb.appendToForm(form); | ||
document.body.appendChild(form); | ||
form.submit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/org/jenkins/plugins/lockableresources/LockableResourceApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* SPDX-License-Identifier: MIT | ||
* Copyright (c) 2020, Tobias Gruetzmacher | ||
*/ | ||
package org.jenkins.plugins.lockableresources; | ||
|
||
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; | ||
import hudson.security.FullControlOnceLoggedInAuthorizationStrategy; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.jenkins.plugins.lockableresources.TestHelpers.clickButton; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class LockableResourceApiTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void reserveUnreserveApi() throws Exception { | ||
LockableResourcesManager.get().createResource("a1"); | ||
|
||
j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); | ||
j.jenkins.setAuthorizationStrategy(new FullControlOnceLoggedInAuthorizationStrategy()); | ||
|
||
JenkinsRule.WebClient wc = j.createWebClient(); | ||
wc.login("user"); | ||
clickButton(wc, "reserve"); | ||
assertThat(LockableResourcesManager.get().fromName("a1").isReserved(), is(true)); | ||
clickButton(wc, "unreserve"); | ||
assertThat(LockableResourcesManager.get().fromName("a1").isReserved(), is(false)); | ||
} | ||
|
||
@Test | ||
@Issue("SECURITY-1958") | ||
public void apiUsageHttpGet() { | ||
JenkinsRule.WebClient wc = j.createWebClient(); | ||
FailingHttpStatusCodeException e = assertThrows(FailingHttpStatusCodeException.class, | ||
() -> wc.goTo("lockable-resources/reserve?resource=resource1")); | ||
assertThat(e.getStatusCode(), is(405)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters